Merge pull request #1195 from hashicorp/f-retire-goamz
provider/aws: Retire goamz
This commit is contained in:
commit
dc4abb48fa
|
@ -3,21 +3,16 @@ package aws
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/multierror"
|
"github.com/hashicorp/terraform/helper/multierror"
|
||||||
"github.com/mitchellh/goamz/aws"
|
|
||||||
"github.com/mitchellh/goamz/ec2"
|
|
||||||
|
|
||||||
awsGo "github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
||||||
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
||||||
|
|
||||||
awsEC2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -29,7 +24,6 @@ type Config struct {
|
||||||
|
|
||||||
type AWSClient struct {
|
type AWSClient struct {
|
||||||
ec2conn *ec2.EC2
|
ec2conn *ec2.EC2
|
||||||
awsEC2conn *awsEC2.EC2
|
|
||||||
elbconn *elb.ELB
|
elbconn *elb.ELB
|
||||||
autoscalingconn *autoscaling.AutoScaling
|
autoscalingconn *autoscaling.AutoScaling
|
||||||
s3conn *s3.S3
|
s3conn *s3.S3
|
||||||
|
@ -45,14 +39,9 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
// Get the auth and region. This can fail if keys/regions were not
|
// Get the auth and region. This can fail if keys/regions were not
|
||||||
// specified and we're attempting to use the environment.
|
// specified and we're attempting to use the environment.
|
||||||
var errs []error
|
var errs []error
|
||||||
log.Println("[INFO] Building AWS auth structure")
|
|
||||||
auth, err := c.AWSAuth()
|
|
||||||
if err != nil {
|
|
||||||
errs = append(errs, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("[INFO] Building AWS region structure")
|
log.Println("[INFO] Building AWS region structure")
|
||||||
region, err := c.AWSRegion()
|
err := c.ValidateRegion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
@ -62,10 +51,9 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
// bucket storage in S3
|
// bucket storage in S3
|
||||||
client.region = c.Region
|
client.region = c.Region
|
||||||
|
|
||||||
creds := awsGo.Creds(c.AccessKey, c.SecretKey, c.Token)
|
log.Println("[INFO] Building AWS auth structure")
|
||||||
|
creds := aws.Creds(c.AccessKey, c.SecretKey, c.Token)
|
||||||
|
|
||||||
log.Println("[INFO] Initializing EC2 connection")
|
|
||||||
client.ec2conn = ec2.New(auth, region)
|
|
||||||
log.Println("[INFO] Initializing ELB connection")
|
log.Println("[INFO] Initializing ELB connection")
|
||||||
client.elbconn = elb.New(creds, c.Region, nil)
|
client.elbconn = elb.New(creds, c.Region, nil)
|
||||||
log.Println("[INFO] Initializing AutoScaling connection")
|
log.Println("[INFO] Initializing AutoScaling connection")
|
||||||
|
@ -80,8 +68,8 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
// 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 Route53 connection")
|
log.Println("[INFO] Initializing Route53 connection")
|
||||||
client.r53conn = route53.New(creds, "us-east-1", nil)
|
client.r53conn = route53.New(creds, "us-east-1", nil)
|
||||||
log.Println("[INFO] Initializing AWS-GO EC2 Connection")
|
log.Println("[INFO] Initializing EC2 Connection")
|
||||||
client.awsEC2conn = awsEC2.New(creds, c.Region, nil)
|
client.ec2conn = ec2.New(creds, c.Region, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
@ -91,54 +79,17 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
return &client, nil
|
return &client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AWSAuth returns a valid aws.Auth object for access to AWS services, or
|
|
||||||
// an error if the authentication couldn't be resolved.
|
|
||||||
//
|
|
||||||
// TODO(mitchellh): Test in some way.
|
|
||||||
func (c *Config) AWSAuth() (aws.Auth, error) {
|
|
||||||
auth, err := aws.GetAuth(c.AccessKey, c.SecretKey)
|
|
||||||
if err == nil {
|
|
||||||
// Store the accesskey and secret that we got...
|
|
||||||
c.AccessKey = auth.AccessKey
|
|
||||||
c.SecretKey = auth.SecretKey
|
|
||||||
c.Token = auth.Token
|
|
||||||
}
|
|
||||||
|
|
||||||
return auth, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsValidRegion returns true if the configured region is a valid AWS
|
// IsValidRegion returns true if the configured region is a valid AWS
|
||||||
// region and false if it's not
|
// region and false if it's not
|
||||||
func (c *Config) IsValidRegion() bool {
|
func (c *Config) ValidateRegion() error {
|
||||||
var regions = [11]string{"us-east-1", "us-west-2", "us-west-1", "eu-west-1",
|
var regions = [11]string{"us-east-1", "us-west-2", "us-west-1", "eu-west-1",
|
||||||
"eu-central-1", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1",
|
"eu-central-1", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1",
|
||||||
"sa-east-1", "cn-north-1", "us-gov-west-1"}
|
"sa-east-1", "cn-north-1", "us-gov-west-1"}
|
||||||
|
|
||||||
for _, valid := range regions {
|
for _, valid := range regions {
|
||||||
if c.Region == valid {
|
if c.Region == valid {
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return fmt.Errorf("Not a valid region: %s", c.Region)
|
||||||
}
|
|
||||||
|
|
||||||
// AWSRegion returns the configured region.
|
|
||||||
//
|
|
||||||
// TODO(mitchellh): Test in some way.
|
|
||||||
func (c *Config) AWSRegion() (aws.Region, error) {
|
|
||||||
if c.Region != "" {
|
|
||||||
if c.IsValidRegion() {
|
|
||||||
return aws.Regions[c.Region], nil
|
|
||||||
} else {
|
|
||||||
return aws.Region{}, fmt.Errorf("Not a valid region: %s", c.Region)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
md, err := aws.GetMetaData("placement/availability-zone")
|
|
||||||
if err != nil {
|
|
||||||
return aws.Region{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
region := strings.TrimRightFunc(string(md), unicode.IsLetter)
|
|
||||||
return aws.Regions[region], nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
os := o.(*schema.Set)
|
os := o.(*schema.Set)
|
||||||
ns := n.(*schema.Set)
|
ns := n.(*schema.Set)
|
||||||
|
|
||||||
// Expand the "parameter" set to goamz compat []rds.Parameter
|
// Expand the "parameter" set to aws-sdk-go compat []rds.Parameter
|
||||||
parameters, err := expandParameters(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).awsEC2conn
|
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).awsEC2conn
|
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).awsEC2conn
|
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).awsEC2conn
|
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).awsEC2conn
|
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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
if strings.Contains(rs.Primary.ID, "eipalloc") {
|
if strings.Contains(rs.Primary.ID, "eipalloc") {
|
||||||
req := &ec2.DescribeAddressesRequest{
|
req := &ec2.DescribeAddressesRequest{
|
||||||
|
|
|
@ -161,7 +161,7 @@ func resourceAwsElb() *schema.Resource {
|
||||||
func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
elbconn := meta.(*AWSClient).elbconn
|
elbconn := meta.(*AWSClient).elbconn
|
||||||
|
|
||||||
// Expand the "listener" set to goamz compat []elb.Listener
|
// Expand the "listener" set to aws-sdk-go compat []elb.Listener
|
||||||
listeners, err := expandListeners(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
|
||||||
|
|
|
@ -254,7 +254,7 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Figure out user data
|
// Figure out user data
|
||||||
userData := ""
|
userData := ""
|
||||||
|
@ -442,7 +442,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
resp, err := ec2conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
resp, err := ec2conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
||||||
InstanceIDs: []string{d.Id()},
|
InstanceIDs: []string{d.Id()},
|
||||||
|
@ -486,7 +486,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("subnet_id", instance.SubnetID)
|
d.Set("subnet_id", instance.SubnetID)
|
||||||
}
|
}
|
||||||
d.Set("ebs_optimized", instance.EBSOptimized)
|
d.Set("ebs_optimized", instance.EBSOptimized)
|
||||||
d.Set("tags", tagsToMapSDK(instance.Tags))
|
d.Set("tags", tagsToMap(instance.Tags))
|
||||||
d.Set("tenancy", instance.Placement.Tenancy)
|
d.Set("tenancy", instance.Placement.Tenancy)
|
||||||
|
|
||||||
// Determine whether we're referring to security groups with
|
// Determine whether we're referring to security groups with
|
||||||
|
@ -566,7 +566,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
opts := new(ec2.ModifyInstanceAttributeRequest)
|
opts := new(ec2.ModifyInstanceAttributeRequest)
|
||||||
|
|
||||||
log.Printf("[INFO] Modifying instance %s: %#v", d.Id(), opts)
|
log.Printf("[INFO] Modifying instance %s: %#v", d.Id(), opts)
|
||||||
|
@ -584,7 +584,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// TODO(mitchellh): wait for the attributes we modified to
|
// TODO(mitchellh): wait for the attributes we modified to
|
||||||
// persist the change...
|
// persist the change...
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -594,7 +594,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf("[INFO] Terminating instance: %s", d.Id())
|
log.Printf("[INFO] Terminating instance: %s", d.Id())
|
||||||
req := &ec2.TerminateInstancesRequest{
|
req := &ec2.TerminateInstancesRequest{
|
||||||
|
|
|
@ -238,9 +238,9 @@ func TestAccAWSInstance_tags(t *testing.T) {
|
||||||
Config: testAccCheckInstanceConfigTags,
|
Config: testAccCheckInstanceConfigTags,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckInstanceExists("aws_instance.foo", &v),
|
testAccCheckInstanceExists("aws_instance.foo", &v),
|
||||||
testAccCheckTagsSDK(&v.Tags, "foo", "bar"),
|
testAccCheckTags(&v.Tags, "foo", "bar"),
|
||||||
// Guard against regression of https://github.com/hashicorp/terraform/issues/914
|
// Guard against regression of https://github.com/hashicorp/terraform/issues/914
|
||||||
testAccCheckTagsSDK(&v.Tags, "#", ""),
|
testAccCheckTags(&v.Tags, "#", ""),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -248,8 +248,8 @@ func TestAccAWSInstance_tags(t *testing.T) {
|
||||||
Config: testAccCheckInstanceConfigTagsUpdate,
|
Config: testAccCheckInstanceConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckInstanceExists("aws_instance.foo", &v),
|
testAccCheckInstanceExists("aws_instance.foo", &v),
|
||||||
testAccCheckTagsSDK(&v.Tags, "foo", ""),
|
testAccCheckTags(&v.Tags, "foo", ""),
|
||||||
testAccCheckTagsSDK(&v.Tags, "bar", "baz"),
|
testAccCheckTags(&v.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -315,7 +315,7 @@ func TestAccAWSInstance_associatePublicIPAndPrivateIP(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckInstanceDestroy(s *terraform.State) error {
|
func testAccCheckInstanceDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
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" {
|
||||||
|
@ -358,7 +358,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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
||||||
InstanceIDs: []string{rs.Primary.ID},
|
InstanceIDs: []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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Create the gateway
|
// Create the gateway
|
||||||
log.Printf("[DEBUG] Creating internet gateway")
|
log.Printf("[DEBUG] Creating internet gateway")
|
||||||
|
@ -43,7 +43,7 @@ func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{})
|
||||||
d.SetId(*ig.InternetGatewayID)
|
d.SetId(*ig.InternetGatewayID)
|
||||||
log.Printf("[INFO] InternetGateway ID: %s", d.Id())
|
log.Printf("[INFO] InternetGateway ID: %s", d.Id())
|
||||||
|
|
||||||
err = setTagsSDK(ec2conn, d)
|
err = setTags(ec2conn, d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
igRaw, _, err := IGStateRefreshFunc(ec2conn, d.Id())()
|
igRaw, _, err := IGStateRefreshFunc(ec2conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,7 +73,7 @@ func resourceAwsInternetGatewayRead(d *schema.ResourceData, meta interface{}) er
|
||||||
d.Set("vpc_id", ig.Attachments[0].VPCID)
|
d.Set("vpc_id", ig.Attachments[0].VPCID)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("tags", tagsToMapSDK(ig.Tags))
|
d.Set("tags", tagsToMap(ig.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,9 @@ func resourceAwsInternetGatewayUpdate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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")
|
||||||
|
|
|
@ -98,7 +98,7 @@ func TestAccInternetGateway_tags(t *testing.T) {
|
||||||
Config: testAccCheckInternetGatewayConfigTags,
|
Config: testAccCheckInternetGatewayConfigTags,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v),
|
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v),
|
||||||
testAccCheckTagsSDK(&v.Tags, "foo", "bar"),
|
testAccCheckTags(&v.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ func TestAccInternetGateway_tags(t *testing.T) {
|
||||||
Config: testAccCheckInternetGatewayConfigTagsUpdate,
|
Config: testAccCheckInternetGatewayConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v),
|
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v),
|
||||||
testAccCheckTagsSDK(&v.Tags, "foo", ""),
|
testAccCheckTags(&v.Tags, "foo", ""),
|
||||||
testAccCheckTagsSDK(&v.Tags, "bar", "baz"),
|
testAccCheckTags(&v.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -115,7 +115,7 @@ func TestAccInternetGateway_tags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
||||||
ec2conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
ec2conn := 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
ec2conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := ec2conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysRequest{
|
resp, err := ec2conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysRequest{
|
||||||
InternetGatewayIDs: []string{rs.Primary.ID},
|
InternetGatewayIDs: []string{rs.Primary.ID},
|
||||||
})
|
})
|
||||||
|
|
|
@ -37,7 +37,7 @@ func resourceAwsKeyPair() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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)
|
||||||
|
@ -55,7 +55,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
req := &ec2.DescribeKeyPairsRequest{
|
req := &ec2.DescribeKeyPairsRequest{
|
||||||
KeyNames: []string{d.Id()},
|
KeyNames: []string{d.Id()},
|
||||||
|
@ -77,7 +77,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
err := ec2conn.DeleteKeyPair(&ec2.DeleteKeyPairRequest{
|
err := ec2conn.DeleteKeyPair(&ec2.DeleteKeyPairRequest{
|
||||||
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 {
|
||||||
ec2conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
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" {
|
||||||
|
@ -81,7 +81,7 @@ 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
ec2conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
resp, err := ec2conn.DescribeKeyPairs(&ec2.DescribeKeyPairsRequest{
|
resp, err := ec2conn.DescribeKeyPairs(&ec2.DescribeKeyPairsRequest{
|
||||||
KeyNames: []string{rs.Primary.ID},
|
KeyNames: []string{rs.Primary.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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
mainAssociation, err := findMainRouteTableAssociation(
|
mainAssociation, err := findMainRouteTableAssociation(
|
||||||
ec2conn,
|
ec2conn,
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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).awsEC2conn
|
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 {
|
||||||
|
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Create the Network Acl
|
// Create the Network Acl
|
||||||
createOpts := &ec2.CreateNetworkACLRequest{
|
createOpts := &ec2.CreateNetworkACLRequest{
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
resp, err := ec2conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
resp, err := ec2conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||||
NetworkACLIDs: []string{d.Id()},
|
NetworkACLIDs: []string{d.Id()},
|
||||||
|
@ -161,13 +161,13 @@ func resourceAwsNetworkAclRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("vpc_id", networkAcl.VPCID)
|
d.Set("vpc_id", networkAcl.VPCID)
|
||||||
d.Set("ingress", ingressEntries)
|
d.Set("ingress", ingressEntries)
|
||||||
d.Set("egress", egressEntries)
|
d.Set("egress", egressEntries)
|
||||||
d.Set("tags", tagsToMapSDK(networkAcl.Tags))
|
d.Set("tags", tagsToMap(networkAcl.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
|
|
||||||
if d.HasChange("ingress") {
|
if d.HasChange("ingress") {
|
||||||
|
@ -202,7 +202,7 @@ func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -265,7 +265,7 @@ func updateNetworkAclEntries(d *schema.ResourceData, entryType string, ec2conn *
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
|
|
|
@ -151,7 +151,7 @@ func TestAccAWSNetworkAclsOnlyEgressRules(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),
|
||||||
testAccCheckTagsSDK(&networkAcl.Tags, "foo", "bar"),
|
testAccCheckTags(&networkAcl.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -184,7 +184,7 @@ func TestAccAWSNetworkAcl_SubnetChange(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
if rs.Type != "aws_network" {
|
if rs.Type != "aws_network" {
|
||||||
|
@ -226,7 +226,7 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkACL) resou
|
||||||
if rs.Primary.ID == "" {
|
if rs.Primary.ID == "" {
|
||||||
return fmt.Errorf("No Security Group is set")
|
return fmt.Errorf("No Security Group is set")
|
||||||
}
|
}
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||||
NetworkACLIDs: []string{rs.Primary.ID},
|
NetworkACLIDs: []string{rs.Primary.ID},
|
||||||
|
@ -266,7 +266,7 @@ func testAccCheckSubnetIsAssociatedWithAcl(acl string, sub string) resource.Test
|
||||||
networkAcl := s.RootModule().Resources[acl]
|
networkAcl := s.RootModule().Resources[acl]
|
||||||
subnet := s.RootModule().Resources[sub]
|
subnet := s.RootModule().Resources[sub]
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||||
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
||||||
Filters: []ec2.Filter{
|
Filters: []ec2.Filter{
|
||||||
|
@ -296,7 +296,7 @@ func testAccCheckSubnetIsNotAssociatedWithAcl(acl string, subnet string) resourc
|
||||||
networkAcl := s.RootModule().Resources[acl]
|
networkAcl := s.RootModule().Resources[acl]
|
||||||
subnet := s.RootModule().Resources[subnet]
|
subnet := s.RootModule().Resources[subnet]
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||||
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
||||||
Filters: []ec2.Filter{
|
Filters: []ec2.Filter{
|
||||||
|
|
|
@ -62,7 +62,7 @@ func resourceAwsRouteTable() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Create the routing table
|
// Create the routing table
|
||||||
createOpts := &ec2.CreateRouteTableRequest{
|
createOpts := &ec2.CreateRouteTableRequest{
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id())()
|
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -146,13 +146,13 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("route", route)
|
d.Set("route", route)
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
d.Set("tags", tagsToMapSDK(rt.Tags))
|
d.Set("tags", tagsToMap(rt.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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") {
|
||||||
|
@ -203,7 +203,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -213,7 +213,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf("[INFO] Deleting route table association: %s", d.Id())
|
log.Printf("[INFO] Deleting route table association: %s", d.Id())
|
||||||
err := ec2conn.DisassociateRouteTable(&ec2.DisassociateRouteTableRequest{
|
err := ec2conn.DisassociateRouteTable(&ec2.DisassociateRouteTableRequest{
|
||||||
|
|
|
@ -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).awsEC2conn
|
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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
||||||
RouteTableIDs: []string{rs.Primary.Attributes["route_table_id"]},
|
RouteTableIDs: []string{rs.Primary.Attributes["route_table_id"]},
|
||||||
})
|
})
|
||||||
|
|
|
@ -134,7 +134,7 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
|
||||||
Config: testAccRouteTableConfigTags,
|
Config: testAccRouteTableConfigTags,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
||||||
testAccCheckTagsSDK(&route_table.Tags, "foo", "bar"),
|
testAccCheckTags(&route_table.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -142,8 +142,8 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
|
||||||
Config: testAccRouteTableConfigTagsUpdate,
|
Config: testAccRouteTableConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
||||||
testAccCheckTagsSDK(&route_table.Tags, "foo", ""),
|
testAccCheckTags(&route_table.Tags, "foo", ""),
|
||||||
testAccCheckTagsSDK(&route_table.Tags, "bar", "baz"),
|
testAccCheckTags(&route_table.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -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).awsEC2conn
|
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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
||||||
RouteTableIDs: []string{rs.Primary.ID},
|
RouteTableIDs: []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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
securityGroupOpts := &ec2.CreateSecurityGroupRequest{
|
securityGroupOpts := &ec2.CreateSecurityGroupRequest{
|
||||||
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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
sgRaw, _, err := SGStateRefreshFunc(ec2conn, d.Id())()
|
sgRaw, _, err := SGStateRefreshFunc(ec2conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -209,12 +209,12 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
d.Set("owner_id", sg.OwnerID)
|
d.Set("owner_id", sg.OwnerID)
|
||||||
d.Set("ingress", ingressRules)
|
d.Set("ingress", ingressRules)
|
||||||
d.Set("egress", egressRules)
|
d.Set("egress", egressRules)
|
||||||
d.Set("tags", tagsToMapSDK(sg.Tags))
|
d.Set("tags", tagsToMap(sg.Tags))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
sgRaw, _, err := SGStateRefreshFunc(ec2conn, d.Id())()
|
sgRaw, _, err := SGStateRefreshFunc(ec2conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -239,7 +239,7 @@ func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf("[DEBUG] Security Group destroy: %v", d.Id())
|
log.Printf("[DEBUG] Security Group destroy: %v", d.Id())
|
||||||
|
|
||||||
|
@ -354,7 +354,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() {
|
||||||
|
@ -396,7 +396,6 @@ func resourceAwsSecurityGroupUpdateRules(
|
||||||
os := o.(*schema.Set)
|
os := o.(*schema.Set)
|
||||||
ns := n.(*schema.Set)
|
ns := n.(*schema.Set)
|
||||||
|
|
||||||
// TODO: re-munge this when test is updated
|
|
||||||
remove := expandIPPerms(d.Id(), os.Difference(ns).List())
|
remove := expandIPPerms(d.Id(), os.Difference(ns).List())
|
||||||
add := expandIPPerms(d.Id(), ns.Difference(os).List())
|
add := expandIPPerms(d.Id(), ns.Difference(os).List())
|
||||||
|
|
||||||
|
@ -410,7 +409,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if len(remove) > 0 {
|
if len(remove) > 0 {
|
||||||
|
|
|
@ -186,7 +186,7 @@ func TestAccAWSSecurityGroup_Change(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
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" {
|
||||||
|
@ -230,7 +230,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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
req := &ec2.DescribeSecurityGroupsRequest{
|
req := &ec2.DescribeSecurityGroupsRequest{
|
||||||
GroupIDs: []string{rs.Primary.ID},
|
GroupIDs: []string{rs.Primary.ID},
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ func TestAccAWSSecurityGroup_tags(t *testing.T) {
|
||||||
Config: testAccAWSSecurityGroupConfigTags,
|
Config: testAccAWSSecurityGroupConfigTags,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
||||||
testAccCheckTagsSDK(&group.Tags, "foo", "bar"),
|
testAccCheckTags(&group.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -304,8 +304,8 @@ func TestAccAWSSecurityGroup_tags(t *testing.T) {
|
||||||
Config: testAccAWSSecurityGroupConfigTagsUpdate,
|
Config: testAccAWSSecurityGroupConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
||||||
testAccCheckTagsSDK(&group.Tags, "foo", ""),
|
testAccCheckTags(&group.Tags, "foo", ""),
|
||||||
testAccCheckTagsSDK(&group.Tags, "bar", "baz"),
|
testAccCheckTags(&group.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,7 +51,7 @@ func resourceAwsSubnet() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
createOpts := &ec2.CreateSubnetRequest{
|
createOpts := &ec2.CreateSubnetRequest{
|
||||||
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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsRequest{
|
resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsRequest{
|
||||||
SubnetIDs: []string{d.Id()},
|
SubnetIDs: []string{d.Id()},
|
||||||
|
@ -115,17 +115,17 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("availability_zone", subnet.AvailabilityZone)
|
d.Set("availability_zone", subnet.AvailabilityZone)
|
||||||
d.Set("cidr_block", subnet.CIDRBlock)
|
d.Set("cidr_block", subnet.CIDRBlock)
|
||||||
d.Set("map_public_ip_on_launch", subnet.MapPublicIPOnLaunch)
|
d.Set("map_public_ip_on_launch", subnet.MapPublicIPOnLaunch)
|
||||||
d.Set("tags", tagsToMapSDK(subnet.Tags))
|
d.Set("tags", tagsToMap(subnet.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -154,7 +154,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf("[INFO] Deleting subnet: %s", d.Id())
|
log.Printf("[INFO] Deleting subnet: %s", d.Id())
|
||||||
|
|
||||||
|
|
|
@ -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).awsEC2conn
|
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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsRequest{
|
resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsRequest{
|
||||||
SubnetIDs: []string{rs.Primary.ID},
|
SubnetIDs: []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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := 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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Refresh the VPC state
|
// Refresh the VPC state
|
||||||
vpcRaw, _, err := VPCStateRefreshFunc(ec2conn, d.Id())()
|
vpcRaw, _, err := VPCStateRefreshFunc(ec2conn, d.Id())()
|
||||||
|
@ -128,7 +128,7 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("cidr_block", vpc.CIDRBlock)
|
d.Set("cidr_block", vpc.CIDRBlock)
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
d.Set("tags", tagsToMapSDK(vpc.Tags))
|
d.Set("tags", tagsToMap(vpc.Tags))
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
attribute := "enableDnsSupport"
|
attribute := "enableDnsSupport"
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Turn on partial mode
|
// Turn on partial mode
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
|
@ -220,7 +220,7 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.SetPartial("enable_dns_support")
|
d.SetPartial("enable_dns_support")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -231,7 +231,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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
vpcID := d.Id()
|
vpcID := d.Id()
|
||||||
DeleteVpcOpts := &ec2.DeleteVPCRequest{
|
DeleteVpcOpts := &ec2.DeleteVPCRequest{
|
||||||
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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Create the vpc peering connection
|
// Create the vpc peering connection
|
||||||
createOpts := &ec2.CreateVPCPeeringConnectionRequest{
|
createOpts := &ec2.CreateVPCPeeringConnectionRequest{
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())()
|
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -95,15 +95,15 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("peer_owner_id", pc.AccepterVPCInfo.OwnerID)
|
d.Set("peer_owner_id", pc.AccepterVPCInfo.OwnerID)
|
||||||
d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID)
|
d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID)
|
||||||
d.Set("vpc_id", pc.RequesterVPCInfo.VPCID)
|
d.Set("vpc_id", pc.RequesterVPCInfo.VPCID)
|
||||||
d.Set("tags", tagsToMapSDK(pc.Tags))
|
d.Set("tags", tagsToMap(pc.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -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 {
|
||||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
_, err := ec2conn.DeleteVPCPeeringConnection(
|
_, err := ec2conn.DeleteVPCPeeringConnection(
|
||||||
&ec2.DeleteVPCPeeringConnectionRequest{
|
&ec2.DeleteVPCPeeringConnectionRequest{
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestAccAWSVPCPeeringConnection_normal(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
|
func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
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" {
|
||||||
|
|
|
@ -65,7 +65,7 @@ func TestAccVpc_tags(t *testing.T) {
|
||||||
testAccCheckVpcCidr(&vpc, "10.1.0.0/16"),
|
testAccCheckVpcCidr(&vpc, "10.1.0.0/16"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_vpc.foo", "cidr_block", "10.1.0.0/16"),
|
"aws_vpc.foo", "cidr_block", "10.1.0.0/16"),
|
||||||
testAccCheckTagsSDK(&vpc.Tags, "foo", "bar"),
|
testAccCheckTags(&vpc.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ func TestAccVpc_tags(t *testing.T) {
|
||||||
Config: testAccVpcConfigTagsUpdate,
|
Config: testAccVpcConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckVpcExists("aws_vpc.foo", &vpc),
|
testAccCheckVpcExists("aws_vpc.foo", &vpc),
|
||||||
testAccCheckTagsSDK(&vpc.Tags, "foo", ""),
|
testAccCheckTags(&vpc.Tags, "foo", ""),
|
||||||
testAccCheckTagsSDK(&vpc.Tags, "bar", "baz"),
|
testAccCheckTags(&vpc.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -111,7 +111,7 @@ func TestAccVpcUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckVpcDestroy(s *terraform.State) error {
|
func testAccCheckVpcDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
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" {
|
||||||
|
@ -166,7 +166,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).awsEC2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
DescribeVpcOpts := &ec2.DescribeVPCsRequest{
|
DescribeVpcOpts := &ec2.DescribeVPCsRequest{
|
||||||
VPCIDs: []string{rs.Primary.ID},
|
VPCIDs: []string{rs.Primary.ID},
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
awsEC2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Takes the result of flatmap.Expand for an array of listeners and
|
// Takes the result of flatmap.Expand for an array of listeners and
|
||||||
|
@ -17,7 +16,7 @@ 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 goamz 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{})
|
||||||
|
|
||||||
|
@ -40,10 +39,10 @@ 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(id string, configured []interface{}) []awsEC2.IPPermission {
|
func expandIPPerms(id string, configured []interface{}) []ec2.IPPermission {
|
||||||
perms := make([]awsEC2.IPPermission, len(configured))
|
perms := make([]ec2.IPPermission, len(configured))
|
||||||
for i, mRaw := range configured {
|
for i, mRaw := range configured {
|
||||||
var perm awsEC2.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.Integer(m["from_port"].(int))
|
||||||
|
@ -62,14 +61,14 @@ func expandIPPerms(id string, configured []interface{}) []awsEC2.IPPermission {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(groups) > 0 {
|
if len(groups) > 0 {
|
||||||
perm.UserIDGroupPairs = make([]awsEC2.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] = awsEC2.UserIDGroupPair{
|
perm.UserIDGroupPairs[i] = ec2.UserIDGroupPair{
|
||||||
GroupID: aws.String(id),
|
GroupID: aws.String(id),
|
||||||
UserID: aws.String(ownerId),
|
UserID: aws.String(ownerId),
|
||||||
}
|
}
|
||||||
|
@ -78,9 +77,9 @@ func expandIPPerms(id string, configured []interface{}) []awsEC2.IPPermission {
|
||||||
|
|
||||||
if raw, ok := m["cidr_blocks"]; ok {
|
if raw, ok := m["cidr_blocks"]; ok {
|
||||||
list := raw.([]interface{})
|
list := raw.([]interface{})
|
||||||
perm.IPRanges = make([]awsEC2.IPRange, len(list))
|
perm.IPRanges = make([]ec2.IPRange, len(list))
|
||||||
for i, v := range list {
|
for i, v := range list {
|
||||||
perm.IPRanges[i] = awsEC2.IPRange{aws.String(v.(string))}
|
perm.IPRanges[i] = ec2.IPRange{aws.String(v.(string))}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +95,7 @@ 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 goamz 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{})
|
||||||
|
|
||||||
|
@ -130,16 +129,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.UserSecurityGroup) []string {
|
func flattenSecurityGroups(list []ec2.UserIDGroupPair) []string {
|
||||||
result := make([]string, 0, len(list))
|
|
||||||
for _, g := range list {
|
|
||||||
result = append(result, g.Id)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flattens an array of UserSecurityGroups into a []string
|
|
||||||
func flattenSecurityGroupsSDK(list []awsEC2.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)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
awsEC2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
|
ec2 "github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||||
"github.com/hashicorp/terraform/flatmap"
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
|
@ -61,28 +61,28 @@ func TestExpandIPPerms(t *testing.T) {
|
||||||
}
|
}
|
||||||
perms := expandIPPerms("foo", expanded)
|
perms := expandIPPerms("foo", expanded)
|
||||||
|
|
||||||
expected := []awsEC2.IPPermission{
|
expected := []ec2.IPPermission{
|
||||||
awsEC2.IPPermission{
|
ec2.IPPermission{
|
||||||
IPProtocol: aws.String("icmp"),
|
IPProtocol: aws.String("icmp"),
|
||||||
FromPort: aws.Integer(1),
|
FromPort: aws.Integer(1),
|
||||||
ToPort: aws.Integer(-1),
|
ToPort: aws.Integer(-1),
|
||||||
IPRanges: []awsEC2.IPRange{awsEC2.IPRange{aws.String("0.0.0.0/0")}},
|
IPRanges: []ec2.IPRange{ec2.IPRange{aws.String("0.0.0.0/0")}},
|
||||||
UserIDGroupPairs: []awsEC2.UserIDGroupPair{
|
UserIDGroupPairs: []ec2.UserIDGroupPair{
|
||||||
awsEC2.UserIDGroupPair{
|
ec2.UserIDGroupPair{
|
||||||
UserID: aws.String("foo"),
|
UserID: aws.String("foo"),
|
||||||
GroupID: aws.String("sg-22222"),
|
GroupID: aws.String("sg-22222"),
|
||||||
},
|
},
|
||||||
awsEC2.UserIDGroupPair{
|
ec2.UserIDGroupPair{
|
||||||
GroupID: aws.String("sg-22222"),
|
GroupID: aws.String("sg-22222"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
awsEC2.IPPermission{
|
ec2.IPPermission{
|
||||||
IPProtocol: aws.String("icmp"),
|
IPProtocol: aws.String("icmp"),
|
||||||
FromPort: aws.Integer(1),
|
FromPort: aws.Integer(1),
|
||||||
ToPort: aws.Integer(-1),
|
ToPort: aws.Integer(-1),
|
||||||
UserIDGroupPairs: []awsEC2.UserIDGroupPair{
|
UserIDGroupPairs: []ec2.UserIDGroupPair{
|
||||||
awsEC2.UserIDGroupPair{
|
ec2.UserIDGroupPair{
|
||||||
UserID: aws.String("foo"),
|
UserID: aws.String("foo"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,11 +3,13 @@ package aws
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// tagsSchema returns the schema to use for tags.
|
// tagsSchema returns the schema to use for tags.
|
||||||
|
//
|
||||||
func tagsSchema() *schema.Schema {
|
func tagsSchema() *schema.Schema {
|
||||||
return &schema.Schema{
|
return &schema.Schema{
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
|
@ -27,13 +29,21 @@ func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||||
// 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)
|
||||||
if _, err := conn.DeleteTags([]string{d.Id()}, remove); err != nil {
|
err := conn.DeleteTags(&ec2.DeleteTagsRequest{
|
||||||
|
Resources: []string{d.Id()},
|
||||||
|
Tags: remove,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(create) > 0 {
|
if len(create) > 0 {
|
||||||
log.Printf("[DEBUG] Creating tags: %#v", create)
|
log.Printf("[DEBUG] Creating tags: %#v", create)
|
||||||
if _, err := conn.CreateTags([]string{d.Id()}, create); err != nil {
|
err := conn.CreateTags(&ec2.CreateTagsRequest{
|
||||||
|
Resources: []string{d.Id()},
|
||||||
|
Tags: create,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,14 +59,14 @@ func diffTags(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 {
|
||||||
create[t.Key] = t.Value
|
create[*t.Key] = *t.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
||||||
// Delete it!
|
// Delete it!
|
||||||
remove = append(remove, t)
|
remove = append(remove, t)
|
||||||
}
|
}
|
||||||
|
@ -70,8 +80,8 @@ func tagsFromMap(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: k,
|
Key: aws.String(k),
|
||||||
Value: v.(string),
|
Value: aws.String(v.(string)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +92,7 @@ func tagsFromMap(m map[string]interface{}) []ec2.Tag {
|
||||||
func tagsToMap(ts []ec2.Tag) map[string]string {
|
func tagsToMap(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
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
package aws
|
|
||||||
|
|
||||||
// TODO: Clint: consolidate tags and tags_sdk
|
|
||||||
// tags_sdk and tags_sdk_test are used only for transition to aws-sdk-go
|
|
||||||
// and will replace tags and tags_test when the transition to aws-sdk-go/ec2 is
|
|
||||||
// complete
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
|
||||||
)
|
|
||||||
|
|
||||||
// tagsSchema returns the schema to use for tags.
|
|
||||||
//
|
|
||||||
// TODO: uncomment this when we replace the original tags.go
|
|
||||||
//
|
|
||||||
// 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.DeleteTagsRequest{
|
|
||||||
Resources: []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.CreateTagsRequest{
|
|
||||||
Resources: []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/hashicorp/aws-sdk-go/gen/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,9 +5,9 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiffTags(t *testing.T) {
|
func TestDiffTags(t *testing.T) {
|
||||||
|
|
|
@ -56,4 +56,4 @@ The following attributes are exported:
|
||||||
|
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
You still have to accept the peering with the aws console, aws-cli or goamz
|
You still have to accept the peering with the aws console, aws-cli or aws-sdk-go.
|
||||||
|
|
Loading…
Reference in New Issue