Merge pull request #1565 from hashicorp/f-aws-upstream-cleanup
F aws upstream cleanup
This commit is contained in:
commit
0d1540d448
|
@ -6,17 +6,14 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform/helper/multierror"
|
||||
|
||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
|
||||
awsSDK "github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||
awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||
"github.com/awslabs/aws-sdk-go/service/iam"
|
||||
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@ -35,7 +32,6 @@ type AWSClient struct {
|
|||
region string
|
||||
rdsconn *rds.RDS
|
||||
iamconn *iam.IAM
|
||||
ec2SDKconn *awsEC2.EC2
|
||||
}
|
||||
|
||||
// Client configures and returns a fully initailized AWSClient
|
||||
|
@ -59,40 +55,34 @@ func (c *Config) Client() (interface{}, error) {
|
|||
|
||||
log.Println("[INFO] Building AWS auth structure")
|
||||
creds := aws.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
|
||||
|
||||
log.Println("[INFO] Building AWS SDK auth structure")
|
||||
sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
|
||||
awsConfig := &awsSDK.Config{
|
||||
Credentials: sdkCreds,
|
||||
awsConfig := &aws.Config{
|
||||
Credentials: creds,
|
||||
Region: c.Region,
|
||||
}
|
||||
|
||||
log.Println("[INFO] Initializing ELB SDK connection")
|
||||
log.Println("[INFO] Initializing ELB connection")
|
||||
client.elbconn = elb.New(awsConfig)
|
||||
|
||||
log.Println("[INFO] Initializing S3 connection")
|
||||
client.s3conn = s3.New(awsConfig)
|
||||
|
||||
log.Println("[INFO] Initializing EC2 Connection")
|
||||
client.ec2conn = ec2.New(creds, c.Region, nil)
|
||||
|
||||
log.Println("[INFO] Initializing RDS SDK Connection")
|
||||
log.Println("[INFO] Initializing RDS Connection")
|
||||
client.rdsconn = rds.New(awsConfig)
|
||||
|
||||
log.Println("[INFO] Initializing IAM SDK Connection")
|
||||
log.Println("[INFO] Initializing IAM Connection")
|
||||
client.iamconn = iam.New(awsConfig)
|
||||
log.Println("[INFO] Initializing AutoScaling SDK connection")
|
||||
log.Println("[INFO] Initializing AutoScaling connection")
|
||||
client.autoscalingconn = autoscaling.New(awsConfig)
|
||||
|
||||
log.Println("[INFO] Initializing EC2 SDK Connection")
|
||||
client.ec2SDKconn = awsEC2.New(awsConfig)
|
||||
log.Println("[INFO] Initializing EC2 Connection")
|
||||
client.ec2conn = ec2.New(awsConfig)
|
||||
|
||||
// aws-sdk-go uses v4 for signing requests, which requires all global
|
||||
// endpoints to use 'us-east-1'.
|
||||
// See http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html
|
||||
log.Println("[INFO] Initializing Route 53 SDK connection")
|
||||
client.r53conn = route53.New(&awsSDK.Config{
|
||||
Credentials: sdkCreds,
|
||||
log.Println("[INFO] Initializing Route 53 connection")
|
||||
client.r53conn = route53.New(&aws.Config{
|
||||
Credentials: creds,
|
||||
Region: "us-east-1",
|
||||
})
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
|||
autoScalingGroupOpts.LaunchConfigurationName = aws.String(d.Get("launch_configuration").(string))
|
||||
autoScalingGroupOpts.MinSize = aws.Long(int64(d.Get("min_size").(int)))
|
||||
autoScalingGroupOpts.MaxSize = aws.Long(int64(d.Get("max_size").(int)))
|
||||
autoScalingGroupOpts.AvailabilityZones = expandStringListSDK(
|
||||
autoScalingGroupOpts.AvailabilityZones = expandStringList(
|
||||
d.Get("availability_zones").(*schema.Set).List())
|
||||
|
||||
if v, ok := d.GetOk("tag"); ok {
|
||||
|
@ -157,12 +157,12 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
if v, ok := d.GetOk("load_balancers"); ok && v.(*schema.Set).Len() > 0 {
|
||||
autoScalingGroupOpts.LoadBalancerNames = expandStringListSDK(
|
||||
autoScalingGroupOpts.LoadBalancerNames = expandStringList(
|
||||
v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("vpc_zone_identifier"); ok && v.(*schema.Set).Len() > 0 {
|
||||
exp := expandStringListSDK(v.(*schema.Set).List())
|
||||
exp := expandStringList(v.(*schema.Set).List())
|
||||
strs := make([]string, len(exp))
|
||||
for _, s := range exp {
|
||||
strs = append(strs, *s)
|
||||
|
@ -171,7 +171,7 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
if v, ok := d.GetOk("termination_policies"); ok && v.(*schema.Set).Len() > 0 {
|
||||
autoScalingGroupOpts.TerminationPolicies = expandStringListSDK(
|
||||
autoScalingGroupOpts.TerminationPolicies = expandStringList(
|
||||
v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
|
|||
return err
|
||||
}
|
||||
|
||||
d.Set("parameter", flattenParametersSDK(describeParametersResp.Parameters))
|
||||
d.Set("parameter", flattenParameters(describeParametersResp.Parameters))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{})
|
|||
ns := n.(*schema.Set)
|
||||
|
||||
// Expand the "parameter" set to aws-sdk-go compat []rds.Parameter
|
||||
parameters, err := expandParametersSDK(ns.Difference(os).List())
|
||||
parameters, err := expandParameters(ns.Difference(os).List())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func resourceAwsEip() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2SDKconn
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// By default, we're not in a VPC
|
||||
domainOpt := ""
|
||||
|
@ -97,7 +97,7 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2SDKconn
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
domain := resourceAwsEipDomain(d)
|
||||
id := d.Id()
|
||||
|
@ -148,7 +148,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2SDKconn
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
domain := resourceAwsEipDomain(d)
|
||||
|
||||
|
@ -181,7 +181,7 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2SDKconn
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
if err := resourceAwsEipRead(d, meta); err != nil {
|
||||
return err
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestAccAWSEIP_instance(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckAWSEIPDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_eip" {
|
||||
|
@ -113,7 +113,7 @@ func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc
|
|||
return fmt.Errorf("No EIP ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
if strings.Contains(rs.Primary.ID, "eipalloc") {
|
||||
req := &ec2.DescribeAddressesInput{
|
||||
|
|
|
@ -164,7 +164,7 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
elbconn := meta.(*AWSClient).elbconn
|
||||
|
||||
// Expand the "listener" set to aws-sdk-go compat []*elb.Listener
|
||||
listeners, err := expandListenersSDK(d.Get("listener").(*schema.Set).List())
|
||||
listeners, err := expandListeners(d.Get("listener").(*schema.Set).List())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -182,15 +182,15 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
if v, ok := d.GetOk("availability_zones"); ok {
|
||||
elbOpts.AvailabilityZones = expandStringListSDK(v.(*schema.Set).List())
|
||||
elbOpts.AvailabilityZones = expandStringList(v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("security_groups"); ok {
|
||||
elbOpts.SecurityGroups = expandStringListSDK(v.(*schema.Set).List())
|
||||
elbOpts.SecurityGroups = expandStringList(v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("subnets"); ok {
|
||||
elbOpts.Subnets = expandStringListSDK(v.(*schema.Set).List())
|
||||
elbOpts.Subnets = expandStringList(v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] ELB create configuration: %#v", elbOpts)
|
||||
|
@ -267,8 +267,8 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
|
|||
d.Set("dns_name", *lb.DNSName)
|
||||
d.Set("internal", *lb.Scheme == "internal")
|
||||
d.Set("availability_zones", lb.AvailabilityZones)
|
||||
d.Set("instances", flattenInstancesSDK(lb.Instances))
|
||||
d.Set("listener", flattenListenersSDK(lb.ListenerDescriptions))
|
||||
d.Set("instances", flattenInstances(lb.Instances))
|
||||
d.Set("listener", flattenListeners(lb.ListenerDescriptions))
|
||||
d.Set("security_groups", lb.SecurityGroups)
|
||||
d.Set("subnets", lb.Subnets)
|
||||
|
||||
|
@ -284,7 +284,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
|
|||
// There's only one health check, so save that to state as we
|
||||
// currently can
|
||||
if *lb.HealthCheck.Target != "" {
|
||||
d.Set("health_check", flattenHealthCheckSDK(lb.HealthCheck))
|
||||
d.Set("health_check", flattenHealthCheck(lb.HealthCheck))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -302,8 +302,8 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
o, n := d.GetChange("instances")
|
||||
os := o.(*schema.Set)
|
||||
ns := n.(*schema.Set)
|
||||
remove := expandInstanceStringSDK(os.Difference(ns).List())
|
||||
add := expandInstanceStringSDK(ns.Difference(os).List())
|
||||
remove := expandInstanceString(os.Difference(ns).List())
|
||||
add := expandInstanceString(ns.Difference(os).List())
|
||||
|
||||
if len(add) > 0 {
|
||||
registerInstancesOpts := elb.RegisterInstancesWithLoadBalancerInput{
|
||||
|
|
|
@ -299,7 +299,7 @@ func resourceAwsInstance() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Figure out user data
|
||||
userData := ""
|
||||
|
@ -547,7 +547,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||
InstanceIDs: []*string{aws.String(d.Id())},
|
||||
|
@ -644,7 +644,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
d.Partial(true)
|
||||
|
||||
|
@ -676,7 +676,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf("[INFO] Terminating instance: %s", d.Id())
|
||||
req := &ec2.TerminateInstancesInput{
|
||||
|
|
|
@ -41,7 +41,7 @@ func TestAccAWSInstance_normal(t *testing.T) {
|
|||
// Need a resource in this config so the provisioner will be available
|
||||
Config: testAccInstanceConfig_pre,
|
||||
Check: func(*terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
var err error
|
||||
vol, err = conn.CreateVolume(&ec2.CreateVolumeInput{
|
||||
AvailabilityZone: aws.String("us-west-2a"),
|
||||
|
@ -88,7 +88,7 @@ func TestAccAWSInstance_normal(t *testing.T) {
|
|||
resource.TestStep{
|
||||
Config: testAccInstanceConfig,
|
||||
Check: func(*terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
_, err := conn.DeleteVolume(&ec2.DeleteVolumeInput{VolumeID: vol.VolumeID})
|
||||
return err
|
||||
},
|
||||
|
@ -364,7 +364,7 @@ func TestAccAWSInstance_associatePublicIPAndPrivateIP(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckInstanceDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_instance" {
|
||||
|
@ -407,7 +407,7 @@ func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFun
|
|||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||
InstanceIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
|
|
@ -29,7 +29,7 @@ func resourceAwsInternetGateway() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Create the gateway
|
||||
log.Printf("[DEBUG] Creating internet gateway")
|
||||
|
@ -53,7 +53,7 @@ func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
func resourceAwsInternetGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
igRaw, _, err := IGStateRefreshFunc(conn, d.Id())()
|
||||
if err != nil {
|
||||
|
@ -91,7 +91,7 @@ func resourceAwsInternetGatewayUpdate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
}
|
||||
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
if err := setTagsSDK(conn, d); err != nil {
|
||||
return err
|
||||
|
@ -103,7 +103,7 @@ func resourceAwsInternetGatewayUpdate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Detach if it is attached
|
||||
if err := resourceAwsInternetGatewayDetach(d, meta); err != nil {
|
||||
|
@ -137,7 +137,7 @@ func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
if d.Get("vpc_id").(string) == "" {
|
||||
log.Printf(
|
||||
|
@ -182,7 +182,7 @@ func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Get the old VPC ID to detach from
|
||||
vpcID, _ := d.GetChange("vpc_id")
|
||||
|
|
|
@ -115,7 +115,7 @@ func TestAccAWSInternetGateway_tags(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_internet_gateway" {
|
||||
|
@ -158,7 +158,7 @@ func testAccCheckInternetGatewayExists(n string, ig *ec2.InternetGateway) resour
|
|||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysInput{
|
||||
InternetGatewayIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
|
|
@ -36,7 +36,7 @@ func resourceAwsKeyPair() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
keyName := d.Get("key_name").(string)
|
||||
publicKey := d.Get("public_key").(string)
|
||||
|
@ -54,7 +54,7 @@ func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
req := &ec2.DescribeKeyPairsInput{
|
||||
KeyNames: []*string{aws.String(d.Id())},
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsKeyPairDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
_, err := conn.DeleteKeyPair(&ec2.DeleteKeyPairInput{
|
||||
KeyName: aws.String(d.Id()),
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestAccAWSKeyPair_normal(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckAWSKeyPairDestroy(s *terraform.State) error {
|
||||
ec2SDKconn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_key_pair" {
|
||||
|
@ -38,7 +38,7 @@ func testAccCheckAWSKeyPairDestroy(s *terraform.State) error {
|
|||
}
|
||||
|
||||
// Try to find key pair
|
||||
resp, err := ec2SDKconn.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{
|
||||
resp, err := ec2conn.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{
|
||||
KeyNames: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
if err == nil {
|
||||
|
@ -81,9 +81,9 @@ func testAccCheckAWSKeyPairExists(n string, res *ec2.KeyPairInfo) resource.TestC
|
|||
return fmt.Errorf("No KeyPair name is set")
|
||||
}
|
||||
|
||||
ec2SDKconn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
resp, err := ec2SDKconn.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{
|
||||
resp, err := ec2conn.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{
|
||||
KeyNames: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -243,7 +243,7 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
|
|||
|
||||
func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||
ec2conn := meta.(*AWSClient).ec2SDKconn
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
createLaunchConfigurationOpts := autoscaling.CreateLaunchConfigurationInput{
|
||||
LaunchConfigurationName: aws.String(d.Get("name").(string)),
|
||||
|
@ -277,7 +277,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
|||
}
|
||||
|
||||
if v, ok := d.GetOk("security_groups"); ok {
|
||||
createLaunchConfigurationOpts.SecurityGroups = expandStringListSDK(
|
||||
createLaunchConfigurationOpts.SecurityGroups = expandStringList(
|
||||
v.(*schema.Set).List(),
|
||||
)
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
|||
|
||||
func resourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface{}) error {
|
||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||
ec2conn := meta.(*AWSClient).ec2SDKconn
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
describeOpts := autoscaling.DescribeLaunchConfigurationsInput{
|
||||
LaunchConfigurationNames: []*string{aws.String(d.Id())},
|
||||
|
|
|
@ -40,7 +40,7 @@ func resourceAwsMainRouteTableAssociation() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsMainRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
vpcId := d.Get("vpc_id").(string)
|
||||
routeTableId := d.Get("route_table_id").(string)
|
||||
|
||||
|
@ -67,7 +67,7 @@ func resourceAwsMainRouteTableAssociationCreate(d *schema.ResourceData, meta int
|
|||
}
|
||||
|
||||
func resourceAwsMainRouteTableAssociationRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
mainAssociation, err := findMainRouteTableAssociation(
|
||||
conn,
|
||||
|
@ -88,7 +88,7 @@ func resourceAwsMainRouteTableAssociationRead(d *schema.ResourceData, meta inter
|
|||
// original_route_table_id - this needs to stay recorded as the AWS-created
|
||||
// table from VPC creation.
|
||||
func resourceAwsMainRouteTableAssociationUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
vpcId := d.Get("vpc_id").(string)
|
||||
routeTableId := d.Get("route_table_id").(string)
|
||||
|
||||
|
@ -109,7 +109,7 @@ func resourceAwsMainRouteTableAssociationUpdate(d *schema.ResourceData, meta int
|
|||
}
|
||||
|
||||
func resourceAwsMainRouteTableAssociationDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
vpcId := d.Get("vpc_id").(string)
|
||||
originalRouteTableId := d.Get("original_route_table_id").(string)
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ func testAccCheckMainRouteTableAssociation(
|
|||
return fmt.Errorf("Not found: %s", vpcResource)
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
mainAssociation, err := findMainRouteTableAssociation(conn, vpc.Primary.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -109,7 +109,7 @@ func resourceAwsNetworkAcl() *schema.Resource {
|
|||
|
||||
func resourceAwsNetworkAclCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Create the Network Acl
|
||||
createOpts := &ec2.CreateNetworkACLInput{
|
||||
|
@ -132,7 +132,7 @@ func resourceAwsNetworkAclCreate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsNetworkAclRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
|
||||
NetworkACLIDs: []*string{aws.String(d.Id())},
|
||||
|
@ -167,7 +167,7 @@ func resourceAwsNetworkAclRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
d.Partial(true)
|
||||
|
||||
if d.HasChange("ingress") {
|
||||
|
@ -265,7 +265,7 @@ func updateNetworkAclEntries(d *schema.ResourceData, entryType string, conn *ec2
|
|||
}
|
||||
|
||||
func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf("[INFO] Deleting Network Acl: %s", d.Id())
|
||||
return resource.Retry(5*time.Minute, func() error {
|
||||
|
|
|
@ -4,12 +4,10 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
// "github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
// "github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSNetworkAcl_EgressAndIngressRules(t *testing.T) {
|
||||
|
@ -151,7 +149,7 @@ func TestAccAWSNetworkAcl_OnlyEgressRules(t *testing.T) {
|
|||
Config: testAccAWSNetworkAclEgressConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSNetworkAclExists("aws_network_acl.bond", &networkAcl),
|
||||
testAccCheckTags(&networkAcl.Tags, "foo", "bar"),
|
||||
testAccCheckTagsSDK(&networkAcl.Tags, "foo", "bar"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -192,8 +190,8 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
|||
}
|
||||
|
||||
// Retrieve the network acl
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{rs.Primary.ID},
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
|
||||
NetworkACLIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
if err == nil {
|
||||
if len(resp.NetworkACLs) > 0 && *resp.NetworkACLs[0].NetworkACLID == rs.Primary.ID {
|
||||
|
@ -228,15 +226,15 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkACL) resou
|
|||
}
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{rs.Primary.ID},
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
|
||||
NetworkACLIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(resp.NetworkACLs) > 0 && *resp.NetworkACLs[0].NetworkACLID == rs.Primary.ID {
|
||||
*networkAcl = resp.NetworkACLs[0]
|
||||
*networkAcl = *resp.NetworkACLs[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -246,7 +244,7 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkACL) resou
|
|||
|
||||
func testIngressRuleLength(networkAcl *ec2.NetworkACL, length int) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
var ingressEntries []ec2.NetworkACLEntry
|
||||
var ingressEntries []*ec2.NetworkACLEntry
|
||||
for _, e := range networkAcl.Entries {
|
||||
if *e.Egress == false {
|
||||
ingressEntries = append(ingressEntries, e)
|
||||
|
@ -267,12 +265,12 @@ func testAccCheckSubnetIsAssociatedWithAcl(acl string, sub string) resource.Test
|
|||
subnet := s.RootModule().Resources[sub]
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
||||
Filters: []ec2.Filter{
|
||||
ec2.Filter{
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
|
||||
NetworkACLIDs: []*string{aws.String(networkAcl.Primary.ID)},
|
||||
Filters: []*ec2.Filter{
|
||||
&ec2.Filter{
|
||||
Name: aws.String("association.subnet-id"),
|
||||
Values: []string{subnet.Primary.ID},
|
||||
Values: []*string{aws.String(subnet.Primary.ID)},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -297,12 +295,12 @@ func testAccCheckSubnetIsNotAssociatedWithAcl(acl string, subnet string) resourc
|
|||
subnet := s.RootModule().Resources[subnet]
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
||||
Filters: []ec2.Filter{
|
||||
ec2.Filter{
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsInput{
|
||||
NetworkACLIDs: []*string{aws.String(networkAcl.Primary.ID)},
|
||||
Filters: []*ec2.Filter{
|
||||
&ec2.Filter{
|
||||
Name: aws.String("association.subnet-id"),
|
||||
Values: []string{subnet.Primary.ID},
|
||||
Values: []*string{aws.String(subnet.Primary.ID)},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
@ -78,12 +78,12 @@ func resourceAwsNetworkInterface() *schema.Resource {
|
|||
|
||||
func resourceAwsNetworkInterfaceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
request := &ec2.CreateNetworkInterfaceInput{
|
||||
Groups: expandStringListSDK(d.Get("security_groups").(*schema.Set).List()),
|
||||
Groups: expandStringList(d.Get("security_groups").(*schema.Set).List()),
|
||||
SubnetID: aws.String(d.Get("subnet_id").(string)),
|
||||
PrivateIPAddresses: expandPrivateIPAddessesSDK(d.Get("private_ips").(*schema.Set).List()),
|
||||
PrivateIPAddresses: expandPrivateIPAddesses(d.Get("private_ips").(*schema.Set).List()),
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Creating network interface")
|
||||
|
@ -99,7 +99,7 @@ func resourceAwsNetworkInterfaceCreate(d *schema.ResourceData, meta interface{})
|
|||
|
||||
func resourceAwsNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
describe_network_interfaces_request := &ec2.DescribeNetworkInterfacesInput{
|
||||
NetworkInterfaceIDs: []*string{aws.String(d.Id())},
|
||||
}
|
||||
|
@ -120,14 +120,14 @@ func resourceAwsNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
eni := describeResp.NetworkInterfaces[0]
|
||||
d.Set("subnet_id", eni.SubnetID)
|
||||
d.Set("private_ips", flattenNetworkInterfacesPrivateIPAddessesSDK(eni.PrivateIPAddresses))
|
||||
d.Set("security_groups", flattenGroupIdentifiersSDK(eni.Groups))
|
||||
d.Set("private_ips", flattenNetworkInterfacesPrivateIPAddesses(eni.PrivateIPAddresses))
|
||||
d.Set("security_groups", flattenGroupIdentifiers(eni.Groups))
|
||||
|
||||
// Tags
|
||||
d.Set("tags", tagsToMapSDK(eni.TagSet))
|
||||
|
||||
if eni.Attachment != nil {
|
||||
attachment := []map[string]interface{}{flattenAttachmentSDK(eni.Attachment)}
|
||||
attachment := []map[string]interface{}{flattenAttachment(eni.Attachment)}
|
||||
d.Set("attachment", attachment)
|
||||
} else {
|
||||
d.Set("attachment", nil)
|
||||
|
@ -164,7 +164,7 @@ func resourceAwsNetworkInterfaceDetach(oa *schema.Set, meta interface{}, eniId s
|
|||
AttachmentID: aws.String(old_attachment["attachment_id"].(string)),
|
||||
Force: aws.Boolean(true),
|
||||
}
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
_, detach_err := conn.DetachNetworkInterface(detach_request)
|
||||
if detach_err != nil {
|
||||
return fmt.Errorf("Error detaching ENI: %s", detach_err)
|
||||
|
@ -187,7 +187,7 @@ func resourceAwsNetworkInterfaceDetach(oa *schema.Set, meta interface{}, eniId s
|
|||
}
|
||||
|
||||
func resourceAwsNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
d.Partial(true)
|
||||
|
||||
if d.HasChange("attachment") {
|
||||
|
@ -219,7 +219,7 @@ func resourceAwsNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{})
|
|||
if d.HasChange("security_groups") {
|
||||
request := &ec2.ModifyNetworkInterfaceAttributeInput{
|
||||
NetworkInterfaceID: aws.String(d.Id()),
|
||||
Groups: expandStringListSDK(d.Get("security_groups").(*schema.Set).List()),
|
||||
Groups: expandStringList(d.Get("security_groups").(*schema.Set).List()),
|
||||
}
|
||||
|
||||
_, err := conn.ModifyNetworkInterfaceAttribute(request)
|
||||
|
@ -242,7 +242,7 @@ func resourceAwsNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
func resourceAwsNetworkInterfaceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf("[INFO] Deleting ENI: %s", d.Id())
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ func testAccCheckAWSENIExists(n string, res *ec2.NetworkInterface) resource.Test
|
|||
return fmt.Errorf("No ENI ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
describe_network_interfaces_request := &ec2.DescribeNetworkInterfacesInput{
|
||||
NetworkInterfaceIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func testAccCheckAWSENIDestroy(s *terraform.State) error {
|
|||
continue
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
describe_network_interfaces_request := &ec2.DescribeNetworkInterfacesInput{
|
||||
NetworkInterfaceIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func resourceAwsRouteTable() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Create the routing table
|
||||
createOpts := &ec2.CreateRouteTableInput{
|
||||
|
@ -100,7 +100,7 @@ func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(conn, d.Id())()
|
||||
if err != nil {
|
||||
|
@ -153,7 +153,7 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Check if the route set as a whole has changed
|
||||
if d.HasChange("route") {
|
||||
|
@ -214,7 +214,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// First request the routing table since we'll have to disassociate
|
||||
// all the subnets first.
|
||||
|
|
|
@ -32,7 +32,7 @@ func resourceAwsRouteTableAssociation() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf(
|
||||
"[INFO] Creating route table association: %s => %s",
|
||||
|
@ -56,7 +56,7 @@ func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interfa
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableAssociationRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Get the routing table that this association belongs to
|
||||
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(
|
||||
|
@ -88,7 +88,7 @@ func resourceAwsRouteTableAssociationRead(d *schema.ResourceData, meta interface
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf(
|
||||
"[INFO] Creating route table association: %s => %s",
|
||||
|
@ -119,7 +119,7 @@ func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interfa
|
|||
}
|
||||
|
||||
func resourceAwsRouteTableAssociationDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf("[INFO] Deleting route table association: %s", d.Id())
|
||||
_, err := conn.DisassociateRouteTable(&ec2.DisassociateRouteTableInput{
|
||||
|
|
|
@ -38,7 +38,7 @@ func TestAccAWSRouteTableAssociation(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_route_table_association" {
|
||||
|
@ -83,7 +83,7 @@ func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resour
|
|||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||
RouteTableIDs: []*string{aws.String(rs.Primary.Attributes["route_table_id"])},
|
||||
})
|
||||
|
|
|
@ -151,7 +151,7 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckRouteTableDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_route_table" {
|
||||
|
@ -194,7 +194,7 @@ func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestChec
|
|||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||
RouteTableIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
|
|
@ -142,7 +142,7 @@ func resourceAwsSecurityGroup() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsSecurityGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
securityGroupOpts := &ec2.CreateSecurityGroupInput{
|
||||
GroupName: aws.String(d.Get("name").(string)),
|
||||
|
@ -187,7 +187,7 @@ func resourceAwsSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er
|
|||
}
|
||||
|
||||
func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
sgRaw, _, err := SGStateRefreshFunc(conn, d.Id())()
|
||||
if err != nil {
|
||||
|
@ -214,7 +214,7 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
|
|||
}
|
||||
|
||||
func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
sgRaw, _, err := SGStateRefreshFunc(conn, d.Id())()
|
||||
if err != nil {
|
||||
|
@ -249,7 +249,7 @@ func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) er
|
|||
}
|
||||
|
||||
func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf("[DEBUG] Security Group destroy: %v", d.Id())
|
||||
|
||||
|
@ -355,7 +355,7 @@ func resourceAwsSecurityGroupIPPermGather(d *schema.ResourceData, permissions []
|
|||
|
||||
var groups []string
|
||||
if len(perm.UserIDGroupPairs) > 0 {
|
||||
groups = flattenSecurityGroupsSDK(perm.UserIDGroupPairs)
|
||||
groups = flattenSecurityGroups(perm.UserIDGroupPairs)
|
||||
}
|
||||
for i, id := range groups {
|
||||
if id == d.Id() {
|
||||
|
@ -398,8 +398,8 @@ func resourceAwsSecurityGroupUpdateRules(
|
|||
os := o.(*schema.Set)
|
||||
ns := n.(*schema.Set)
|
||||
|
||||
remove := expandIPPermsSDK(group, os.Difference(ns).List())
|
||||
add := expandIPPermsSDK(group, ns.Difference(os).List())
|
||||
remove := expandIPPerms(group, os.Difference(ns).List())
|
||||
add := expandIPPerms(group, ns.Difference(os).List())
|
||||
|
||||
// TODO: We need to handle partial state better in the in-between
|
||||
// in this update.
|
||||
|
@ -411,7 +411,7 @@ func resourceAwsSecurityGroupUpdateRules(
|
|||
// not have service issues.
|
||||
|
||||
if len(remove) > 0 || len(add) > 0 {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
var err error
|
||||
if len(remove) > 0 {
|
||||
|
|
|
@ -185,7 +185,7 @@ func TestAccAWSSecurityGroup_Change(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_security_group" {
|
||||
|
@ -229,7 +229,7 @@ func testAccCheckAWSSecurityGroupExists(n string, group *ec2.SecurityGroup) reso
|
|||
return fmt.Errorf("No Security Group is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
req := &ec2.DescribeSecurityGroupsInput{
|
||||
GroupIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func resourceAwsSubnet() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
createOpts := &ec2.CreateSubnetInput{
|
||||
AvailabilityZone: aws.String(d.Get("availability_zone").(string)),
|
||||
|
@ -91,7 +91,7 @@ func resourceAwsSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsInput{
|
||||
SubnetIDs: []*string{aws.String(d.Id())},
|
||||
|
@ -121,7 +121,7 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
d.Partial(true)
|
||||
|
||||
|
@ -156,7 +156,7 @@ func resourceAwsSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
log.Printf("[INFO] Deleting subnet: %s", d.Id())
|
||||
req := &ec2.DeleteSubnetInput{
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestAccAWSSubnet(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckSubnetDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_subnet" {
|
||||
|
@ -86,7 +86,7 @@ func testAccCheckSubnetExists(n string, v *ec2.Subnet) resource.TestCheckFunc {
|
|||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsInput{
|
||||
SubnetIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
|
|
@ -64,7 +64,7 @@ func resourceAwsVpc() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
instance_tenancy := "default"
|
||||
if v, ok := d.GetOk("instance_tenancy"); ok {
|
||||
instance_tenancy = v.(string)
|
||||
|
@ -110,7 +110,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Refresh the VPC state
|
||||
vpcRaw, _, err := VPCStateRefreshFunc(conn, d.Id())()
|
||||
|
@ -180,7 +180,7 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Turn on partial mode
|
||||
d.Partial(true)
|
||||
|
@ -234,7 +234,7 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
vpcID := d.Id()
|
||||
DeleteVpcOpts := &ec2.DeleteVPCInput{
|
||||
VPCID: &vpcID,
|
||||
|
|
|
@ -41,7 +41,7 @@ func resourceAwsVpcPeeringConnection() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Create the vpc peering connection
|
||||
createOpts := &ec2.CreateVPCPeeringConnectionInput{
|
||||
|
@ -80,7 +80,7 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id())()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -101,7 +101,7 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
if err := setTagsSDK(conn, d); err != nil {
|
||||
return err
|
||||
|
@ -113,7 +113,7 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
_, err := conn.DeleteVPCPeeringConnection(
|
||||
&ec2.DeleteVPCPeeringConnectionInput{
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestAccAWSVPCPeeringConnection_normal(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_vpc_peering_connection" {
|
||||
|
|
|
@ -112,7 +112,7 @@ func TestAccVpcUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckVpcDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_vpc" {
|
||||
|
@ -167,7 +167,7 @@ func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc {
|
|||
return fmt.Errorf("No VPC ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
DescribeVpcOpts := &ec2.DescribeVPCsInput{
|
||||
VPCIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func resourceAwsVpnGateway() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
createOpts := &ec2.CreateVPNGatewayInput{
|
||||
AvailabilityZone: aws.String(d.Get("availability_zone").(string)),
|
||||
|
@ -60,7 +60,7 @@ func resourceAwsVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
resp, err := conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysInput{
|
||||
VPNGatewayIDs: []*string{aws.String(d.Id())},
|
||||
|
@ -107,7 +107,7 @@ func resourceAwsVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
}
|
||||
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
if err := setTagsSDK(conn, d); err != nil {
|
||||
return err
|
||||
|
@ -119,7 +119,7 @@ func resourceAwsVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Detach if it is attached
|
||||
if err := resourceAwsVpnGatewayDetach(d, meta); err != nil {
|
||||
|
@ -153,7 +153,7 @@ func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
if d.Get("vpc_id").(string) == "" {
|
||||
log.Printf(
|
||||
|
@ -198,7 +198,7 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error
|
|||
}
|
||||
|
||||
func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2SDKconn
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
// Get the old VPC ID to detach from
|
||||
vpcID, _ := d.GetChange("vpc_id")
|
||||
|
|
|
@ -115,7 +115,7 @@ func TestAccVpnGateway_tags(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccCheckVpnGatewayDestroy(s *terraform.State) error {
|
||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_vpn_gateway" {
|
||||
|
@ -158,7 +158,7 @@ func testAccCheckVpnGatewayExists(n string, ig *ec2.VPNGateway) resource.TestChe
|
|||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
resp, err := ec2conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysInput{
|
||||
VPNGatewayIDs: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
// Takes the result of flatmap.Expand for an array of listeners and
|
||||
// returns ELB API compatible objects
|
||||
func expandListeners(configured []interface{}) ([]elb.Listener, error) {
|
||||
listeners := make([]elb.Listener, 0, len(configured))
|
||||
func expandListeners(configured []interface{}) ([]*elb.Listener, error) {
|
||||
listeners := make([]*elb.Listener, 0, len(configured))
|
||||
|
||||
// Loop over our configured listeners and create
|
||||
// an array of aws-sdk-go compatabile objects
|
||||
for _, lRaw := range configured {
|
||||
data := lRaw.(map[string]interface{})
|
||||
|
||||
l := elb.Listener{
|
||||
InstancePort: aws.Integer(data["instance_port"].(int)),
|
||||
ip := int64(data["instance_port"].(int))
|
||||
lp := int64(data["lb_port"].(int))
|
||||
l := &elb.Listener{
|
||||
InstancePort: &ip,
|
||||
InstanceProtocol: aws.String(data["instance_protocol"].(string)),
|
||||
LoadBalancerPort: aws.Integer(data["lb_port"].(int)),
|
||||
LoadBalancerPort: &lp,
|
||||
Protocol: aws.String(data["lb_protocol"].(string)),
|
||||
}
|
||||
|
||||
|
@ -40,16 +44,16 @@ func expandListeners(configured []interface{}) ([]elb.Listener, error) {
|
|||
// Takes the result of flatmap.Expand for an array of ingress/egress
|
||||
// security group rules and returns EC2 API compatible objects
|
||||
func expandIPPerms(
|
||||
group ec2.SecurityGroup, configured []interface{}) []ec2.IPPermission {
|
||||
group *ec2.SecurityGroup, configured []interface{}) []*ec2.IPPermission {
|
||||
vpc := group.VPCID != nil
|
||||
|
||||
perms := make([]ec2.IPPermission, len(configured))
|
||||
perms := make([]*ec2.IPPermission, len(configured))
|
||||
for i, mRaw := range configured {
|
||||
var perm ec2.IPPermission
|
||||
m := mRaw.(map[string]interface{})
|
||||
|
||||
perm.FromPort = aws.Integer(m["from_port"].(int))
|
||||
perm.ToPort = aws.Integer(m["to_port"].(int))
|
||||
perm.FromPort = aws.Long(int64(m["from_port"].(int)))
|
||||
perm.ToPort = aws.Long(int64(m["to_port"].(int)))
|
||||
perm.IPProtocol = aws.String(m["protocol"].(string))
|
||||
|
||||
var groups []string
|
||||
|
@ -68,14 +72,14 @@ func expandIPPerms(
|
|||
}
|
||||
|
||||
if len(groups) > 0 {
|
||||
perm.UserIDGroupPairs = make([]ec2.UserIDGroupPair, len(groups))
|
||||
perm.UserIDGroupPairs = make([]*ec2.UserIDGroupPair, len(groups))
|
||||
for i, name := range groups {
|
||||
ownerId, id := "", name
|
||||
if items := strings.Split(id, "/"); len(items) > 1 {
|
||||
ownerId, id = items[0], items[1]
|
||||
}
|
||||
|
||||
perm.UserIDGroupPairs[i] = ec2.UserIDGroupPair{
|
||||
perm.UserIDGroupPairs[i] = &ec2.UserIDGroupPair{
|
||||
GroupID: aws.String(id),
|
||||
UserID: aws.String(ownerId),
|
||||
}
|
||||
|
@ -89,13 +93,13 @@ func expandIPPerms(
|
|||
|
||||
if raw, ok := m["cidr_blocks"]; ok {
|
||||
list := raw.([]interface{})
|
||||
perm.IPRanges = make([]ec2.IPRange, len(list))
|
||||
perm.IPRanges = make([]*ec2.IPRange, len(list))
|
||||
for i, v := range list {
|
||||
perm.IPRanges[i] = ec2.IPRange{aws.String(v.(string))}
|
||||
perm.IPRanges[i] = &ec2.IPRange{CIDRIP: aws.String(v.(string))}
|
||||
}
|
||||
}
|
||||
|
||||
perms[i] = perm
|
||||
perms[i] = &perm
|
||||
}
|
||||
|
||||
return perms
|
||||
|
@ -103,15 +107,15 @@ func expandIPPerms(
|
|||
|
||||
// Takes the result of flatmap.Expand for an array of parameters and
|
||||
// returns Parameter API compatible objects
|
||||
func expandParameters(configured []interface{}) ([]rds.Parameter, error) {
|
||||
parameters := make([]rds.Parameter, 0, len(configured))
|
||||
func expandParameters(configured []interface{}) ([]*rds.Parameter, error) {
|
||||
parameters := make([]*rds.Parameter, 0, len(configured))
|
||||
|
||||
// Loop over our configured parameters and create
|
||||
// an array of aws-sdk-go compatabile objects
|
||||
for _, pRaw := range configured {
|
||||
data := pRaw.(map[string]interface{})
|
||||
|
||||
p := rds.Parameter{
|
||||
p := &rds.Parameter{
|
||||
ApplyMethod: aws.String(data["apply_method"].(string)),
|
||||
ParameterName: aws.String(data["name"].(string)),
|
||||
ParameterValue: aws.String(data["value"].(string)),
|
||||
|
@ -141,7 +145,7 @@ func flattenHealthCheck(check *elb.HealthCheck) []map[string]interface{} {
|
|||
}
|
||||
|
||||
// Flattens an array of UserSecurityGroups into a []string
|
||||
func flattenSecurityGroups(list []ec2.UserIDGroupPair) []string {
|
||||
func flattenSecurityGroups(list []*ec2.UserIDGroupPair) []string {
|
||||
result := make([]string, 0, len(list))
|
||||
for _, g := range list {
|
||||
result = append(result, *g.GroupID)
|
||||
|
@ -150,7 +154,7 @@ func flattenSecurityGroups(list []ec2.UserIDGroupPair) []string {
|
|||
}
|
||||
|
||||
// Flattens an array of Instances into a []string
|
||||
func flattenInstances(list []elb.Instance) []string {
|
||||
func flattenInstances(list []*elb.Instance) []string {
|
||||
result := make([]string, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, *i.InstanceID)
|
||||
|
@ -159,16 +163,16 @@ func flattenInstances(list []elb.Instance) []string {
|
|||
}
|
||||
|
||||
// Expands an array of String Instance IDs into a []Instances
|
||||
func expandInstanceString(list []interface{}) []elb.Instance {
|
||||
result := make([]elb.Instance, 0, len(list))
|
||||
func expandInstanceString(list []interface{}) []*elb.Instance {
|
||||
result := make([]*elb.Instance, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, elb.Instance{aws.String(i.(string))})
|
||||
result = append(result, &elb.Instance{InstanceID: aws.String(i.(string))})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Flattens an array of Listeners into a []map[string]interface{}
|
||||
func flattenListeners(list []elb.ListenerDescription) []map[string]interface{} {
|
||||
func flattenListeners(list []*elb.ListenerDescription) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, len(list))
|
||||
for _, i := range list {
|
||||
l := map[string]interface{}{
|
||||
|
@ -187,7 +191,7 @@ func flattenListeners(list []elb.ListenerDescription) []map[string]interface{} {
|
|||
}
|
||||
|
||||
// Flattens an array of Parameters into a []map[string]interface{}
|
||||
func flattenParameters(list []rds.Parameter) []map[string]interface{} {
|
||||
func flattenParameters(list []*rds.Parameter) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, map[string]interface{}{
|
||||
|
@ -200,16 +204,16 @@ func flattenParameters(list []rds.Parameter) []map[string]interface{} {
|
|||
|
||||
// Takes the result of flatmap.Expand for an array of strings
|
||||
// and returns a []string
|
||||
func expandStringList(configured []interface{}) []string {
|
||||
vs := make([]string, 0, len(configured))
|
||||
func expandStringList(configured []interface{}) []*string {
|
||||
vs := make([]*string, 0, len(configured))
|
||||
for _, v := range configured {
|
||||
vs = append(vs, v.(string))
|
||||
vs = append(vs, aws.String(v.(string)))
|
||||
}
|
||||
return vs
|
||||
}
|
||||
|
||||
//Flattens an array of private ip addresses into a []string, where the elements returned are the IP strings e.g. "192.168.0.0"
|
||||
func flattenNetworkInterfacesPrivateIPAddesses(dtos []ec2.NetworkInterfacePrivateIPAddress) []string {
|
||||
func flattenNetworkInterfacesPrivateIPAddesses(dtos []*ec2.NetworkInterfacePrivateIPAddress) []string {
|
||||
ips := make([]string, 0, len(dtos))
|
||||
for _, v := range dtos {
|
||||
ip := *v.PrivateIPAddress
|
||||
|
@ -219,7 +223,7 @@ func flattenNetworkInterfacesPrivateIPAddesses(dtos []ec2.NetworkInterfacePrivat
|
|||
}
|
||||
|
||||
//Flattens security group identifiers into a []string, where the elements returned are the GroupIDs
|
||||
func flattenGroupIdentifiers(dtos []ec2.GroupIdentifier) []string {
|
||||
func flattenGroupIdentifiers(dtos []*ec2.GroupIdentifier) []string {
|
||||
ids := make([]string, 0, len(dtos))
|
||||
for _, v := range dtos {
|
||||
group_id := *v.GroupID
|
||||
|
@ -229,10 +233,10 @@ func flattenGroupIdentifiers(dtos []ec2.GroupIdentifier) []string {
|
|||
}
|
||||
|
||||
//Expands an array of IPs into a ec2 Private IP Address Spec
|
||||
func expandPrivateIPAddesses(ips []interface{}) []ec2.PrivateIPAddressSpecification {
|
||||
dtos := make([]ec2.PrivateIPAddressSpecification, 0, len(ips))
|
||||
func expandPrivateIPAddesses(ips []interface{}) []*ec2.PrivateIPAddressSpecification {
|
||||
dtos := make([]*ec2.PrivateIPAddressSpecification, 0, len(ips))
|
||||
for i, v := range ips {
|
||||
new_private_ip := ec2.PrivateIPAddressSpecification{
|
||||
new_private_ip := &ec2.PrivateIPAddressSpecification{
|
||||
PrivateIPAddress: aws.String(v.(string)),
|
||||
}
|
||||
|
||||
|
@ -251,3 +255,29 @@ func flattenAttachment(a *ec2.NetworkInterfaceAttachment) map[string]interface{}
|
|||
att["attachment_id"] = *a.AttachmentID
|
||||
return att
|
||||
}
|
||||
|
||||
func flattenResourceRecords(recs []*route53.ResourceRecord) []string {
|
||||
strs := make([]string, 0, len(recs))
|
||||
for _, r := range recs {
|
||||
if r.Value != nil {
|
||||
s := strings.Replace(*r.Value, "\"", "", 2)
|
||||
strs = append(strs, s)
|
||||
}
|
||||
}
|
||||
return strs
|
||||
}
|
||||
|
||||
func expandResourceRecords(recs []interface{}, typeStr string) []*route53.ResourceRecord {
|
||||
records := make([]*route53.ResourceRecord, 0, len(recs))
|
||||
for _, r := range recs {
|
||||
s := r.(string)
|
||||
switch typeStr {
|
||||
case "TXT":
|
||||
str := fmt.Sprintf("\"%s\"", s)
|
||||
records = append(records, &route53.ResourceRecord{Value: aws.String(str)})
|
||||
default:
|
||||
records = append(records, &route53.ResourceRecord{Value: aws.String(s)})
|
||||
}
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
|
|
@ -1,283 +0,0 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
// Takes the result of flatmap.Expand for an array of listeners and
|
||||
// returns ELB API compatible objects
|
||||
func expandListenersSDK(configured []interface{}) ([]*elb.Listener, error) {
|
||||
listeners := make([]*elb.Listener, 0, len(configured))
|
||||
|
||||
// Loop over our configured listeners and create
|
||||
// an array of aws-sdk-go compatabile objects
|
||||
for _, lRaw := range configured {
|
||||
data := lRaw.(map[string]interface{})
|
||||
|
||||
ip := int64(data["instance_port"].(int))
|
||||
lp := int64(data["lb_port"].(int))
|
||||
l := &elb.Listener{
|
||||
InstancePort: &ip,
|
||||
InstanceProtocol: aws.String(data["instance_protocol"].(string)),
|
||||
LoadBalancerPort: &lp,
|
||||
Protocol: aws.String(data["lb_protocol"].(string)),
|
||||
}
|
||||
|
||||
if v, ok := data["ssl_certificate_id"]; ok {
|
||||
l.SSLCertificateID = aws.String(v.(string))
|
||||
}
|
||||
|
||||
listeners = append(listeners, l)
|
||||
}
|
||||
|
||||
return listeners, nil
|
||||
}
|
||||
|
||||
// Takes the result of flatmap.Expand for an array of ingress/egress
|
||||
// security group rules and returns EC2 API compatible objects
|
||||
func expandIPPermsSDK(
|
||||
group *ec2.SecurityGroup, configured []interface{}) []*ec2.IPPermission {
|
||||
vpc := group.VPCID != nil
|
||||
|
||||
perms := make([]*ec2.IPPermission, len(configured))
|
||||
for i, mRaw := range configured {
|
||||
var perm ec2.IPPermission
|
||||
m := mRaw.(map[string]interface{})
|
||||
|
||||
perm.FromPort = aws.Long(int64(m["from_port"].(int)))
|
||||
perm.ToPort = aws.Long(int64(m["to_port"].(int)))
|
||||
perm.IPProtocol = aws.String(m["protocol"].(string))
|
||||
|
||||
var groups []string
|
||||
if raw, ok := m["security_groups"]; ok {
|
||||
list := raw.(*schema.Set).List()
|
||||
for _, v := range list {
|
||||
groups = append(groups, v.(string))
|
||||
}
|
||||
}
|
||||
if v, ok := m["self"]; ok && v.(bool) {
|
||||
if vpc {
|
||||
groups = append(groups, *group.GroupID)
|
||||
} else {
|
||||
groups = append(groups, *group.GroupName)
|
||||
}
|
||||
}
|
||||
|
||||
if len(groups) > 0 {
|
||||
perm.UserIDGroupPairs = make([]*ec2.UserIDGroupPair, len(groups))
|
||||
for i, name := range groups {
|
||||
ownerId, id := "", name
|
||||
if items := strings.Split(id, "/"); len(items) > 1 {
|
||||
ownerId, id = items[0], items[1]
|
||||
}
|
||||
|
||||
perm.UserIDGroupPairs[i] = &ec2.UserIDGroupPair{
|
||||
GroupID: aws.String(id),
|
||||
UserID: aws.String(ownerId),
|
||||
}
|
||||
if !vpc {
|
||||
perm.UserIDGroupPairs[i].GroupID = nil
|
||||
perm.UserIDGroupPairs[i].GroupName = aws.String(id)
|
||||
perm.UserIDGroupPairs[i].UserID = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if raw, ok := m["cidr_blocks"]; ok {
|
||||
list := raw.([]interface{})
|
||||
perm.IPRanges = make([]*ec2.IPRange, len(list))
|
||||
for i, v := range list {
|
||||
perm.IPRanges[i] = &ec2.IPRange{CIDRIP: aws.String(v.(string))}
|
||||
}
|
||||
}
|
||||
|
||||
perms[i] = &perm
|
||||
}
|
||||
|
||||
return perms
|
||||
}
|
||||
|
||||
// Takes the result of flatmap.Expand for an array of parameters and
|
||||
// returns Parameter API compatible objects
|
||||
func expandParametersSDK(configured []interface{}) ([]*rds.Parameter, error) {
|
||||
parameters := make([]*rds.Parameter, 0, len(configured))
|
||||
|
||||
// Loop over our configured parameters and create
|
||||
// an array of aws-sdk-go compatabile objects
|
||||
for _, pRaw := range configured {
|
||||
data := pRaw.(map[string]interface{})
|
||||
|
||||
p := &rds.Parameter{
|
||||
ApplyMethod: aws.String(data["apply_method"].(string)),
|
||||
ParameterName: aws.String(data["name"].(string)),
|
||||
ParameterValue: aws.String(data["value"].(string)),
|
||||
}
|
||||
|
||||
parameters = append(parameters, p)
|
||||
}
|
||||
|
||||
return parameters, nil
|
||||
}
|
||||
|
||||
// Flattens a health check into something that flatmap.Flatten()
|
||||
// can handle
|
||||
func flattenHealthCheckSDK(check *elb.HealthCheck) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, 1)
|
||||
|
||||
chk := make(map[string]interface{})
|
||||
chk["unhealthy_threshold"] = *check.UnhealthyThreshold
|
||||
chk["healthy_threshold"] = *check.HealthyThreshold
|
||||
chk["target"] = *check.Target
|
||||
chk["timeout"] = *check.Timeout
|
||||
chk["interval"] = *check.Interval
|
||||
|
||||
result = append(result, chk)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Flattens an array of UserSecurityGroups into a []string
|
||||
func flattenSecurityGroupsSDK(list []*ec2.UserIDGroupPair) []string {
|
||||
result := make([]string, 0, len(list))
|
||||
for _, g := range list {
|
||||
result = append(result, *g.GroupID)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Flattens an array of Instances into a []string
|
||||
func flattenInstancesSDK(list []*elb.Instance) []string {
|
||||
result := make([]string, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, *i.InstanceID)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Expands an array of String Instance IDs into a []Instances
|
||||
func expandInstanceStringSDK(list []interface{}) []*elb.Instance {
|
||||
result := make([]*elb.Instance, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, &elb.Instance{InstanceID: aws.String(i.(string))})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Flattens an array of Listeners into a []map[string]interface{}
|
||||
func flattenListenersSDK(list []*elb.ListenerDescription) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, len(list))
|
||||
for _, i := range list {
|
||||
l := map[string]interface{}{
|
||||
"instance_port": *i.Listener.InstancePort,
|
||||
"instance_protocol": strings.ToLower(*i.Listener.InstanceProtocol),
|
||||
"lb_port": *i.Listener.LoadBalancerPort,
|
||||
"lb_protocol": strings.ToLower(*i.Listener.Protocol),
|
||||
}
|
||||
// SSLCertificateID is optional, and may be nil
|
||||
if i.Listener.SSLCertificateID != nil {
|
||||
l["ssl_certificate_id"] = *i.Listener.SSLCertificateID
|
||||
}
|
||||
result = append(result, l)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Flattens an array of Parameters into a []map[string]interface{}
|
||||
func flattenParametersSDK(list []*rds.Parameter) []map[string]interface{} {
|
||||
result := make([]map[string]interface{}, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, map[string]interface{}{
|
||||
"name": strings.ToLower(*i.ParameterName),
|
||||
"value": strings.ToLower(*i.ParameterValue),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Takes the result of flatmap.Expand for an array of strings
|
||||
// and returns a []string
|
||||
func expandStringListSDK(configured []interface{}) []*string {
|
||||
vs := make([]*string, 0, len(configured))
|
||||
for _, v := range configured {
|
||||
vs = append(vs, aws.String(v.(string)))
|
||||
}
|
||||
return vs
|
||||
}
|
||||
|
||||
//Flattens an array of private ip addresses into a []string, where the elements returned are the IP strings e.g. "192.168.0.0"
|
||||
func flattenNetworkInterfacesPrivateIPAddessesSDK(dtos []*ec2.NetworkInterfacePrivateIPAddress) []string {
|
||||
ips := make([]string, 0, len(dtos))
|
||||
for _, v := range dtos {
|
||||
ip := *v.PrivateIPAddress
|
||||
ips = append(ips, ip)
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
//Flattens security group identifiers into a []string, where the elements returned are the GroupIDs
|
||||
func flattenGroupIdentifiersSDK(dtos []*ec2.GroupIdentifier) []string {
|
||||
ids := make([]string, 0, len(dtos))
|
||||
for _, v := range dtos {
|
||||
group_id := *v.GroupID
|
||||
ids = append(ids, group_id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
//Expands an array of IPs into a ec2 Private IP Address Spec
|
||||
func expandPrivateIPAddessesSDK(ips []interface{}) []*ec2.PrivateIPAddressSpecification {
|
||||
dtos := make([]*ec2.PrivateIPAddressSpecification, 0, len(ips))
|
||||
for i, v := range ips {
|
||||
new_private_ip := &ec2.PrivateIPAddressSpecification{
|
||||
PrivateIPAddress: aws.String(v.(string)),
|
||||
}
|
||||
|
||||
new_private_ip.Primary = aws.Boolean(i == 0)
|
||||
|
||||
dtos = append(dtos, new_private_ip)
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
//Flattens network interface attachment into a map[string]interface
|
||||
func flattenAttachmentSDK(a *ec2.NetworkInterfaceAttachment) map[string]interface{} {
|
||||
att := make(map[string]interface{})
|
||||
att["instance"] = *a.InstanceID
|
||||
att["device_index"] = *a.DeviceIndex
|
||||
att["attachment_id"] = *a.AttachmentID
|
||||
return att
|
||||
}
|
||||
|
||||
func flattenResourceRecords(recs []*route53.ResourceRecord) []string {
|
||||
strs := make([]string, 0, len(recs))
|
||||
for _, r := range recs {
|
||||
if r.Value != nil {
|
||||
s := strings.Replace(*r.Value, "\"", "", 2)
|
||||
strs = append(strs, s)
|
||||
}
|
||||
}
|
||||
return strs
|
||||
}
|
||||
|
||||
func expandResourceRecords(recs []interface{}, typeStr string) []*route53.ResourceRecord {
|
||||
records := make([]*route53.ResourceRecord, 0, len(recs))
|
||||
for _, r := range recs {
|
||||
s := r.(string)
|
||||
switch typeStr {
|
||||
case "TXT":
|
||||
str := fmt.Sprintf("\"%s\"", s)
|
||||
records = append(records, &route53.ResourceRecord{Value: aws.String(str)})
|
||||
default:
|
||||
records = append(records, &route53.ResourceRecord{Value: aws.String(s)})
|
||||
}
|
||||
}
|
||||
return records
|
||||
}
|
|
@ -1,466 +0,0 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||
"github.com/hashicorp/terraform/flatmap"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
// Returns test configuration
|
||||
func testConfSDK() map[string]string {
|
||||
return map[string]string{
|
||||
"listener.#": "1",
|
||||
"listener.0.lb_port": "80",
|
||||
"listener.0.lb_protocol": "http",
|
||||
"listener.0.instance_port": "8000",
|
||||
"listener.0.instance_protocol": "http",
|
||||
"availability_zones.#": "2",
|
||||
"availability_zones.0": "us-east-1a",
|
||||
"availability_zones.1": "us-east-1b",
|
||||
"ingress.#": "1",
|
||||
"ingress.0.protocol": "icmp",
|
||||
"ingress.0.from_port": "1",
|
||||
"ingress.0.to_port": "-1",
|
||||
"ingress.0.cidr_blocks.#": "1",
|
||||
"ingress.0.cidr_blocks.0": "0.0.0.0/0",
|
||||
"ingress.0.security_groups.#": "2",
|
||||
"ingress.0.security_groups.0": "sg-11111",
|
||||
"ingress.0.security_groups.1": "foo/sg-22222",
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandIPPermsSDK(t *testing.T) {
|
||||
hash := func(v interface{}) int {
|
||||
return hashcode.String(v.(string))
|
||||
}
|
||||
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"protocol": "icmp",
|
||||
"from_port": 1,
|
||||
"to_port": -1,
|
||||
"cidr_blocks": []interface{}{"0.0.0.0/0"},
|
||||
"security_groups": schema.NewSet(hash, []interface{}{
|
||||
"sg-11111",
|
||||
"foo/sg-22222",
|
||||
}),
|
||||
},
|
||||
map[string]interface{}{
|
||||
"protocol": "icmp",
|
||||
"from_port": 1,
|
||||
"to_port": -1,
|
||||
"self": true,
|
||||
},
|
||||
}
|
||||
group := &ec2.SecurityGroup{
|
||||
GroupID: aws.String("foo"),
|
||||
VPCID: aws.String("bar"),
|
||||
}
|
||||
perms := expandIPPermsSDK(group, expanded)
|
||||
|
||||
expected := []ec2.IPPermission{
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}},
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
UserID: aws.String("foo"),
|
||||
GroupID: aws.String("sg-22222"),
|
||||
},
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupID: aws.String("sg-22222"),
|
||||
},
|
||||
},
|
||||
},
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
UserID: aws.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
exp := expected[0]
|
||||
perm := perms[0]
|
||||
|
||||
if *exp.FromPort != *perm.FromPort {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
*perm.FromPort,
|
||||
*exp.FromPort)
|
||||
}
|
||||
|
||||
if *exp.IPRanges[0].CIDRIP != *perm.IPRanges[0].CIDRIP {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
*perm.IPRanges[0].CIDRIP,
|
||||
*exp.IPRanges[0].CIDRIP)
|
||||
}
|
||||
|
||||
if *exp.UserIDGroupPairs[0].UserID != *perm.UserIDGroupPairs[0].UserID {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
*perm.UserIDGroupPairs[0].UserID,
|
||||
*exp.UserIDGroupPairs[0].UserID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExpandIPPerms_nonVPCSDK(t *testing.T) {
|
||||
hash := func(v interface{}) int {
|
||||
return hashcode.String(v.(string))
|
||||
}
|
||||
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"protocol": "icmp",
|
||||
"from_port": 1,
|
||||
"to_port": -1,
|
||||
"cidr_blocks": []interface{}{"0.0.0.0/0"},
|
||||
"security_groups": schema.NewSet(hash, []interface{}{
|
||||
"sg-11111",
|
||||
"foo/sg-22222",
|
||||
}),
|
||||
},
|
||||
map[string]interface{}{
|
||||
"protocol": "icmp",
|
||||
"from_port": 1,
|
||||
"to_port": -1,
|
||||
"self": true,
|
||||
},
|
||||
}
|
||||
group := &ec2.SecurityGroup{
|
||||
GroupName: aws.String("foo"),
|
||||
}
|
||||
perms := expandIPPermsSDK(group, expanded)
|
||||
|
||||
expected := []ec2.IPPermission{
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}},
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupName: aws.String("sg-22222"),
|
||||
},
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupName: aws.String("sg-22222"),
|
||||
},
|
||||
},
|
||||
},
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupName: aws.String("foo"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
exp := expected[0]
|
||||
perm := perms[0]
|
||||
|
||||
if *exp.FromPort != *perm.FromPort {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
*perm.FromPort,
|
||||
*exp.FromPort)
|
||||
}
|
||||
|
||||
if *exp.IPRanges[0].CIDRIP != *perm.IPRanges[0].CIDRIP {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
*perm.IPRanges[0].CIDRIP,
|
||||
*exp.IPRanges[0].CIDRIP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandListenersSDK(t *testing.T) {
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"instance_port": 8000,
|
||||
"lb_port": 80,
|
||||
"instance_protocol": "http",
|
||||
"lb_protocol": "http",
|
||||
},
|
||||
}
|
||||
listeners, err := expandListenersSDK(expanded)
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
|
||||
expected := &elb.Listener{
|
||||
InstancePort: aws.Long(int64(8000)),
|
||||
LoadBalancerPort: aws.Long(int64(80)),
|
||||
InstanceProtocol: aws.String("http"),
|
||||
Protocol: aws.String("http"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(listeners[0], expected) {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
listeners[0],
|
||||
expected)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFlattenHealthCheckSDK(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input *elb.HealthCheck
|
||||
Output []map[string]interface{}
|
||||
}{
|
||||
{
|
||||
Input: &elb.HealthCheck{
|
||||
UnhealthyThreshold: aws.Long(int64(10)),
|
||||
HealthyThreshold: aws.Long(int64(10)),
|
||||
Target: aws.String("HTTP:80/"),
|
||||
Timeout: aws.Long(int64(30)),
|
||||
Interval: aws.Long(int64(30)),
|
||||
},
|
||||
Output: []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"unhealthy_threshold": int64(10),
|
||||
"healthy_threshold": int64(10),
|
||||
"target": "HTTP:80/",
|
||||
"timeout": int64(30),
|
||||
"interval": int64(30),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
output := flattenHealthCheckSDK(tc.Input)
|
||||
if !reflect.DeepEqual(output, tc.Output) {
|
||||
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandStringListSDK(t *testing.T) {
|
||||
expanded := flatmap.Expand(testConfSDK(), "availability_zones").([]interface{})
|
||||
stringList := expandStringList(expanded)
|
||||
expected := []string{
|
||||
"us-east-1a",
|
||||
"us-east-1b",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(stringList, expected) {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
stringList,
|
||||
expected)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExpandParametersSDK(t *testing.T) {
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "character_set_client",
|
||||
"value": "utf8",
|
||||
"apply_method": "immediate",
|
||||
},
|
||||
}
|
||||
parameters, err := expandParametersSDK(expanded)
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
|
||||
expected := &rds.Parameter{
|
||||
ParameterName: aws.String("character_set_client"),
|
||||
ParameterValue: aws.String("utf8"),
|
||||
ApplyMethod: aws.String("immediate"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(parameters[0], expected) {
|
||||
t.Fatalf(
|
||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||
parameters[0],
|
||||
expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenParametersSDK(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input []*rds.Parameter
|
||||
Output []map[string]interface{}
|
||||
}{
|
||||
{
|
||||
Input: []*rds.Parameter{
|
||||
&rds.Parameter{
|
||||
ParameterName: aws.String("character_set_client"),
|
||||
ParameterValue: aws.String("utf8"),
|
||||
},
|
||||
},
|
||||
Output: []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "character_set_client",
|
||||
"value": "utf8",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
output := flattenParametersSDK(tc.Input)
|
||||
if !reflect.DeepEqual(output, tc.Output) {
|
||||
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandInstanceStringSDK(t *testing.T) {
|
||||
|
||||
expected := []*elb.Instance{
|
||||
&elb.Instance{InstanceID: aws.String("test-one")},
|
||||
&elb.Instance{InstanceID: aws.String("test-two")},
|
||||
}
|
||||
|
||||
ids := []interface{}{
|
||||
"test-one",
|
||||
"test-two",
|
||||
}
|
||||
|
||||
expanded := expandInstanceStringSDK(ids)
|
||||
|
||||
if !reflect.DeepEqual(expanded, expected) {
|
||||
t.Fatalf("Expand Instance String output did not match.\nGot:\n%#v\n\nexpected:\n%#v", expanded, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenNetworkInterfacesPrivateIPAddessesSDK(t *testing.T) {
|
||||
expanded := []*ec2.NetworkInterfacePrivateIPAddress{
|
||||
&ec2.NetworkInterfacePrivateIPAddress{PrivateIPAddress: aws.String("192.168.0.1")},
|
||||
&ec2.NetworkInterfacePrivateIPAddress{PrivateIPAddress: aws.String("192.168.0.2")},
|
||||
}
|
||||
|
||||
result := flattenNetworkInterfacesPrivateIPAddessesSDK(expanded)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("result was nil")
|
||||
}
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
||||
}
|
||||
|
||||
if result[0] != "192.168.0.1" {
|
||||
t.Fatalf("expected ip to be 192.168.0.1, but was %s", result[0])
|
||||
}
|
||||
|
||||
if result[1] != "192.168.0.2" {
|
||||
t.Fatalf("expected ip to be 192.168.0.2, but was %s", result[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenGroupIdentifiersSDK(t *testing.T) {
|
||||
expanded := []*ec2.GroupIdentifier{
|
||||
&ec2.GroupIdentifier{GroupID: aws.String("sg-001")},
|
||||
&ec2.GroupIdentifier{GroupID: aws.String("sg-002")},
|
||||
}
|
||||
|
||||
result := flattenGroupIdentifiersSDK(expanded)
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
||||
}
|
||||
|
||||
if result[0] != "sg-001" {
|
||||
t.Fatalf("expected id to be sg-001, but was %s", result[0])
|
||||
}
|
||||
|
||||
if result[1] != "sg-002" {
|
||||
t.Fatalf("expected id to be sg-002, but was %s", result[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandPrivateIPAddessesSDK(t *testing.T) {
|
||||
|
||||
ip1 := "192.168.0.1"
|
||||
ip2 := "192.168.0.2"
|
||||
flattened := []interface{}{
|
||||
ip1,
|
||||
ip2,
|
||||
}
|
||||
|
||||
result := expandPrivateIPAddessesSDK(flattened)
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("expected result had %d elements, but got %d", 2, len(result))
|
||||
}
|
||||
|
||||
if *result[0].PrivateIPAddress != "192.168.0.1" || !*result[0].Primary {
|
||||
t.Fatalf("expected ip to be 192.168.0.1 and Primary, but got %v, %t", *result[0].PrivateIPAddress, *result[0].Primary)
|
||||
}
|
||||
|
||||
if *result[1].PrivateIPAddress != "192.168.0.2" || *result[1].Primary {
|
||||
t.Fatalf("expected ip to be 192.168.0.2 and not Primary, but got %v, %t", *result[1].PrivateIPAddress, *result[1].Primary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenAttachmentSDK(t *testing.T) {
|
||||
expanded := &ec2.NetworkInterfaceAttachment{
|
||||
InstanceID: aws.String("i-00001"),
|
||||
DeviceIndex: aws.Long(int64(1)),
|
||||
AttachmentID: aws.String("at-002"),
|
||||
}
|
||||
|
||||
result := flattenAttachmentSDK(expanded)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("expected result to have value, but got nil")
|
||||
}
|
||||
|
||||
if result["instance"] != "i-00001" {
|
||||
t.Fatalf("expected instance to be i-00001, but got %s", result["instance"])
|
||||
}
|
||||
|
||||
if result["device_index"] != int64(1) {
|
||||
t.Fatalf("expected device_index to be 1, but got %d", result["device_index"])
|
||||
}
|
||||
|
||||
if result["attachment_id"] != "at-002" {
|
||||
t.Fatalf("expected attachment_id to be at-002, but got %s", result["attachment_id"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenResourceRecords(t *testing.T) {
|
||||
expanded := []*route53.ResourceRecord{
|
||||
&route53.ResourceRecord{
|
||||
Value: aws.String("127.0.0.1"),
|
||||
},
|
||||
&route53.ResourceRecord{
|
||||
Value: aws.String("127.0.0.3"),
|
||||
},
|
||||
}
|
||||
|
||||
result := flattenResourceRecords(expanded)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("expected result to have value, but got nil")
|
||||
}
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatal("expected result to have value, but got nil")
|
||||
}
|
||||
}
|
|
@ -4,10 +4,11 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
ec2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||
"github.com/hashicorp/terraform/flatmap"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
@ -36,7 +37,7 @@ func testConf() map[string]string {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExpandIPPerms(t *testing.T) {
|
||||
func TestexpandIPPerms(t *testing.T) {
|
||||
hash := func(v interface{}) int {
|
||||
return hashcode.String(v.(string))
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ func TestExpandIPPerms(t *testing.T) {
|
|||
"self": true,
|
||||
},
|
||||
}
|
||||
group := ec2.SecurityGroup{
|
||||
group := &ec2.SecurityGroup{
|
||||
GroupID: aws.String("foo"),
|
||||
VPCID: aws.String("bar"),
|
||||
}
|
||||
|
@ -68,25 +69,25 @@ func TestExpandIPPerms(t *testing.T) {
|
|||
expected := []ec2.IPPermission{
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Integer(1),
|
||||
ToPort: aws.Integer(-1),
|
||||
IPRanges: []ec2.IPRange{ec2.IPRange{aws.String("0.0.0.0/0")}},
|
||||
UserIDGroupPairs: []ec2.UserIDGroupPair{
|
||||
ec2.UserIDGroupPair{
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}},
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
UserID: aws.String("foo"),
|
||||
GroupID: aws.String("sg-22222"),
|
||||
},
|
||||
ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupID: aws.String("sg-22222"),
|
||||
},
|
||||
},
|
||||
},
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Integer(1),
|
||||
ToPort: aws.Integer(-1),
|
||||
UserIDGroupPairs: []ec2.UserIDGroupPair{
|
||||
ec2.UserIDGroupPair{
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
UserID: aws.String("foo"),
|
||||
},
|
||||
},
|
||||
|
@ -142,7 +143,7 @@ func TestExpandIPPerms_nonVPC(t *testing.T) {
|
|||
"self": true,
|
||||
},
|
||||
}
|
||||
group := ec2.SecurityGroup{
|
||||
group := &ec2.SecurityGroup{
|
||||
GroupName: aws.String("foo"),
|
||||
}
|
||||
perms := expandIPPerms(group, expanded)
|
||||
|
@ -150,24 +151,24 @@ func TestExpandIPPerms_nonVPC(t *testing.T) {
|
|||
expected := []ec2.IPPermission{
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Integer(1),
|
||||
ToPort: aws.Integer(-1),
|
||||
IPRanges: []ec2.IPRange{ec2.IPRange{aws.String("0.0.0.0/0")}},
|
||||
UserIDGroupPairs: []ec2.UserIDGroupPair{
|
||||
ec2.UserIDGroupPair{
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
IPRanges: []*ec2.IPRange{&ec2.IPRange{CIDRIP: aws.String("0.0.0.0/0")}},
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupName: aws.String("sg-22222"),
|
||||
},
|
||||
ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupName: aws.String("sg-22222"),
|
||||
},
|
||||
},
|
||||
},
|
||||
ec2.IPPermission{
|
||||
IPProtocol: aws.String("icmp"),
|
||||
FromPort: aws.Integer(1),
|
||||
ToPort: aws.Integer(-1),
|
||||
UserIDGroupPairs: []ec2.UserIDGroupPair{
|
||||
ec2.UserIDGroupPair{
|
||||
FromPort: aws.Long(int64(1)),
|
||||
ToPort: aws.Long(int64(-1)),
|
||||
UserIDGroupPairs: []*ec2.UserIDGroupPair{
|
||||
&ec2.UserIDGroupPair{
|
||||
GroupName: aws.String("foo"),
|
||||
},
|
||||
},
|
||||
|
@ -192,7 +193,7 @@ func TestExpandIPPerms_nonVPC(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExpandListeners(t *testing.T) {
|
||||
func TestexpandListeners(t *testing.T) {
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"instance_port": 8000,
|
||||
|
@ -206,9 +207,9 @@ func TestExpandListeners(t *testing.T) {
|
|||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
|
||||
expected := elb.Listener{
|
||||
InstancePort: aws.Integer(8000),
|
||||
LoadBalancerPort: aws.Integer(80),
|
||||
expected := &elb.Listener{
|
||||
InstancePort: aws.Long(int64(8000)),
|
||||
LoadBalancerPort: aws.Long(int64(80)),
|
||||
InstanceProtocol: aws.String("http"),
|
||||
Protocol: aws.String("http"),
|
||||
}
|
||||
|
@ -222,33 +223,33 @@ func TestExpandListeners(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestFlattenHealthCheck(t *testing.T) {
|
||||
func TestflattenHealthCheck(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input elb.HealthCheck
|
||||
Input *elb.HealthCheck
|
||||
Output []map[string]interface{}
|
||||
}{
|
||||
{
|
||||
Input: elb.HealthCheck{
|
||||
UnhealthyThreshold: aws.Integer(10),
|
||||
HealthyThreshold: aws.Integer(10),
|
||||
Input: &elb.HealthCheck{
|
||||
UnhealthyThreshold: aws.Long(int64(10)),
|
||||
HealthyThreshold: aws.Long(int64(10)),
|
||||
Target: aws.String("HTTP:80/"),
|
||||
Timeout: aws.Integer(30),
|
||||
Interval: aws.Integer(30),
|
||||
Timeout: aws.Long(int64(30)),
|
||||
Interval: aws.Long(int64(30)),
|
||||
},
|
||||
Output: []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"unhealthy_threshold": 10,
|
||||
"healthy_threshold": 10,
|
||||
"unhealthy_threshold": int64(10),
|
||||
"healthy_threshold": int64(10),
|
||||
"target": "HTTP:80/",
|
||||
"timeout": 30,
|
||||
"interval": 30,
|
||||
"timeout": int64(30),
|
||||
"interval": int64(30),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
output := flattenHealthCheck(&tc.Input)
|
||||
output := flattenHealthCheck(tc.Input)
|
||||
if !reflect.DeepEqual(output, tc.Output) {
|
||||
t.Fatalf("Got:\n\n%#v\n\nExpected:\n\n%#v", output, tc.Output)
|
||||
}
|
||||
|
@ -258,9 +259,9 @@ func TestFlattenHealthCheck(t *testing.T) {
|
|||
func TestExpandStringList(t *testing.T) {
|
||||
expanded := flatmap.Expand(testConf(), "availability_zones").([]interface{})
|
||||
stringList := expandStringList(expanded)
|
||||
expected := []string{
|
||||
"us-east-1a",
|
||||
"us-east-1b",
|
||||
expected := []*string{
|
||||
aws.String("us-east-1a"),
|
||||
aws.String("us-east-1b"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(stringList, expected) {
|
||||
|
@ -272,7 +273,7 @@ func TestExpandStringList(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestExpandParameters(t *testing.T) {
|
||||
func TestexpandParameters(t *testing.T) {
|
||||
expanded := []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "character_set_client",
|
||||
|
@ -285,7 +286,7 @@ func TestExpandParameters(t *testing.T) {
|
|||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
|
||||
expected := rds.Parameter{
|
||||
expected := &rds.Parameter{
|
||||
ParameterName: aws.String("character_set_client"),
|
||||
ParameterValue: aws.String("utf8"),
|
||||
ApplyMethod: aws.String("immediate"),
|
||||
|
@ -299,14 +300,14 @@ func TestExpandParameters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFlattenParameters(t *testing.T) {
|
||||
func TestflattenParameters(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input []rds.Parameter
|
||||
Input []*rds.Parameter
|
||||
Output []map[string]interface{}
|
||||
}{
|
||||
{
|
||||
Input: []rds.Parameter{
|
||||
rds.Parameter{
|
||||
Input: []*rds.Parameter{
|
||||
&rds.Parameter{
|
||||
ParameterName: aws.String("character_set_client"),
|
||||
ParameterValue: aws.String("utf8"),
|
||||
},
|
||||
|
@ -328,11 +329,11 @@ func TestFlattenParameters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExpandInstanceString(t *testing.T) {
|
||||
func TestexpandInstanceString(t *testing.T) {
|
||||
|
||||
expected := []elb.Instance{
|
||||
elb.Instance{aws.String("test-one")},
|
||||
elb.Instance{aws.String("test-two")},
|
||||
expected := []*elb.Instance{
|
||||
&elb.Instance{InstanceID: aws.String("test-one")},
|
||||
&elb.Instance{InstanceID: aws.String("test-two")},
|
||||
}
|
||||
|
||||
ids := []interface{}{
|
||||
|
@ -347,10 +348,10 @@ func TestExpandInstanceString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFlattenNetworkInterfacesPrivateIPAddesses(t *testing.T) {
|
||||
expanded := []ec2.NetworkInterfacePrivateIPAddress{
|
||||
ec2.NetworkInterfacePrivateIPAddress{PrivateIPAddress: aws.String("192.168.0.1")},
|
||||
ec2.NetworkInterfacePrivateIPAddress{PrivateIPAddress: aws.String("192.168.0.2")},
|
||||
func TestflattenNetworkInterfacesPrivateIPAddesses(t *testing.T) {
|
||||
expanded := []*ec2.NetworkInterfacePrivateIPAddress{
|
||||
&ec2.NetworkInterfacePrivateIPAddress{PrivateIPAddress: aws.String("192.168.0.1")},
|
||||
&ec2.NetworkInterfacePrivateIPAddress{PrivateIPAddress: aws.String("192.168.0.2")},
|
||||
}
|
||||
|
||||
result := flattenNetworkInterfacesPrivateIPAddesses(expanded)
|
||||
|
@ -372,10 +373,10 @@ func TestFlattenNetworkInterfacesPrivateIPAddesses(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFlattenGroupIdentifiers(t *testing.T) {
|
||||
expanded := []ec2.GroupIdentifier{
|
||||
ec2.GroupIdentifier{GroupID: aws.String("sg-001")},
|
||||
ec2.GroupIdentifier{GroupID: aws.String("sg-002")},
|
||||
func TestflattenGroupIdentifiers(t *testing.T) {
|
||||
expanded := []*ec2.GroupIdentifier{
|
||||
&ec2.GroupIdentifier{GroupID: aws.String("sg-001")},
|
||||
&ec2.GroupIdentifier{GroupID: aws.String("sg-002")},
|
||||
}
|
||||
|
||||
result := flattenGroupIdentifiers(expanded)
|
||||
|
@ -393,7 +394,7 @@ func TestFlattenGroupIdentifiers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestExpandPrivateIPAddesses(t *testing.T) {
|
||||
func TestexpandPrivateIPAddesses(t *testing.T) {
|
||||
|
||||
ip1 := "192.168.0.1"
|
||||
ip2 := "192.168.0.2"
|
||||
|
@ -417,10 +418,10 @@ func TestExpandPrivateIPAddesses(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFlattenAttachment(t *testing.T) {
|
||||
func TestflattenAttachment(t *testing.T) {
|
||||
expanded := &ec2.NetworkInterfaceAttachment{
|
||||
InstanceID: aws.String("i-00001"),
|
||||
DeviceIndex: aws.Integer(1),
|
||||
DeviceIndex: aws.Long(int64(1)),
|
||||
AttachmentID: aws.String("at-002"),
|
||||
}
|
||||
|
||||
|
@ -434,7 +435,7 @@ func TestFlattenAttachment(t *testing.T) {
|
|||
t.Fatalf("expected instance to be i-00001, but got %s", result["instance"])
|
||||
}
|
||||
|
||||
if result["device_index"] != 1 {
|
||||
if result["device_index"] != int64(1) {
|
||||
t.Fatalf("expected device_index to be 1, but got %d", result["device_index"])
|
||||
}
|
||||
|
||||
|
@ -442,3 +443,24 @@ func TestFlattenAttachment(t *testing.T) {
|
|||
t.Fatalf("expected attachment_id to be at-002, but got %s", result["attachment_id"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenResourceRecords(t *testing.T) {
|
||||
expanded := []*route53.ResourceRecord{
|
||||
&route53.ResourceRecord{
|
||||
Value: aws.String("127.0.0.1"),
|
||||
},
|
||||
&route53.ResourceRecord{
|
||||
Value: aws.String("127.0.0.3"),
|
||||
},
|
||||
}
|
||||
|
||||
result := flattenResourceRecords(expanded)
|
||||
|
||||
if result == nil {
|
||||
t.Fatal("expected result to have value, but got nil")
|
||||
}
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatal("expected result to have value, but got nil")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package aws
|
|||
import (
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
|
@ -19,18 +19,18 @@ func tagsSchema() *schema.Schema {
|
|||
|
||||
// setTags is a helper to set the tags for a resource. It expects the
|
||||
// tags field to be named "tags"
|
||||
func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||
func setTagsSDK(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||
if d.HasChange("tags") {
|
||||
oraw, nraw := d.GetChange("tags")
|
||||
o := oraw.(map[string]interface{})
|
||||
n := nraw.(map[string]interface{})
|
||||
create, remove := diffTags(tagsFromMap(o), tagsFromMap(n))
|
||||
create, remove := diffTagsSDK(tagsFromMapSDK(o), tagsFromMapSDK(n))
|
||||
|
||||
// Set tags
|
||||
if len(remove) > 0 {
|
||||
log.Printf("[DEBUG] Removing tags: %#v", remove)
|
||||
err := conn.DeleteTags(&ec2.DeleteTagsRequest{
|
||||
Resources: []string{d.Id()},
|
||||
_, err := conn.DeleteTags(&ec2.DeleteTagsInput{
|
||||
Resources: []*string{aws.String(d.Id())},
|
||||
Tags: remove,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -39,8 +39,8 @@ func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
|
|||
}
|
||||
if len(create) > 0 {
|
||||
log.Printf("[DEBUG] Creating tags: %#v", create)
|
||||
err := conn.CreateTags(&ec2.CreateTagsRequest{
|
||||
Resources: []string{d.Id()},
|
||||
_, err := conn.CreateTags(&ec2.CreateTagsInput{
|
||||
Resources: []*string{aws.String(d.Id())},
|
||||
Tags: create,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -55,7 +55,7 @@ func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
|
|||
// diffTags takes our tags locally and the ones remotely and returns
|
||||
// the set of tags that must be created, and the set of tags that must
|
||||
// be destroyed.
|
||||
func diffTags(oldTags, newTags []ec2.Tag) ([]ec2.Tag, []ec2.Tag) {
|
||||
func diffTagsSDK(oldTags, newTags []*ec2.Tag) ([]*ec2.Tag, []*ec2.Tag) {
|
||||
// First, we're creating everything we have
|
||||
create := make(map[string]interface{})
|
||||
for _, t := range newTags {
|
||||
|
@ -63,7 +63,7 @@ func diffTags(oldTags, newTags []ec2.Tag) ([]ec2.Tag, []ec2.Tag) {
|
|||
}
|
||||
|
||||
// Build the list of what to remove
|
||||
var remove []ec2.Tag
|
||||
var remove []*ec2.Tag
|
||||
for _, t := range oldTags {
|
||||
old, ok := create[*t.Key]
|
||||
if !ok || old != *t.Value {
|
||||
|
@ -72,14 +72,14 @@ func diffTags(oldTags, newTags []ec2.Tag) ([]ec2.Tag, []ec2.Tag) {
|
|||
}
|
||||
}
|
||||
|
||||
return tagsFromMap(create), remove
|
||||
return tagsFromMapSDK(create), remove
|
||||
}
|
||||
|
||||
// tagsFromMap returns the tags for the given map of data.
|
||||
func tagsFromMap(m map[string]interface{}) []ec2.Tag {
|
||||
result := make([]ec2.Tag, 0, len(m))
|
||||
func tagsFromMapSDK(m map[string]interface{}) []*ec2.Tag {
|
||||
result := make([]*ec2.Tag, 0, len(m))
|
||||
for k, v := range m {
|
||||
result = append(result, ec2.Tag{
|
||||
result = append(result, &ec2.Tag{
|
||||
Key: aws.String(k),
|
||||
Value: aws.String(v.(string)),
|
||||
})
|
||||
|
@ -89,7 +89,7 @@ func tagsFromMap(m map[string]interface{}) []ec2.Tag {
|
|||
}
|
||||
|
||||
// tagsToMap turns the list of tags into a map.
|
||||
func tagsToMap(ts []ec2.Tag) map[string]string {
|
||||
func tagsToMapSDK(ts []*ec2.Tag) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, t := range ts {
|
||||
result[*t.Key] = *t.Value
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/awslabs/aws-sdk-go/aws"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
// tagsSchema returns the schema to use for tags.
|
||||
//
|
||||
// func tagsSchema() *schema.Schema {
|
||||
// return &schema.Schema{
|
||||
// Type: schema.TypeMap,
|
||||
// Optional: true,
|
||||
// }
|
||||
// }
|
||||
|
||||
// setTags is a helper to set the tags for a resource. It expects the
|
||||
// tags field to be named "tags"
|
||||
func setTagsSDK(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||
if d.HasChange("tags") {
|
||||
oraw, nraw := d.GetChange("tags")
|
||||
o := oraw.(map[string]interface{})
|
||||
n := nraw.(map[string]interface{})
|
||||
create, remove := diffTagsSDK(tagsFromMapSDK(o), tagsFromMapSDK(n))
|
||||
|
||||
// Set tags
|
||||
if len(remove) > 0 {
|
||||
log.Printf("[DEBUG] Removing tags: %#v", remove)
|
||||
_, err := conn.DeleteTags(&ec2.DeleteTagsInput{
|
||||
Resources: []*string{aws.String(d.Id())},
|
||||
Tags: remove,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(create) > 0 {
|
||||
log.Printf("[DEBUG] Creating tags: %#v", create)
|
||||
_, err := conn.CreateTags(&ec2.CreateTagsInput{
|
||||
Resources: []*string{aws.String(d.Id())},
|
||||
Tags: create,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// diffTags takes our tags locally and the ones remotely and returns
|
||||
// the set of tags that must be created, and the set of tags that must
|
||||
// be destroyed.
|
||||
func diffTagsSDK(oldTags, newTags []*ec2.Tag) ([]*ec2.Tag, []*ec2.Tag) {
|
||||
// First, we're creating everything we have
|
||||
create := make(map[string]interface{})
|
||||
for _, t := range newTags {
|
||||
create[*t.Key] = *t.Value
|
||||
}
|
||||
|
||||
// Build the list of what to remove
|
||||
var remove []*ec2.Tag
|
||||
for _, t := range oldTags {
|
||||
old, ok := create[*t.Key]
|
||||
if !ok || old != *t.Value {
|
||||
// Delete it!
|
||||
remove = append(remove, t)
|
||||
}
|
||||
}
|
||||
|
||||
return tagsFromMapSDK(create), remove
|
||||
}
|
||||
|
||||
// tagsFromMap returns the tags for the given map of data.
|
||||
func tagsFromMapSDK(m map[string]interface{}) []*ec2.Tag {
|
||||
result := make([]*ec2.Tag, 0, len(m))
|
||||
for k, v := range m {
|
||||
result = append(result, &ec2.Tag{
|
||||
Key: aws.String(k),
|
||||
Value: aws.String(v.(string)),
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// tagsToMap turns the list of tags into a map.
|
||||
func tagsToMapSDK(ts []*ec2.Tag) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, t := range ts {
|
||||
result[*t.Key] = *t.Value
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestDiffTagsSDK(t *testing.T) {
|
||||
cases := []struct {
|
||||
Old, New map[string]interface{}
|
||||
Create, Remove map[string]string
|
||||
}{
|
||||
// Basic add/remove
|
||||
{
|
||||
Old: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
New: map[string]interface{}{
|
||||
"bar": "baz",
|
||||
},
|
||||
Create: map[string]string{
|
||||
"bar": "baz",
|
||||
},
|
||||
Remove: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
|
||||
// Modify
|
||||
{
|
||||
Old: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
New: map[string]interface{}{
|
||||
"foo": "baz",
|
||||
},
|
||||
Create: map[string]string{
|
||||
"foo": "baz",
|
||||
},
|
||||
Remove: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
c, r := diffTagsSDK(tagsFromMapSDK(tc.Old), tagsFromMapSDK(tc.New))
|
||||
cm := tagsToMapSDK(c)
|
||||
rm := tagsToMapSDK(r)
|
||||
if !reflect.DeepEqual(cm, tc.Create) {
|
||||
t.Fatalf("%d: bad create: %#v", i, cm)
|
||||
}
|
||||
if !reflect.DeepEqual(rm, tc.Remove) {
|
||||
t.Fatalf("%d: bad remove: %#v", i, rm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// testAccCheckTags can be used to check the tags on a resource.
|
||||
func testAccCheckTagsSDK(
|
||||
ts *[]*ec2.Tag, key string, value string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
m := tagsToMapSDK(*ts)
|
||||
v, ok := m[key]
|
||||
if value != "" && !ok {
|
||||
return fmt.Errorf("Missing tag: %s", key)
|
||||
} else if value == "" && ok {
|
||||
return fmt.Errorf("Extra tag: %s", key)
|
||||
}
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if v != value {
|
||||
return fmt.Errorf("%s: bad value: %s", key, v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
|
@ -5,12 +5,12 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestDiffTags(t *testing.T) {
|
||||
func TestDiffTagsSDK(t *testing.T) {
|
||||
cases := []struct {
|
||||
Old, New map[string]interface{}
|
||||
Create, Remove map[string]string
|
||||
|
@ -49,9 +49,9 @@ func TestDiffTags(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
c, r := diffTags(tagsFromMap(tc.Old), tagsFromMap(tc.New))
|
||||
cm := tagsToMap(c)
|
||||
rm := tagsToMap(r)
|
||||
c, r := diffTagsSDK(tagsFromMapSDK(tc.Old), tagsFromMapSDK(tc.New))
|
||||
cm := tagsToMapSDK(c)
|
||||
rm := tagsToMapSDK(r)
|
||||
if !reflect.DeepEqual(cm, tc.Create) {
|
||||
t.Fatalf("%d: bad create: %#v", i, cm)
|
||||
}
|
||||
|
@ -62,10 +62,10 @@ func TestDiffTags(t *testing.T) {
|
|||
}
|
||||
|
||||
// testAccCheckTags can be used to check the tags on a resource.
|
||||
func testAccCheckTags(
|
||||
ts *[]ec2.Tag, key string, value string) resource.TestCheckFunc {
|
||||
func testAccCheckTagsSDK(
|
||||
ts *[]*ec2.Tag, key string, value string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
m := tagsToMap(*ts)
|
||||
m := tagsToMapSDK(*ts)
|
||||
v, ok := m[key]
|
||||
if value != "" && !ok {
|
||||
return fmt.Errorf("Missing tag: %s", key)
|
||||
|
|
Loading…
Reference in New Issue