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