Merge remote-tracking branch 'refs/remotes/origin/master' into route53-zone-nameservers
This commit is contained in:
commit
c3f9c12426
23
CHANGELOG.md
23
CHANGELOG.md
|
@ -1,3 +1,26 @@
|
||||||
|
## 0.5.0 (unreleased)
|
||||||
|
|
||||||
|
IMPROVEMENTS:
|
||||||
|
|
||||||
|
* **New config function: `length`** - Get the length of a string or a list.
|
||||||
|
Useful in conjunction with `split`. [GH-1495]
|
||||||
|
* core: Improve error message on diff mismatch [GH-1501]
|
||||||
|
* provisioner/file: expand `~` in source path [GH-1569]
|
||||||
|
|
||||||
|
BUG FIXES:
|
||||||
|
|
||||||
|
* core: math on arbitrary variables works if first operand isn't a
|
||||||
|
numeric primitive. [GH-1381]
|
||||||
|
* core: avoid unnecessary cycles by pruning tainted destroys from
|
||||||
|
graph if there are no tainted resources [GH-1475]
|
||||||
|
* core: fix issue where destroy nodes weren't pruned in specific
|
||||||
|
edge cases around matching prefixes, which could cause cycles [GH-1527]
|
||||||
|
* core: fix issue causing diff mismatch errors in certain scenarios during
|
||||||
|
resource replacement [GH-1515]
|
||||||
|
* command: remote states with uppercase types work [GH-1356]
|
||||||
|
* provider/aws: launch configuration ID set after create success [GH-1518]
|
||||||
|
* provider/openstack: region config is not required [GH-1441]
|
||||||
|
|
||||||
## 0.4.2 (April 10, 2015)
|
## 0.4.2 (April 10, 2015)
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -61,23 +61,23 @@ func setAutoscalingTags(conn *autoscaling.AutoScaling, d *schema.ResourceData) e
|
||||||
autoscalingTagsFromMap(o, resourceID),
|
autoscalingTagsFromMap(o, resourceID),
|
||||||
autoscalingTagsFromMap(n, resourceID),
|
autoscalingTagsFromMap(n, resourceID),
|
||||||
resourceID)
|
resourceID)
|
||||||
create := autoscaling.CreateOrUpdateTagsType{
|
create := autoscaling.CreateOrUpdateTagsInput{
|
||||||
Tags: c,
|
Tags: c,
|
||||||
}
|
}
|
||||||
remove := autoscaling.DeleteTagsType{
|
remove := autoscaling.DeleteTagsInput{
|
||||||
Tags: r,
|
Tags: r,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set tags
|
// Set tags
|
||||||
if len(r) > 0 {
|
if len(r) > 0 {
|
||||||
log.Printf("[DEBUG] Removing autoscaling tags: %#v", r)
|
log.Printf("[DEBUG] Removing autoscaling tags: %#v", r)
|
||||||
if err := conn.DeleteTags(&remove); err != nil {
|
if _, err := conn.DeleteTags(&remove); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(c) > 0 {
|
if len(c) > 0 {
|
||||||
log.Printf("[DEBUG] Creating autoscaling tags: %#v", c)
|
log.Printf("[DEBUG] Creating autoscaling tags: %#v", c)
|
||||||
if err := conn.CreateOrUpdateTags(&create); err != nil {
|
if _, err := conn.CreateOrUpdateTags(&create); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func setAutoscalingTags(conn *autoscaling.AutoScaling, d *schema.ResourceData) e
|
||||||
// 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 diffAutoscalingTags(oldTags, newTags []autoscaling.Tag, resourceID string) ([]autoscaling.Tag, []autoscaling.Tag) {
|
func diffAutoscalingTags(oldTags, newTags []*autoscaling.Tag, resourceID string) ([]*autoscaling.Tag, []*autoscaling.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 {
|
||||||
|
@ -101,7 +101,7 @@ func diffAutoscalingTags(oldTags, newTags []autoscaling.Tag, resourceID string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of what to remove
|
// Build the list of what to remove
|
||||||
var remove []autoscaling.Tag
|
var remove []*autoscaling.Tag
|
||||||
for _, t := range oldTags {
|
for _, t := range oldTags {
|
||||||
old, ok := create[*t.Key].(map[string]interface{})
|
old, ok := create[*t.Key].(map[string]interface{})
|
||||||
|
|
||||||
|
@ -115,11 +115,11 @@ func diffAutoscalingTags(oldTags, newTags []autoscaling.Tag, resourceID string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsFromMap returns the tags for the given map of data.
|
// tagsFromMap returns the tags for the given map of data.
|
||||||
func autoscalingTagsFromMap(m map[string]interface{}, resourceID string) []autoscaling.Tag {
|
func autoscalingTagsFromMap(m map[string]interface{}, resourceID string) []*autoscaling.Tag {
|
||||||
result := make([]autoscaling.Tag, 0, len(m))
|
result := make([]*autoscaling.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
attr := v.(map[string]interface{})
|
attr := v.(map[string]interface{})
|
||||||
result = append(result, autoscaling.Tag{
|
result = append(result, &autoscaling.Tag{
|
||||||
Key: aws.String(k),
|
Key: aws.String(k),
|
||||||
Value: aws.String(attr["value"].(string)),
|
Value: aws.String(attr["value"].(string)),
|
||||||
PropagateAtLaunch: aws.Boolean(attr["propagate_at_launch"].(bool)),
|
PropagateAtLaunch: aws.Boolean(attr["propagate_at_launch"].(bool)),
|
||||||
|
@ -132,7 +132,7 @@ func autoscalingTagsFromMap(m map[string]interface{}, resourceID string) []autos
|
||||||
}
|
}
|
||||||
|
|
||||||
// autoscalingTagsToMap turns the list of tags into a map.
|
// autoscalingTagsToMap turns the list of tags into a map.
|
||||||
func autoscalingTagsToMap(ts []autoscaling.Tag) map[string]interface{} {
|
func autoscalingTagsToMap(ts []*autoscaling.Tag) map[string]interface{} {
|
||||||
tags := make(map[string]interface{})
|
tags := make(map[string]interface{})
|
||||||
for _, t := range ts {
|
for _, t := range ts {
|
||||||
tag := map[string]interface{}{
|
tag := map[string]interface{}{
|
||||||
|
@ -146,9 +146,9 @@ func autoscalingTagsToMap(ts []autoscaling.Tag) map[string]interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// autoscalingTagDescriptionsToMap turns the list of tags into a map.
|
// autoscalingTagDescriptionsToMap turns the list of tags into a map.
|
||||||
func autoscalingTagDescriptionsToMap(ts []autoscaling.TagDescription) map[string]map[string]interface{} {
|
func autoscalingTagDescriptionsToMap(ts *[]*autoscaling.TagDescription) map[string]map[string]interface{} {
|
||||||
tags := make(map[string]map[string]interface{})
|
tags := make(map[string]map[string]interface{})
|
||||||
for _, t := range ts {
|
for _, t := range *ts {
|
||||||
tag := map[string]interface{}{
|
tag := map[string]interface{}{
|
||||||
"value": *t.Value,
|
"value": *t.Value,
|
||||||
"propagate_at_launch": *t.PropagateAtLaunch,
|
"propagate_at_launch": *t.PropagateAtLaunch,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -93,9 +93,9 @@ func TestDiffAutoscalingTags(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 testAccCheckAutoscalingTags(
|
func testAccCheckAutoscalingTags(
|
||||||
ts *[]autoscaling.TagDescription, key string, expected map[string]interface{}) resource.TestCheckFunc {
|
ts *[]*autoscaling.TagDescription, key string, expected map[string]interface{}) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
m := autoscalingTagDescriptionsToMap(*ts)
|
m := autoscalingTagDescriptionsToMap(ts)
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Missing tag: %s", key)
|
return fmt.Errorf("Missing tag: %s", key)
|
||||||
|
@ -110,9 +110,9 @@ func testAccCheckAutoscalingTags(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAutoscalingTagNotExists(ts *[]autoscaling.TagDescription, key string) resource.TestCheckFunc {
|
func testAccCheckAutoscalingTagNotExists(ts *[]*autoscaling.TagDescription, key string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
m := autoscalingTagDescriptionsToMap(*ts)
|
m := autoscalingTagDescriptionsToMap(ts)
|
||||||
if _, ok := m[key]; ok {
|
if _, ok := m[key]; ok {
|
||||||
return fmt.Errorf("Tag exists when it should not: %s", key)
|
return fmt.Errorf("Tag exists when it should not: %s", key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,14 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/multierror"
|
"github.com/hashicorp/terraform/helper/multierror"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
"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/iam"
|
"github.com/awslabs/aws-sdk-go/service/iam"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
|
|
||||||
awsSDK "github.com/awslabs/aws-sdk-go/aws"
|
|
||||||
awsEC2 "github.com/awslabs/aws-sdk-go/service/ec2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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,30 +55,37 @@ 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{
|
||||||
|
Credentials: creds,
|
||||||
|
Region: c.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(awsConfig)
|
||||||
log.Println("[INFO] Initializing AutoScaling connection")
|
|
||||||
client.autoscalingconn = autoscaling.New(creds, c.Region, nil)
|
|
||||||
log.Println("[INFO] Initializing S3 connection")
|
log.Println("[INFO] Initializing S3 connection")
|
||||||
client.s3conn = s3.New(creds, c.Region, nil)
|
client.s3conn = s3.New(awsConfig)
|
||||||
log.Println("[INFO] Initializing RDS connection")
|
|
||||||
client.rdsconn = rds.New(creds, c.Region, nil)
|
log.Println("[INFO] Initializing RDS Connection")
|
||||||
|
client.rdsconn = rds.New(awsConfig)
|
||||||
|
|
||||||
|
log.Println("[INFO] Initializing IAM Connection")
|
||||||
|
client.iamconn = iam.New(awsConfig)
|
||||||
|
log.Println("[INFO] Initializing AutoScaling connection")
|
||||||
|
client.autoscalingconn = autoscaling.New(awsConfig)
|
||||||
|
|
||||||
|
log.Println("[INFO] Initializing EC2 Connection")
|
||||||
|
client.ec2conn = ec2.New(awsConfig)
|
||||||
|
|
||||||
// aws-sdk-go uses v4 for signing requests, which requires all global
|
// 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 Route53 connection")
|
log.Println("[INFO] Initializing Route 53 connection")
|
||||||
client.r53conn = route53.New(creds, "us-east-1", nil)
|
client.r53conn = route53.New(&aws.Config{
|
||||||
log.Println("[INFO] Initializing EC2 Connection")
|
Credentials: creds,
|
||||||
client.ec2conn = ec2.New(creds, c.Region, nil)
|
Region: "us-east-1",
|
||||||
client.iamconn = iam.New(creds, c.Region, nil)
|
|
||||||
|
|
||||||
sdkCreds := awsSDK.DetectCreds(c.AccessKey, c.SecretKey, c.Token)
|
|
||||||
client.ec2SDKconn = awsEC2.New(&awsSDK.Config{
|
|
||||||
Credentials: sdkCreds,
|
|
||||||
Region: c.Region,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsAutoscalingGroup() *schema.Resource {
|
func resourceAwsAutoscalingGroup() *schema.Resource {
|
||||||
|
@ -127,11 +127,11 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
|
||||||
func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||||
|
|
||||||
var autoScalingGroupOpts autoscaling.CreateAutoScalingGroupType
|
var autoScalingGroupOpts autoscaling.CreateAutoScalingGroupInput
|
||||||
autoScalingGroupOpts.AutoScalingGroupName = aws.String(d.Get("name").(string))
|
autoScalingGroupOpts.AutoScalingGroupName = aws.String(d.Get("name").(string))
|
||||||
autoScalingGroupOpts.LaunchConfigurationName = aws.String(d.Get("launch_configuration").(string))
|
autoScalingGroupOpts.LaunchConfigurationName = aws.String(d.Get("launch_configuration").(string))
|
||||||
autoScalingGroupOpts.MinSize = aws.Integer(d.Get("min_size").(int))
|
autoScalingGroupOpts.MinSize = aws.Long(int64(d.Get("min_size").(int)))
|
||||||
autoScalingGroupOpts.MaxSize = aws.Integer(d.Get("max_size").(int))
|
autoScalingGroupOpts.MaxSize = aws.Long(int64(d.Get("max_size").(int)))
|
||||||
autoScalingGroupOpts.AvailabilityZones = expandStringList(
|
autoScalingGroupOpts.AvailabilityZones = expandStringList(
|
||||||
d.Get("availability_zones").(*schema.Set).List())
|
d.Get("availability_zones").(*schema.Set).List())
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("default_cooldown"); ok {
|
if v, ok := d.GetOk("default_cooldown"); ok {
|
||||||
autoScalingGroupOpts.DefaultCooldown = aws.Integer(v.(int))
|
autoScalingGroupOpts.DefaultCooldown = aws.Long(int64(v.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("health_check_type"); ok && v.(string) != "" {
|
if v, ok := d.GetOk("health_check_type"); ok && v.(string) != "" {
|
||||||
|
@ -149,11 +149,11 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("desired_capacity"); ok {
|
if v, ok := d.GetOk("desired_capacity"); ok {
|
||||||
autoScalingGroupOpts.DesiredCapacity = aws.Integer(v.(int))
|
autoScalingGroupOpts.DesiredCapacity = aws.Long(int64(v.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("health_check_grace_period"); ok {
|
if v, ok := d.GetOk("health_check_grace_period"); ok {
|
||||||
autoScalingGroupOpts.HealthCheckGracePeriod = aws.Integer(v.(int))
|
autoScalingGroupOpts.HealthCheckGracePeriod = aws.Long(int64(v.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -163,7 +163,11 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
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 := expandStringList(v.(*schema.Set).List())
|
exp := expandStringList(v.(*schema.Set).List())
|
||||||
autoScalingGroupOpts.VPCZoneIdentifier = aws.String(strings.Join(exp, ","))
|
strs := make([]string, len(exp))
|
||||||
|
for _, s := range exp {
|
||||||
|
strs = append(strs, *s)
|
||||||
|
}
|
||||||
|
autoScalingGroupOpts.VPCZoneIdentifier = aws.String(strings.Join(strs, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -172,7 +176,7 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] AutoScaling Group create configuration: %#v", autoScalingGroupOpts)
|
log.Printf("[DEBUG] AutoScaling Group create configuration: %#v", autoScalingGroupOpts)
|
||||||
err := autoscalingconn.CreateAutoScalingGroup(&autoScalingGroupOpts)
|
_, err := autoscalingconn.CreateAutoScalingGroup(&autoScalingGroupOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating Autoscaling Group: %s", err)
|
return fmt.Errorf("Error creating Autoscaling Group: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -212,12 +216,12 @@ func resourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) e
|
||||||
func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||||
|
|
||||||
opts := autoscaling.UpdateAutoScalingGroupType{
|
opts := autoscaling.UpdateAutoScalingGroupInput{
|
||||||
AutoScalingGroupName: aws.String(d.Id()),
|
AutoScalingGroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("desired_capacity") {
|
if d.HasChange("desired_capacity") {
|
||||||
opts.DesiredCapacity = aws.Integer(d.Get("desired_capacity").(int))
|
opts.DesiredCapacity = aws.Long(int64(d.Get("desired_capacity").(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("launch_configuration") {
|
if d.HasChange("launch_configuration") {
|
||||||
|
@ -225,11 +229,11 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("min_size") {
|
if d.HasChange("min_size") {
|
||||||
opts.MinSize = aws.Integer(d.Get("min_size").(int))
|
opts.MinSize = aws.Long(int64(d.Get("min_size").(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("max_size") {
|
if d.HasChange("max_size") {
|
||||||
opts.MaxSize = aws.Integer(d.Get("max_size").(int))
|
opts.MaxSize = aws.Long(int64(d.Get("max_size").(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setAutoscalingTags(autoscalingconn, d); err != nil {
|
if err := setAutoscalingTags(autoscalingconn, d); err != nil {
|
||||||
|
@ -239,7 +243,7 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] AutoScaling Group update configuration: %#v", opts)
|
log.Printf("[DEBUG] AutoScaling Group update configuration: %#v", opts)
|
||||||
err := autoscalingconn.UpdateAutoScalingGroup(&opts)
|
_, err := autoscalingconn.UpdateAutoScalingGroup(&opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
return fmt.Errorf("Error updating Autoscaling group: %s", err)
|
return fmt.Errorf("Error updating Autoscaling group: %s", err)
|
||||||
|
@ -268,7 +272,7 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id())
|
log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id())
|
||||||
deleteopts := autoscaling.DeleteAutoScalingGroupType{AutoScalingGroupName: aws.String(d.Id())}
|
deleteopts := autoscaling.DeleteAutoScalingGroupInput{AutoScalingGroupName: aws.String(d.Id())}
|
||||||
|
|
||||||
// You can force an autoscaling group to delete
|
// You can force an autoscaling group to delete
|
||||||
// even if it's in the process of scaling a resource.
|
// even if it's in the process of scaling a resource.
|
||||||
|
@ -279,7 +283,7 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
|
||||||
deleteopts.ForceDelete = aws.Boolean(true)
|
deleteopts.ForceDelete = aws.Boolean(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := autoscalingconn.DeleteAutoScalingGroup(&deleteopts); err != nil {
|
if _, err := autoscalingconn.DeleteAutoScalingGroup(&deleteopts); err != nil {
|
||||||
autoscalingerr, ok := err.(aws.APIError)
|
autoscalingerr, ok := err.(aws.APIError)
|
||||||
if ok && autoscalingerr.Code == "InvalidGroup.NotFound" {
|
if ok && autoscalingerr.Code == "InvalidGroup.NotFound" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -300,8 +304,8 @@ func getAwsAutoscalingGroup(
|
||||||
meta interface{}) (*autoscaling.AutoScalingGroup, error) {
|
meta interface{}) (*autoscaling.AutoScalingGroup, error) {
|
||||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||||
|
|
||||||
describeOpts := autoscaling.AutoScalingGroupNamesType{
|
describeOpts := autoscaling.DescribeAutoScalingGroupsInput{
|
||||||
AutoScalingGroupNames: []string{d.Id()},
|
AutoScalingGroupNames: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts)
|
log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts)
|
||||||
|
@ -319,7 +323,7 @@ func getAwsAutoscalingGroup(
|
||||||
// Search for the autoscaling group
|
// Search for the autoscaling group
|
||||||
for idx, asc := range describeGroups.AutoScalingGroups {
|
for idx, asc := range describeGroups.AutoScalingGroups {
|
||||||
if *asc.AutoScalingGroupName == d.Id() {
|
if *asc.AutoScalingGroupName == d.Id() {
|
||||||
return &describeGroups.AutoScalingGroups[idx], nil
|
return describeGroups.AutoScalingGroups[idx], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,13 +337,13 @@ func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
// First, set the capacity to zero so the group will drain
|
// First, set the capacity to zero so the group will drain
|
||||||
log.Printf("[DEBUG] Reducing autoscaling group capacity to zero")
|
log.Printf("[DEBUG] Reducing autoscaling group capacity to zero")
|
||||||
opts := autoscaling.UpdateAutoScalingGroupType{
|
opts := autoscaling.UpdateAutoScalingGroupInput{
|
||||||
AutoScalingGroupName: aws.String(d.Id()),
|
AutoScalingGroupName: aws.String(d.Id()),
|
||||||
DesiredCapacity: aws.Integer(0),
|
DesiredCapacity: aws.Long(0),
|
||||||
MinSize: aws.Integer(0),
|
MinSize: aws.Long(0),
|
||||||
MaxSize: aws.Integer(0),
|
MaxSize: aws.Long(0),
|
||||||
}
|
}
|
||||||
if err := autoscalingconn.UpdateAutoScalingGroup(&opts); err != nil {
|
if _, err := autoscalingconn.UpdateAutoScalingGroup(&opts); err != nil {
|
||||||
return fmt.Errorf("Error setting capacity to zero to drain: %s", err)
|
return fmt.Errorf("Error setting capacity to zero to drain: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -98,7 +98,7 @@ func TestAccAWSAutoScalingGroup_tags(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSAutoScalingGroupWithLoadBalancer(t *testing.T) {
|
func TestAccAWSAutoScalingGroup_WithLoadBalancer(t *testing.T) {
|
||||||
var group autoscaling.AutoScalingGroup
|
var group autoscaling.AutoScalingGroup
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
@ -126,8 +126,8 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
// Try to find the Group
|
// Try to find the Group
|
||||||
describeGroups, err := conn.DescribeAutoScalingGroups(
|
describeGroups, err := conn.DescribeAutoScalingGroups(
|
||||||
&autoscaling.AutoScalingGroupNamesType{
|
&autoscaling.DescribeAutoScalingGroupsInput{
|
||||||
AutoScalingGroupNames: []string{rs.Primary.ID},
|
AutoScalingGroupNames: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -152,8 +152,8 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.AutoScalingGroup) resource.TestCheckFunc {
|
func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.AutoScalingGroup) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
if group.AvailabilityZones[0] != "us-west-2a" {
|
if *group.AvailabilityZones[0] != "us-west-2a" {
|
||||||
return fmt.Errorf("Bad availability_zones: %s", group.AvailabilityZones[0])
|
return fmt.Errorf("Bad availability_zones: %#v", group.AvailabilityZones[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if *group.AutoScalingGroupName != "foobar3-terraform-test" {
|
if *group.AutoScalingGroupName != "foobar3-terraform-test" {
|
||||||
|
@ -184,7 +184,7 @@ func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.AutoScalingGro
|
||||||
return fmt.Errorf("Bad launch configuration name: %s", *group.LaunchConfigurationName)
|
return fmt.Errorf("Bad launch configuration name: %s", *group.LaunchConfigurationName)
|
||||||
}
|
}
|
||||||
|
|
||||||
t := autoscaling.TagDescription{
|
t := &autoscaling.TagDescription{
|
||||||
Key: aws.String("Foo"),
|
Key: aws.String("Foo"),
|
||||||
Value: aws.String("foo-bar"),
|
Value: aws.String("foo-bar"),
|
||||||
PropagateAtLaunch: aws.Boolean(true),
|
PropagateAtLaunch: aws.Boolean(true),
|
||||||
|
@ -205,8 +205,8 @@ func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.AutoScalingGro
|
||||||
|
|
||||||
func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.AutoScalingGroup) resource.TestCheckFunc {
|
func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.AutoScalingGroup) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
if group.LoadBalancerNames[0] != "foobar-terraform-test" {
|
if *group.LoadBalancerNames[0] != "foobar-terraform-test" {
|
||||||
return fmt.Errorf("Bad load_balancers: %s", group.LoadBalancerNames[0])
|
return fmt.Errorf("Bad load_balancers: %#v", group.LoadBalancerNames[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -226,10 +226,10 @@ func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScal
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
||||||
|
|
||||||
describeOpts := autoscaling.AutoScalingGroupNamesType{
|
describeGroups, err := conn.DescribeAutoScalingGroups(
|
||||||
AutoScalingGroupNames: []string{rs.Primary.ID},
|
&autoscaling.DescribeAutoScalingGroupsInput{
|
||||||
}
|
AutoScalingGroupNames: []*string{aws.String(rs.Primary.ID)},
|
||||||
describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -240,7 +240,7 @@ func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScal
|
||||||
return fmt.Errorf("AutoScaling Group not found")
|
return fmt.Errorf("AutoScaling Group not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*group = describeGroups.AutoScalingGroups[0]
|
*group = *describeGroups.AutoScalingGroups[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/iam"
|
"github.com/awslabs/aws-sdk-go/service/iam"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
@ -196,8 +196,8 @@ func resourceAwsDbInstance() *schema.Resource {
|
||||||
func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
conn := meta.(*AWSClient).rdsconn
|
conn := meta.(*AWSClient).rdsconn
|
||||||
tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{}))
|
tags := tagsFromMapRDS(d.Get("tags").(map[string]interface{}))
|
||||||
opts := rds.CreateDBInstanceMessage{
|
opts := rds.CreateDBInstanceInput{
|
||||||
AllocatedStorage: aws.Integer(d.Get("allocated_storage").(int)),
|
AllocatedStorage: aws.Long(int64(d.Get("allocated_storage").(int))),
|
||||||
DBInstanceClass: aws.String(d.Get("instance_class").(string)),
|
DBInstanceClass: aws.String(d.Get("instance_class").(string)),
|
||||||
DBInstanceIdentifier: aws.String(d.Get("identifier").(string)),
|
DBInstanceIdentifier: aws.String(d.Get("identifier").(string)),
|
||||||
DBName: aws.String(d.Get("name").(string)),
|
DBName: aws.String(d.Get("name").(string)),
|
||||||
|
@ -214,14 +214,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
attr := d.Get("backup_retention_period")
|
attr := d.Get("backup_retention_period")
|
||||||
opts.BackupRetentionPeriod = aws.Integer(attr.(int))
|
opts.BackupRetentionPeriod = aws.Long(int64(attr.(int)))
|
||||||
|
|
||||||
if attr, ok := d.GetOk("iops"); ok {
|
if attr, ok := d.GetOk("iops"); ok {
|
||||||
opts.IOPS = aws.Integer(attr.(int))
|
opts.IOPS = aws.Long(int64(attr.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr, ok := d.GetOk("port"); ok {
|
if attr, ok := d.GetOk("port"); ok {
|
||||||
opts.Port = aws.Integer(attr.(int))
|
opts.Port = aws.Long(int64(attr.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr, ok := d.GetOk("multi_az"); ok {
|
if attr, ok := d.GetOk("multi_az"); ok {
|
||||||
|
@ -253,17 +253,17 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
|
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
|
||||||
var s []string
|
var s []*string
|
||||||
for _, v := range attr.List() {
|
for _, v := range attr.List() {
|
||||||
s = append(s, v.(string))
|
s = append(s, aws.String(v.(string)))
|
||||||
}
|
}
|
||||||
opts.VPCSecurityGroupIDs = s
|
opts.VPCSecurityGroupIDs = s
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 {
|
if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 {
|
||||||
var s []string
|
var s []*string
|
||||||
for _, v := range attr.List() {
|
for _, v := range attr.List() {
|
||||||
s = append(s, v.(string))
|
s = append(s, aws.String(v.(string)))
|
||||||
}
|
}
|
||||||
opts.DBSecurityGroups = s
|
opts.DBSecurityGroups = s
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
log.Printf("[DEBUG] Error building ARN for DB Instance, not setting Tags for DB %s", name)
|
log.Printf("[DEBUG] Error building ARN for DB Instance, not setting Tags for DB %s", name)
|
||||||
} else {
|
} else {
|
||||||
resp, err := conn.ListTagsForResource(&rds.ListTagsForResourceMessage{
|
resp, err := conn.ListTagsForResource(&rds.ListTagsForResourceInput{
|
||||||
ResourceName: aws.String(arn),
|
ResourceName: aws.String(arn),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
log.Printf("[DEBUG] Error retreiving tags for ARN: %s", arn)
|
log.Printf("[DEBUG] Error retreiving tags for ARN: %s", arn)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dt []rds.Tag
|
var dt []*rds.Tag
|
||||||
if len(resp.TagList) > 0 {
|
if len(resp.TagList) > 0 {
|
||||||
dt = resp.TagList
|
dt = resp.TagList
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
log.Printf("[DEBUG] DB Instance destroy: %v", d.Id())
|
log.Printf("[DEBUG] DB Instance destroy: %v", d.Id())
|
||||||
|
|
||||||
opts := rds.DeleteDBInstanceMessage{DBInstanceIdentifier: aws.String(d.Id())}
|
opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())}
|
||||||
|
|
||||||
finalSnapshot := d.Get("final_snapshot_identifier").(string)
|
finalSnapshot := d.Get("final_snapshot_identifier").(string)
|
||||||
if finalSnapshot == "" {
|
if finalSnapshot == "" {
|
||||||
|
@ -437,7 +437,7 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
|
|
||||||
req := &rds.ModifyDBInstanceMessage{
|
req := &rds.ModifyDBInstanceInput{
|
||||||
ApplyImmediately: aws.Boolean(d.Get("apply_immediately").(bool)),
|
ApplyImmediately: aws.Boolean(d.Get("apply_immediately").(bool)),
|
||||||
DBInstanceIdentifier: aws.String(d.Id()),
|
DBInstanceIdentifier: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
@ -445,11 +445,11 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
if d.HasChange("allocated_storage") {
|
if d.HasChange("allocated_storage") {
|
||||||
d.SetPartial("allocated_storage")
|
d.SetPartial("allocated_storage")
|
||||||
req.AllocatedStorage = aws.Integer(d.Get("allocated_storage").(int))
|
req.AllocatedStorage = aws.Long(int64(d.Get("allocated_storage").(int)))
|
||||||
}
|
}
|
||||||
if d.HasChange("backup_retention_period") {
|
if d.HasChange("backup_retention_period") {
|
||||||
d.SetPartial("backup_retention_period")
|
d.SetPartial("backup_retention_period")
|
||||||
req.BackupRetentionPeriod = aws.Integer(d.Get("backup_retention_period").(int))
|
req.BackupRetentionPeriod = aws.Long(int64(d.Get("backup_retention_period").(int)))
|
||||||
}
|
}
|
||||||
if d.HasChange("instance_class") {
|
if d.HasChange("instance_class") {
|
||||||
d.SetPartial("instance_class")
|
d.SetPartial("instance_class")
|
||||||
|
@ -465,7 +465,7 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
if d.HasChange("iops") {
|
if d.HasChange("iops") {
|
||||||
d.SetPartial("iops")
|
d.SetPartial("iops")
|
||||||
req.IOPS = aws.Integer(d.Get("iops").(int))
|
req.IOPS = aws.Long(int64(d.Get("iops").(int)))
|
||||||
}
|
}
|
||||||
if d.HasChange("backup_window") {
|
if d.HasChange("backup_window") {
|
||||||
d.SetPartial("backup_window")
|
d.SetPartial("backup_window")
|
||||||
|
@ -490,9 +490,9 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
if d.HasChange("vpc_security_group_ids") {
|
if d.HasChange("vpc_security_group_ids") {
|
||||||
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
|
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
|
||||||
var s []string
|
var s []*string
|
||||||
for _, v := range attr.List() {
|
for _, v := range attr.List() {
|
||||||
s = append(s, v.(string))
|
s = append(s, aws.String(v.(string)))
|
||||||
}
|
}
|
||||||
req.VPCSecurityGroupIDs = s
|
req.VPCSecurityGroupIDs = s
|
||||||
}
|
}
|
||||||
|
@ -500,9 +500,9 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
if d.HasChange("vpc_security_group_ids") {
|
if d.HasChange("vpc_security_group_ids") {
|
||||||
if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 {
|
if attr := d.Get("security_group_names").(*schema.Set); attr.Len() > 0 {
|
||||||
var s []string
|
var s []*string
|
||||||
for _, v := range attr.List() {
|
for _, v := range attr.List() {
|
||||||
s = append(s, v.(string))
|
s = append(s, aws.String(v.(string)))
|
||||||
}
|
}
|
||||||
req.DBSecurityGroups = s
|
req.DBSecurityGroups = s
|
||||||
}
|
}
|
||||||
|
@ -529,7 +529,7 @@ func resourceAwsBbInstanceRetrieve(
|
||||||
d *schema.ResourceData, meta interface{}) (*rds.DBInstance, error) {
|
d *schema.ResourceData, meta interface{}) (*rds.DBInstance, error) {
|
||||||
conn := meta.(*AWSClient).rdsconn
|
conn := meta.(*AWSClient).rdsconn
|
||||||
|
|
||||||
opts := rds.DescribeDBInstancesMessage{
|
opts := rds.DescribeDBInstancesInput{
|
||||||
DBInstanceIdentifier: aws.String(d.Id()),
|
DBInstanceIdentifier: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,9 +552,7 @@ func resourceAwsBbInstanceRetrieve(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v := resp.DBInstances[0]
|
return resp.DBInstances[0], nil
|
||||||
|
|
||||||
return &v, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsDbInstanceStateRefreshFunc(
|
func resourceAwsDbInstanceStateRefreshFunc(
|
||||||
|
@ -578,8 +576,8 @@ func resourceAwsDbInstanceStateRefreshFunc(
|
||||||
func buildRDSARN(d *schema.ResourceData, meta interface{}) (string, error) {
|
func buildRDSARN(d *schema.ResourceData, meta interface{}) (string, error) {
|
||||||
iamconn := meta.(*AWSClient).iamconn
|
iamconn := meta.(*AWSClient).iamconn
|
||||||
region := meta.(*AWSClient).region
|
region := meta.(*AWSClient).region
|
||||||
// An zero value GetUserRequest{} defers to the currently logged in user
|
// An zero value GetUserInput{} defers to the currently logged in user
|
||||||
resp, err := iamconn.GetUser(&iam.GetUserRequest{})
|
resp, err := iamconn.GetUser(&iam.GetUserInput{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSDBInstance(t *testing.T) {
|
func TestAccAWSDBInstance(t *testing.T) {
|
||||||
|
@ -56,7 +56,7 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
// Try to find the Group
|
// Try to find the Group
|
||||||
resp, err := conn.DescribeDBInstances(
|
resp, err := conn.DescribeDBInstances(
|
||||||
&rds.DescribeDBInstancesMessage{
|
&rds.DescribeDBInstancesInput{
|
||||||
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
||||||
|
|
||||||
opts := rds.DescribeDBInstancesMessage{
|
opts := rds.DescribeDBInstancesInput{
|
||||||
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC
|
||||||
return fmt.Errorf("DB Instance not found")
|
return fmt.Errorf("DB Instance not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = resp.DBInstances[0]
|
*v = *resp.DBInstances[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsDbParameterGroup() *schema.Resource {
|
func resourceAwsDbParameterGroup() *schema.Resource {
|
||||||
|
@ -75,7 +75,7 @@ func resourceAwsDbParameterGroup() *schema.Resource {
|
||||||
func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
rdsconn := meta.(*AWSClient).rdsconn
|
rdsconn := meta.(*AWSClient).rdsconn
|
||||||
|
|
||||||
createOpts := rds.CreateDBParameterGroupMessage{
|
createOpts := rds.CreateDBParameterGroupInput{
|
||||||
DBParameterGroupName: aws.String(d.Get("name").(string)),
|
DBParameterGroupName: aws.String(d.Get("name").(string)),
|
||||||
DBParameterGroupFamily: aws.String(d.Get("family").(string)),
|
DBParameterGroupFamily: aws.String(d.Get("family").(string)),
|
||||||
Description: aws.String(d.Get("description").(string)),
|
Description: aws.String(d.Get("description").(string)),
|
||||||
|
@ -102,7 +102,7 @@ func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
rdsconn := meta.(*AWSClient).rdsconn
|
rdsconn := meta.(*AWSClient).rdsconn
|
||||||
|
|
||||||
describeOpts := rds.DescribeDBParameterGroupsMessage{
|
describeOpts := rds.DescribeDBParameterGroupsInput{
|
||||||
DBParameterGroupName: aws.String(d.Id()),
|
DBParameterGroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
|
||||||
d.Set("description", describeResp.DBParameterGroups[0].Description)
|
d.Set("description", describeResp.DBParameterGroups[0].Description)
|
||||||
|
|
||||||
// Only include user customized parameters as there's hundreds of system/default ones
|
// Only include user customized parameters as there's hundreds of system/default ones
|
||||||
describeParametersOpts := rds.DescribeDBParametersMessage{
|
describeParametersOpts := rds.DescribeDBParametersInput{
|
||||||
DBParameterGroupName: aws.String(d.Id()),
|
DBParameterGroupName: aws.String(d.Id()),
|
||||||
Source: aws.String("user"),
|
Source: aws.String("user"),
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(parameters) > 0 {
|
if len(parameters) > 0 {
|
||||||
modifyOpts := rds.ModifyDBParameterGroupMessage{
|
modifyOpts := rds.ModifyDBParameterGroupInput{
|
||||||
DBParameterGroupName: aws.String(d.Get("name").(string)),
|
DBParameterGroupName: aws.String(d.Get("name").(string)),
|
||||||
Parameters: parameters,
|
Parameters: parameters,
|
||||||
}
|
}
|
||||||
|
@ -198,11 +198,11 @@ func resourceAwsDbParameterGroupDeleteRefreshFunc(
|
||||||
|
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
|
|
||||||
deleteOpts := rds.DeleteDBParameterGroupMessage{
|
deleteOpts := rds.DeleteDBParameterGroupInput{
|
||||||
DBParameterGroupName: aws.String(d.Id()),
|
DBParameterGroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
|
if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
|
||||||
rdserr, ok := err.(aws.APIError)
|
rdserr, ok := err.(aws.APIError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return d, "error", err
|
return d, "error", err
|
||||||
|
|
|
@ -4,8 +4,8 @@ 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/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -115,7 +115,7 @@ func testAccCheckAWSDBParameterGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
// Try to find the Group
|
// Try to find the Group
|
||||||
resp, err := conn.DescribeDBParameterGroups(
|
resp, err := conn.DescribeDBParameterGroups(
|
||||||
&rds.DescribeDBParameterGroupsMessage{
|
&rds.DescribeDBParameterGroupsInput{
|
||||||
DBParameterGroupName: aws.String(rs.Primary.ID),
|
DBParameterGroupName: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ func testAccCheckAWSDBParameterGroupExists(n string, v *rds.DBParameterGroup) re
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
||||||
|
|
||||||
opts := rds.DescribeDBParameterGroupsMessage{
|
opts := rds.DescribeDBParameterGroupsInput{
|
||||||
DBParameterGroupName: aws.String(rs.Primary.ID),
|
DBParameterGroupName: aws.String(rs.Primary.ID),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ func testAccCheckAWSDBParameterGroupExists(n string, v *rds.DBParameterGroup) re
|
||||||
return fmt.Errorf("DB Parameter Group not found")
|
return fmt.Errorf("DB Parameter Group not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = resp.DBParameterGroups[0]
|
*v = *resp.DBParameterGroups[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/multierror"
|
"github.com/hashicorp/terraform/helper/multierror"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
@ -75,7 +75,7 @@ func resourceAwsDbSecurityGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
var err error
|
var err error
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|
||||||
opts := rds.CreateDBSecurityGroupMessage{
|
opts := rds.CreateDBSecurityGroupInput{
|
||||||
DBSecurityGroupName: aws.String(d.Get("name").(string)),
|
DBSecurityGroupName: aws.String(d.Get("name").(string)),
|
||||||
DBSecurityGroupDescription: aws.String(d.Get("description").(string)),
|
DBSecurityGroupDescription: aws.String(d.Get("description").(string)),
|
||||||
}
|
}
|
||||||
|
@ -164,10 +164,10 @@ func resourceAwsDbSecurityGroupDelete(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
log.Printf("[DEBUG] DB Security Group destroy: %v", d.Id())
|
log.Printf("[DEBUG] DB Security Group destroy: %v", d.Id())
|
||||||
|
|
||||||
opts := rds.DeleteDBSecurityGroupMessage{DBSecurityGroupName: aws.String(d.Id())}
|
opts := rds.DeleteDBSecurityGroupInput{DBSecurityGroupName: aws.String(d.Id())}
|
||||||
|
|
||||||
log.Printf("[DEBUG] DB Security Group destroy configuration: %v", opts)
|
log.Printf("[DEBUG] DB Security Group destroy configuration: %v", opts)
|
||||||
err := conn.DeleteDBSecurityGroup(&opts)
|
_, err := conn.DeleteDBSecurityGroup(&opts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
newerr, ok := err.(aws.APIError)
|
newerr, ok := err.(aws.APIError)
|
||||||
|
@ -183,7 +183,7 @@ func resourceAwsDbSecurityGroupDelete(d *schema.ResourceData, meta interface{})
|
||||||
func resourceAwsDbSecurityGroupRetrieve(d *schema.ResourceData, meta interface{}) (*rds.DBSecurityGroup, error) {
|
func resourceAwsDbSecurityGroupRetrieve(d *schema.ResourceData, meta interface{}) (*rds.DBSecurityGroup, error) {
|
||||||
conn := meta.(*AWSClient).rdsconn
|
conn := meta.(*AWSClient).rdsconn
|
||||||
|
|
||||||
opts := rds.DescribeDBSecurityGroupsMessage{
|
opts := rds.DescribeDBSecurityGroupsInput{
|
||||||
DBSecurityGroupName: aws.String(d.Id()),
|
DBSecurityGroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,16 +200,14 @@ func resourceAwsDbSecurityGroupRetrieve(d *schema.ResourceData, meta interface{}
|
||||||
return nil, fmt.Errorf("Unable to find DB Security Group: %#v", resp.DBSecurityGroups)
|
return nil, fmt.Errorf("Unable to find DB Security Group: %#v", resp.DBSecurityGroups)
|
||||||
}
|
}
|
||||||
|
|
||||||
v := resp.DBSecurityGroups[0]
|
return resp.DBSecurityGroups[0], nil
|
||||||
|
|
||||||
return &v, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authorizes the ingress rule on the db security group
|
// Authorizes the ingress rule on the db security group
|
||||||
func resourceAwsDbSecurityGroupAuthorizeRule(ingress interface{}, dbSecurityGroupName string, conn *rds.RDS) error {
|
func resourceAwsDbSecurityGroupAuthorizeRule(ingress interface{}, dbSecurityGroupName string, conn *rds.RDS) error {
|
||||||
ing := ingress.(map[string]interface{})
|
ing := ingress.(map[string]interface{})
|
||||||
|
|
||||||
opts := rds.AuthorizeDBSecurityGroupIngressMessage{
|
opts := rds.AuthorizeDBSecurityGroupIngressInput{
|
||||||
DBSecurityGroupName: aws.String(dbSecurityGroupName),
|
DBSecurityGroupName: aws.String(dbSecurityGroupName),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ 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/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -47,7 +47,7 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
// Try to find the Group
|
// Try to find the Group
|
||||||
resp, err := conn.DescribeDBSecurityGroups(
|
resp, err := conn.DescribeDBSecurityGroups(
|
||||||
&rds.DescribeDBSecurityGroupsMessage{
|
&rds.DescribeDBSecurityGroupsInput{
|
||||||
DBSecurityGroupName: aws.String(rs.Primary.ID),
|
DBSecurityGroupName: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
||||||
|
|
||||||
opts := rds.DescribeDBSecurityGroupsMessage{
|
opts := rds.DescribeDBSecurityGroupsInput{
|
||||||
DBSecurityGroupName: aws.String(rs.Primary.ID),
|
DBSecurityGroupName: aws.String(rs.Primary.ID),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +130,17 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
|
||||||
return fmt.Errorf("DB Security Group not found")
|
return fmt.Errorf("DB Security Group not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = resp.DBSecurityGroups[0]
|
*v = *resp.DBSecurityGroups[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccAWSDBSecurityGroupConfig = `
|
const testAccAWSDBSecurityGroupConfig = `
|
||||||
|
provider "aws" {
|
||||||
|
region = "us-east-1"
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_db_security_group" "bar" {
|
resource "aws_db_security_group" "bar" {
|
||||||
name = "secgroup-terraform"
|
name = "secgroup-terraform"
|
||||||
description = "just cuz"
|
description = "just cuz"
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"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/helper/schema"
|
||||||
|
@ -49,12 +49,12 @@ func resourceAwsDbSubnetGroupCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
rdsconn := meta.(*AWSClient).rdsconn
|
rdsconn := meta.(*AWSClient).rdsconn
|
||||||
|
|
||||||
subnetIdsSet := d.Get("subnet_ids").(*schema.Set)
|
subnetIdsSet := d.Get("subnet_ids").(*schema.Set)
|
||||||
subnetIds := make([]string, subnetIdsSet.Len())
|
subnetIds := make([]*string, subnetIdsSet.Len())
|
||||||
for i, subnetId := range subnetIdsSet.List() {
|
for i, subnetId := range subnetIdsSet.List() {
|
||||||
subnetIds[i] = subnetId.(string)
|
subnetIds[i] = aws.String(subnetId.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
createOpts := rds.CreateDBSubnetGroupMessage{
|
createOpts := rds.CreateDBSubnetGroupInput{
|
||||||
DBSubnetGroupName: aws.String(d.Get("name").(string)),
|
DBSubnetGroupName: aws.String(d.Get("name").(string)),
|
||||||
DBSubnetGroupDescription: aws.String(d.Get("description").(string)),
|
DBSubnetGroupDescription: aws.String(d.Get("description").(string)),
|
||||||
SubnetIDs: subnetIds,
|
SubnetIDs: subnetIds,
|
||||||
|
@ -74,7 +74,7 @@ func resourceAwsDbSubnetGroupCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
rdsconn := meta.(*AWSClient).rdsconn
|
rdsconn := meta.(*AWSClient).rdsconn
|
||||||
|
|
||||||
describeOpts := rds.DescribeDBSubnetGroupsMessage{
|
describeOpts := rds.DescribeDBSubnetGroupsInput{
|
||||||
DBSubnetGroupName: aws.String(d.Id()),
|
DBSubnetGroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
|
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
|
||||||
}
|
}
|
||||||
|
|
||||||
var subnetGroup rds.DBSubnetGroup
|
var subnetGroup *rds.DBSubnetGroup
|
||||||
for _, s := range describeResp.DBSubnetGroups {
|
for _, s := range describeResp.DBSubnetGroups {
|
||||||
// AWS is down casing the name provided, so we compare lower case versions
|
// AWS is down casing the name provided, so we compare lower case versions
|
||||||
// of the names. We lower case both our name and their name in the check,
|
// of the names. We lower case both our name and their name in the check,
|
||||||
|
@ -137,11 +137,11 @@ func resourceAwsDbSubnetGroupDeleteRefreshFunc(
|
||||||
|
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
|
|
||||||
deleteOpts := rds.DeleteDBSubnetGroupMessage{
|
deleteOpts := rds.DeleteDBSubnetGroupInput{
|
||||||
DBSubnetGroupName: aws.String(d.Id()),
|
DBSubnetGroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil {
|
if _, err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil {
|
||||||
rdserr, ok := err.(aws.APIError)
|
rdserr, ok := err.(aws.APIError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return d, "error", err
|
return d, "error", err
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSDBSubnetGroup(t *testing.T) {
|
func TestAccAWSDBSubnetGroup(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
// Try to find the resource
|
// Try to find the resource
|
||||||
resp, err := conn.DescribeDBSubnetGroups(
|
resp, err := conn.DescribeDBSubnetGroups(
|
||||||
&rds.DescribeDBSubnetGroupsMessage{DBSubnetGroupName: aws.String(rs.Primary.ID)})
|
&rds.DescribeDBSubnetGroupsInput{DBSubnetGroupName: aws.String(rs.Primary.ID)})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(resp.DBSubnetGroups) > 0 {
|
if len(resp.DBSubnetGroups) > 0 {
|
||||||
return fmt.Errorf("still exist.")
|
return fmt.Errorf("still exist.")
|
||||||
|
@ -80,7 +80,7 @@ func testAccCheckDBSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.Te
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
||||||
resp, err := conn.DescribeDBSubnetGroups(
|
resp, err := conn.DescribeDBSubnetGroups(
|
||||||
&rds.DescribeDBSubnetGroupsMessage{DBSubnetGroupName: aws.String(rs.Primary.ID)})
|
&rds.DescribeDBSubnetGroupsInput{DBSubnetGroupName: aws.String(rs.Primary.ID)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func testAccCheckDBSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.Te
|
||||||
return fmt.Errorf("DbSubnetGroup not found")
|
return fmt.Errorf("DbSubnetGroup not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = resp.DBSubnetGroups[0]
|
*v = *resp.DBSubnetGroups[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -163,7 +163,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 aws-sdk-go 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
|
||||||
|
@ -171,7 +171,7 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
tags := tagsFromMapELB(d.Get("tags").(map[string]interface{}))
|
tags := tagsFromMapELB(d.Get("tags").(map[string]interface{}))
|
||||||
// Provision the elb
|
// Provision the elb
|
||||||
elbOpts := &elb.CreateAccessPointInput{
|
elbOpts := &elb.CreateLoadBalancerInput{
|
||||||
LoadBalancerName: aws.String(d.Get("name").(string)),
|
LoadBalancerName: aws.String(d.Get("name").(string)),
|
||||||
Listeners: listeners,
|
Listeners: listeners,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
|
@ -221,11 +221,11 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
|
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
|
||||||
LoadBalancerName: aws.String(d.Id()),
|
LoadBalancerName: aws.String(d.Id()),
|
||||||
HealthCheck: &elb.HealthCheck{
|
HealthCheck: &elb.HealthCheck{
|
||||||
HealthyThreshold: aws.Integer(check["healthy_threshold"].(int)),
|
HealthyThreshold: aws.Long(int64(check["healthy_threshold"].(int))),
|
||||||
UnhealthyThreshold: aws.Integer(check["unhealthy_threshold"].(int)),
|
UnhealthyThreshold: aws.Long(int64(check["unhealthy_threshold"].(int))),
|
||||||
Interval: aws.Integer(check["interval"].(int)),
|
Interval: aws.Long(int64(check["interval"].(int))),
|
||||||
Target: aws.String(check["target"].(string)),
|
Target: aws.String(check["target"].(string)),
|
||||||
Timeout: aws.Integer(check["timeout"].(int)),
|
Timeout: aws.Long(int64(check["timeout"].(int))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,8 +243,8 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
elbconn := meta.(*AWSClient).elbconn
|
elbconn := meta.(*AWSClient).elbconn
|
||||||
|
|
||||||
// Retrieve the ELB properties for updating the state
|
// Retrieve the ELB properties for updating the state
|
||||||
describeElbOpts := &elb.DescribeAccessPointsInput{
|
describeElbOpts := &elb.DescribeLoadBalancersInput{
|
||||||
LoadBalancerNames: []string{d.Id()},
|
LoadBalancerNames: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
|
|
||||||
describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts)
|
describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts)
|
||||||
|
@ -273,10 +273,10 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("subnets", lb.Subnets)
|
d.Set("subnets", lb.Subnets)
|
||||||
|
|
||||||
resp, err := elbconn.DescribeTags(&elb.DescribeTagsInput{
|
resp, err := elbconn.DescribeTags(&elb.DescribeTagsInput{
|
||||||
LoadBalancerNames: []string{*lb.LoadBalancerName},
|
LoadBalancerNames: []*string{lb.LoadBalancerName},
|
||||||
})
|
})
|
||||||
|
|
||||||
var et []elb.Tag
|
var et []*elb.Tag
|
||||||
if len(resp.TagDescriptions) > 0 {
|
if len(resp.TagDescriptions) > 0 {
|
||||||
et = resp.TagDescriptions[0].Tags
|
et = resp.TagDescriptions[0].Tags
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
add := expandInstanceString(ns.Difference(os).List())
|
add := expandInstanceString(ns.Difference(os).List())
|
||||||
|
|
||||||
if len(add) > 0 {
|
if len(add) > 0 {
|
||||||
registerInstancesOpts := elb.RegisterEndPointsInput{
|
registerInstancesOpts := elb.RegisterInstancesWithLoadBalancerInput{
|
||||||
LoadBalancerName: aws.String(d.Id()),
|
LoadBalancerName: aws.String(d.Id()),
|
||||||
Instances: add,
|
Instances: add,
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(remove) > 0 {
|
if len(remove) > 0 {
|
||||||
deRegisterInstancesOpts := elb.DeregisterEndPointsInput{
|
deRegisterInstancesOpts := elb.DeregisterInstancesFromLoadBalancerInput{
|
||||||
LoadBalancerName: aws.String(d.Id()),
|
LoadBalancerName: aws.String(d.Id()),
|
||||||
Instances: remove,
|
Instances: remove,
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
LoadBalancerName: aws.String(d.Get("name").(string)),
|
LoadBalancerName: aws.String(d.Get("name").(string)),
|
||||||
LoadBalancerAttributes: &elb.LoadBalancerAttributes{
|
LoadBalancerAttributes: &elb.LoadBalancerAttributes{
|
||||||
CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{
|
CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{
|
||||||
aws.Boolean(d.Get("cross_zone_load_balancing").(bool)),
|
Enabled: aws.Boolean(d.Get("cross_zone_load_balancing").(bool)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -356,11 +356,11 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
|
configureHealthCheckOpts := elb.ConfigureHealthCheckInput{
|
||||||
LoadBalancerName: aws.String(d.Id()),
|
LoadBalancerName: aws.String(d.Id()),
|
||||||
HealthCheck: &elb.HealthCheck{
|
HealthCheck: &elb.HealthCheck{
|
||||||
HealthyThreshold: aws.Integer(check["healthy_threshold"].(int)),
|
HealthyThreshold: aws.Long(int64(check["healthy_threshold"].(int))),
|
||||||
UnhealthyThreshold: aws.Integer(check["unhealthy_threshold"].(int)),
|
UnhealthyThreshold: aws.Long(int64(check["unhealthy_threshold"].(int))),
|
||||||
Interval: aws.Integer(check["interval"].(int)),
|
Interval: aws.Long(int64(check["interval"].(int))),
|
||||||
Target: aws.String(check["target"].(string)),
|
Target: aws.String(check["target"].(string)),
|
||||||
Timeout: aws.Integer(check["timeout"].(int)),
|
Timeout: aws.Long(int64(check["timeout"].(int))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := elbconn.ConfigureHealthCheck(&configureHealthCheckOpts)
|
_, err := elbconn.ConfigureHealthCheck(&configureHealthCheckOpts)
|
||||||
|
@ -387,7 +387,7 @@ func resourceAwsElbDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
log.Printf("[INFO] Deleting ELB: %s", d.Id())
|
log.Printf("[INFO] Deleting ELB: %s", d.Id())
|
||||||
|
|
||||||
// Destroy the load balancer
|
// Destroy the load balancer
|
||||||
deleteElbOpts := elb.DeleteAccessPointInput{
|
deleteElbOpts := elb.DeleteLoadBalancerInput{
|
||||||
LoadBalancerName: aws.String(d.Id()),
|
LoadBalancerName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
if _, err := elbconn.DeleteLoadBalancer(&deleteElbOpts); err != nil {
|
if _, err := elbconn.DeleteLoadBalancer(&deleteElbOpts); err != nil {
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -95,14 +95,14 @@ func testAccLoadTags(conf *elb.LoadBalancerDescription, td *elb.TagDescription)
|
||||||
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
||||||
|
|
||||||
describe, err := conn.DescribeTags(&elb.DescribeTagsInput{
|
describe, err := conn.DescribeTags(&elb.DescribeTagsInput{
|
||||||
LoadBalancerNames: []string{*conf.LoadBalancerName},
|
LoadBalancerNames: []*string{conf.LoadBalancerName},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(describe.TagDescriptions) > 0 {
|
if len(describe.TagDescriptions) > 0 {
|
||||||
*td = describe.TagDescriptions[0]
|
*td = *describe.TagDescriptions[0]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -205,8 +205,8 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
describe, err := conn.DescribeLoadBalancers(&elb.DescribeAccessPointsInput{
|
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
|
||||||
LoadBalancerNames: []string{rs.Primary.ID},
|
LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -233,8 +233,12 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {
|
||||||
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
||||||
sort.StringSlice(conf.AvailabilityZones).Sort()
|
azs := make([]string, 0, len(conf.AvailabilityZones))
|
||||||
if !reflect.DeepEqual(conf.AvailabilityZones, zones) {
|
for _, x := range conf.AvailabilityZones {
|
||||||
|
azs = append(azs, *x)
|
||||||
|
}
|
||||||
|
sort.StringSlice(azs).Sort()
|
||||||
|
if !reflect.DeepEqual(azs, zones) {
|
||||||
return fmt.Errorf("bad availability_zones")
|
return fmt.Errorf("bad availability_zones")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,9 +247,9 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te
|
||||||
}
|
}
|
||||||
|
|
||||||
l := elb.Listener{
|
l := elb.Listener{
|
||||||
InstancePort: aws.Integer(8000),
|
InstancePort: aws.Long(int64(8000)),
|
||||||
InstanceProtocol: aws.String("HTTP"),
|
InstanceProtocol: aws.String("HTTP"),
|
||||||
LoadBalancerPort: aws.Integer(80),
|
LoadBalancerPort: aws.Long(int64(80)),
|
||||||
Protocol: aws.String("HTTP"),
|
Protocol: aws.String("HTTP"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +271,12 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te
|
||||||
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
|
||||||
sort.StringSlice(conf.AvailabilityZones).Sort()
|
azs := make([]string, 0, len(conf.AvailabilityZones))
|
||||||
if !reflect.DeepEqual(conf.AvailabilityZones, zones) {
|
for _, x := range conf.AvailabilityZones {
|
||||||
|
azs = append(azs, *x)
|
||||||
|
}
|
||||||
|
sort.StringSlice(azs).Sort()
|
||||||
|
if !reflect.DeepEqual(azs, zones) {
|
||||||
return fmt.Errorf("bad availability_zones")
|
return fmt.Errorf("bad availability_zones")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,15 +284,15 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription)
|
||||||
return fmt.Errorf("bad name")
|
return fmt.Errorf("bad name")
|
||||||
}
|
}
|
||||||
|
|
||||||
check := elb.HealthCheck{
|
check := &elb.HealthCheck{
|
||||||
Timeout: aws.Integer(30),
|
Timeout: aws.Long(int64(30)),
|
||||||
UnhealthyThreshold: aws.Integer(5),
|
UnhealthyThreshold: aws.Long(int64(5)),
|
||||||
HealthyThreshold: aws.Integer(5),
|
HealthyThreshold: aws.Long(int64(5)),
|
||||||
Interval: aws.Integer(60),
|
Interval: aws.Long(int64(60)),
|
||||||
Target: aws.String("HTTP:8000/"),
|
Target: aws.String("HTTP:8000/"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(conf.HealthCheck, &check) {
|
if !reflect.DeepEqual(conf.HealthCheck, check) {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||||
conf.HealthCheck,
|
conf.HealthCheck,
|
||||||
|
@ -312,8 +320,8 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resour
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
conn := testAccProvider.Meta().(*AWSClient).elbconn
|
||||||
|
|
||||||
describe, err := conn.DescribeLoadBalancers(&elb.DescribeAccessPointsInput{
|
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
|
||||||
LoadBalancerNames: []string{rs.Primary.ID},
|
LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -325,7 +333,7 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resour
|
||||||
return fmt.Errorf("ELB not found")
|
return fmt.Errorf("ELB not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*res = describe.LoadBalancerDescriptions[0]
|
*res = *describe.LoadBalancerDescriptions[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/hashcode"
|
"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/helper/schema"
|
||||||
|
@ -105,6 +105,16 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"vpc_security_group_ids": &schema.Schema{
|
||||||
|
Type: schema.TypeSet,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
Set: func(v interface{}) int {
|
||||||
|
return hashcode.String(v.(string))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
"public_dns": &schema.Schema{
|
"public_dns": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
@ -289,7 +299,7 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Figure out user data
|
// Figure out user data
|
||||||
userData := ""
|
userData := ""
|
||||||
|
@ -319,12 +329,12 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the creation struct
|
// Build the creation struct
|
||||||
runOpts := &ec2.RunInstancesRequest{
|
runOpts := &ec2.RunInstancesInput{
|
||||||
ImageID: aws.String(d.Get("ami").(string)),
|
ImageID: aws.String(d.Get("ami").(string)),
|
||||||
Placement: placement,
|
Placement: placement,
|
||||||
InstanceType: aws.String(d.Get("instance_type").(string)),
|
InstanceType: aws.String(d.Get("instance_type").(string)),
|
||||||
MaxCount: aws.Integer(1),
|
MaxCount: aws.Long(int64(1)),
|
||||||
MinCount: aws.Integer(1),
|
MinCount: aws.Long(int64(1)),
|
||||||
UserData: aws.String(userData),
|
UserData: aws.String(userData),
|
||||||
EBSOptimized: aws.Boolean(d.Get("ebs_optimized").(bool)),
|
EBSOptimized: aws.Boolean(d.Get("ebs_optimized").(bool)),
|
||||||
IAMInstanceProfile: iam,
|
IAMInstanceProfile: iam,
|
||||||
|
@ -335,14 +345,17 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
associatePublicIPAddress = v.(bool)
|
associatePublicIPAddress = v.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var groups []string
|
var groups []*string
|
||||||
if v := d.Get("security_groups"); v != nil {
|
if v := d.Get("security_groups"); v != nil {
|
||||||
// Security group names.
|
// Security group names.
|
||||||
// For a nondefault VPC, you must use security group IDs instead.
|
// For a nondefault VPC, you must use security group IDs instead.
|
||||||
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html
|
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html
|
||||||
|
if hasSubnet {
|
||||||
|
log.Printf("[WARN] Deprecated. Attempting to use 'security_groups' within a VPC instance. Use 'vpc_security_group_ids' instead.")
|
||||||
|
}
|
||||||
for _, v := range v.(*schema.Set).List() {
|
for _, v := range v.(*schema.Set).List() {
|
||||||
str := v.(string)
|
str := v.(string)
|
||||||
groups = append(groups, str)
|
groups = append(groups, aws.String(str))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,9 +367,9 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// You also need to attach Security Groups to the NetworkInterface instead of the instance,
|
// You also need to attach Security Groups to the NetworkInterface instead of the instance,
|
||||||
// to avoid: Network interfaces and an instance-level security groups may not be specified on
|
// to avoid: Network interfaces and an instance-level security groups may not be specified on
|
||||||
// the same request
|
// the same request
|
||||||
ni := ec2.InstanceNetworkInterfaceSpecification{
|
ni := &ec2.InstanceNetworkInterfaceSpecification{
|
||||||
AssociatePublicIPAddress: aws.Boolean(associatePublicIPAddress),
|
AssociatePublicIPAddress: aws.Boolean(associatePublicIPAddress),
|
||||||
DeviceIndex: aws.Integer(0),
|
DeviceIndex: aws.Long(int64(0)),
|
||||||
SubnetID: aws.String(subnetID),
|
SubnetID: aws.String(subnetID),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,11 +377,13 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ni.PrivateIPAddress = aws.String(v.(string))
|
ni.PrivateIPAddress = aws.String(v.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(groups) > 0 {
|
if v := d.Get("vpc_security_group_ids"); v != nil {
|
||||||
ni.Groups = groups
|
for _, v := range v.(*schema.Set).List() {
|
||||||
|
ni.Groups = append(ni.Groups, aws.String(v.(string)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runOpts.NetworkInterfaces = []ec2.InstanceNetworkInterfaceSpecification{ni}
|
runOpts.NetworkInterfaces = []*ec2.InstanceNetworkInterfaceSpecification{ni}
|
||||||
} else {
|
} else {
|
||||||
if subnetID != "" {
|
if subnetID != "" {
|
||||||
runOpts.SubnetID = aws.String(subnetID)
|
runOpts.SubnetID = aws.String(subnetID)
|
||||||
|
@ -383,13 +398,19 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
} else {
|
} else {
|
||||||
runOpts.SecurityGroups = groups
|
runOpts.SecurityGroups = groups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v := d.Get("vpc_security_group_ids"); v != nil {
|
||||||
|
for _, v := range v.(*schema.Set).List() {
|
||||||
|
runOpts.SecurityGroupIDs = append(runOpts.SecurityGroupIDs, aws.String(v.(string)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("key_name"); ok {
|
if v, ok := d.GetOk("key_name"); ok {
|
||||||
runOpts.KeyName = aws.String(v.(string))
|
runOpts.KeyName = aws.String(v.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDevices := make([]ec2.BlockDeviceMapping, 0)
|
blockDevices := make([]*ec2.BlockDeviceMapping, 0)
|
||||||
|
|
||||||
if v, ok := d.GetOk("ebs_block_device"); ok {
|
if v, ok := d.GetOk("ebs_block_device"); ok {
|
||||||
vL := v.(*schema.Set).List()
|
vL := v.(*schema.Set).List()
|
||||||
|
@ -404,7 +425,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
||||||
ebs.VolumeSize = aws.Integer(v)
|
ebs.VolumeSize = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
||||||
|
@ -412,10 +433,10 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["iops"].(int); ok && v > 0 {
|
if v, ok := bd["iops"].(int); ok && v > 0 {
|
||||||
ebs.IOPS = aws.Integer(v)
|
ebs.IOPS = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDevices = append(blockDevices, ec2.BlockDeviceMapping{
|
blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
|
||||||
DeviceName: aws.String(bd["device_name"].(string)),
|
DeviceName: aws.String(bd["device_name"].(string)),
|
||||||
EBS: ebs,
|
EBS: ebs,
|
||||||
})
|
})
|
||||||
|
@ -426,7 +447,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
vL := v.(*schema.Set).List()
|
vL := v.(*schema.Set).List()
|
||||||
for _, v := range vL {
|
for _, v := range vL {
|
||||||
bd := v.(map[string]interface{})
|
bd := v.(map[string]interface{})
|
||||||
blockDevices = append(blockDevices, ec2.BlockDeviceMapping{
|
blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
|
||||||
DeviceName: aws.String(bd["device_name"].(string)),
|
DeviceName: aws.String(bd["device_name"].(string)),
|
||||||
VirtualName: aws.String(bd["virtual_name"].(string)),
|
VirtualName: aws.String(bd["virtual_name"].(string)),
|
||||||
})
|
})
|
||||||
|
@ -445,7 +466,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
||||||
ebs.VolumeSize = aws.Integer(v)
|
ebs.VolumeSize = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
||||||
|
@ -453,11 +474,11 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["iops"].(int); ok && v > 0 {
|
if v, ok := bd["iops"].(int); ok && v > 0 {
|
||||||
ebs.IOPS = aws.Integer(v)
|
ebs.IOPS = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if dn, err := fetchRootDeviceName(d.Get("ami").(string), ec2conn); err == nil {
|
if dn, err := fetchRootDeviceName(d.Get("ami").(string), conn); err == nil {
|
||||||
blockDevices = append(blockDevices, ec2.BlockDeviceMapping{
|
blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
|
||||||
DeviceName: dn,
|
DeviceName: dn,
|
||||||
EBS: ebs,
|
EBS: ebs,
|
||||||
})
|
})
|
||||||
|
@ -473,12 +494,12 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
// Create the instance
|
// Create the instance
|
||||||
log.Printf("[DEBUG] Run configuration: %#v", runOpts)
|
log.Printf("[DEBUG] Run configuration: %#v", runOpts)
|
||||||
runResp, err := ec2conn.RunInstances(runOpts)
|
runResp, err := conn.RunInstances(runOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error launching source instance: %s", err)
|
return fmt.Errorf("Error launching source instance: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := &runResp.Instances[0]
|
instance := runResp.Instances[0]
|
||||||
log.Printf("[INFO] Instance ID: %s", *instance.InstanceID)
|
log.Printf("[INFO] Instance ID: %s", *instance.InstanceID)
|
||||||
|
|
||||||
// Store the resulting ID so we can look this up later
|
// Store the resulting ID so we can look this up later
|
||||||
|
@ -493,7 +514,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"pending"},
|
Pending: []string{"pending"},
|
||||||
Target: "running",
|
Target: "running",
|
||||||
Refresh: InstanceStateRefreshFunc(ec2conn, *instance.InstanceID),
|
Refresh: InstanceStateRefreshFunc(conn, *instance.InstanceID),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: 10 * time.Minute,
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
|
@ -526,10 +547,10 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
resp, err := ec2conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||||
InstanceIDs: []string{d.Id()},
|
InstanceIDs: []*string{aws.String(d.Id())},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the instance was not found, return nil so that we can show
|
// If the instance was not found, return nil so that we can show
|
||||||
|
@ -549,7 +570,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := &resp.Reservations[0].Instances[0]
|
instance := resp.Reservations[0].Instances[0]
|
||||||
|
|
||||||
// If the instance is terminated, then it is gone
|
// If the instance is terminated, then it is gone
|
||||||
if *instance.State.Name == "terminated" {
|
if *instance.State.Name == "terminated" {
|
||||||
|
@ -575,7 +596,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", tagsToMap(instance.Tags))
|
d.Set("tags", tagsToMapSDK(instance.Tags))
|
||||||
|
|
||||||
// Determine whether we're referring to security groups with
|
// Determine whether we're referring to security groups with
|
||||||
// IDs or names. We use a heuristic to figure this out. By default,
|
// IDs or names. We use a heuristic to figure this out. By default,
|
||||||
|
@ -596,17 +617,26 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build up the security groups
|
// Build up the security groups
|
||||||
sgs := make([]string, len(instance.SecurityGroups))
|
sgs := make([]string, 0, len(instance.SecurityGroups))
|
||||||
for i, sg := range instance.SecurityGroups {
|
if useID {
|
||||||
if useID {
|
for _, sg := range instance.SecurityGroups {
|
||||||
sgs[i] = *sg.GroupID
|
sgs = append(sgs, *sg.GroupID)
|
||||||
} else {
|
}
|
||||||
sgs[i] = *sg.GroupName
|
log.Printf("[DEBUG] Setting Security Group IDs: %#v", sgs)
|
||||||
|
if err := d.Set("vpc_security_group_ids", sgs); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, sg := range instance.SecurityGroups {
|
||||||
|
sgs = append(sgs, *sg.GroupName)
|
||||||
|
}
|
||||||
|
log.Printf("[DEBUG] Setting Security Group Names: %#v", sgs)
|
||||||
|
if err := d.Set("security_groups", sgs); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.Set("security_groups", sgs)
|
|
||||||
|
|
||||||
if err := readBlockDevices(d, instance, ec2conn); err != nil {
|
if err := readBlockDevices(d, instance, conn); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,12 +644,14 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
d.Partial(true)
|
||||||
|
|
||||||
// SourceDestCheck can only be set on VPC instances
|
// SourceDestCheck can only be set on VPC instances
|
||||||
if d.Get("subnet_id").(string) != "" {
|
if d.Get("subnet_id").(string) != "" {
|
||||||
log.Printf("[INFO] Modifying instance %s", d.Id())
|
log.Printf("[INFO] Modifying instance %s", d.Id())
|
||||||
err := ec2conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeRequest{
|
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
||||||
InstanceID: aws.String(d.Id()),
|
InstanceID: aws.String(d.Id()),
|
||||||
SourceDestCheck: &ec2.AttributeBooleanValue{
|
SourceDestCheck: &ec2.AttributeBooleanValue{
|
||||||
Value: aws.Boolean(d.Get("source_dest_check").(bool)),
|
Value: aws.Boolean(d.Get("source_dest_check").(bool)),
|
||||||
|
@ -633,23 +665,24 @@ 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 := setTags(ec2conn, d); err != nil {
|
if err := setTagsSDK(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
}
|
}
|
||||||
|
d.Partial(false)
|
||||||
|
|
||||||
return nil
|
return resourceAwsInstanceRead(d, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf("[INFO] Terminating instance: %s", d.Id())
|
log.Printf("[INFO] Terminating instance: %s", d.Id())
|
||||||
req := &ec2.TerminateInstancesRequest{
|
req := &ec2.TerminateInstancesInput{
|
||||||
InstanceIDs: []string{d.Id()},
|
InstanceIDs: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
if _, err := ec2conn.TerminateInstances(req); err != nil {
|
if _, err := conn.TerminateInstances(req); err != nil {
|
||||||
return fmt.Errorf("Error terminating instance: %s", err)
|
return fmt.Errorf("Error terminating instance: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,7 +693,7 @@ func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
||||||
Target: "terminated",
|
Target: "terminated",
|
||||||
Refresh: InstanceStateRefreshFunc(ec2conn, d.Id()),
|
Refresh: InstanceStateRefreshFunc(conn, d.Id()),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: 10 * time.Minute,
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
|
@ -681,8 +714,8 @@ func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
// an EC2 instance.
|
// an EC2 instance.
|
||||||
func InstanceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRefreshFunc {
|
func InstanceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRefreshFunc {
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||||
InstanceIDs: []string{instanceID},
|
InstanceIDs: []*string{aws.String(instanceID)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidInstanceID.NotFound" {
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidInstanceID.NotFound" {
|
||||||
|
@ -700,13 +733,13 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRe
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
i := &resp.Reservations[0].Instances[0]
|
i := resp.Reservations[0].Instances[0]
|
||||||
return i, *i.State.Name, nil
|
return i, *i.State.Name, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readBlockDevices(d *schema.ResourceData, instance *ec2.Instance, ec2conn *ec2.EC2) error {
|
func readBlockDevices(d *schema.ResourceData, instance *ec2.Instance, conn *ec2.EC2) error {
|
||||||
ibds, err := readBlockDevicesFromInstance(instance, ec2conn)
|
ibds, err := readBlockDevicesFromInstance(instance, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -723,12 +756,12 @@ func readBlockDevices(d *schema.ResourceData, instance *ec2.Instance, ec2conn *e
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readBlockDevicesFromInstance(instance *ec2.Instance, ec2conn *ec2.EC2) (map[string]interface{}, error) {
|
func readBlockDevicesFromInstance(instance *ec2.Instance, conn *ec2.EC2) (map[string]interface{}, error) {
|
||||||
blockDevices := make(map[string]interface{})
|
blockDevices := make(map[string]interface{})
|
||||||
blockDevices["ebs"] = make([]map[string]interface{}, 0)
|
blockDevices["ebs"] = make([]map[string]interface{}, 0)
|
||||||
blockDevices["root"] = nil
|
blockDevices["root"] = nil
|
||||||
|
|
||||||
instanceBlockDevices := make(map[string]ec2.InstanceBlockDeviceMapping)
|
instanceBlockDevices := make(map[string]*ec2.InstanceBlockDeviceMapping)
|
||||||
for _, bd := range instance.BlockDeviceMappings {
|
for _, bd := range instance.BlockDeviceMappings {
|
||||||
if bd.EBS != nil {
|
if bd.EBS != nil {
|
||||||
instanceBlockDevices[*(bd.EBS.VolumeID)] = bd
|
instanceBlockDevices[*(bd.EBS.VolumeID)] = bd
|
||||||
|
@ -739,14 +772,14 @@ func readBlockDevicesFromInstance(instance *ec2.Instance, ec2conn *ec2.EC2) (map
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
volIDs := make([]string, 0, len(instanceBlockDevices))
|
volIDs := make([]*string, 0, len(instanceBlockDevices))
|
||||||
for volID := range instanceBlockDevices {
|
for volID := range instanceBlockDevices {
|
||||||
volIDs = append(volIDs, volID)
|
volIDs = append(volIDs, aws.String(volID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to call DescribeVolumes to get volume_size and volume_type for each
|
// Need to call DescribeVolumes to get volume_size and volume_type for each
|
||||||
// EBS block device
|
// EBS block device
|
||||||
volResp, err := ec2conn.DescribeVolumes(&ec2.DescribeVolumesRequest{
|
volResp, err := conn.DescribeVolumes(&ec2.DescribeVolumesInput{
|
||||||
VolumeIDs: volIDs,
|
VolumeIDs: volIDs,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -790,19 +823,19 @@ func readBlockDevicesFromInstance(instance *ec2.Instance, ec2conn *ec2.EC2) (map
|
||||||
return blockDevices, nil
|
return blockDevices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func blockDeviceIsRoot(bd ec2.InstanceBlockDeviceMapping, instance *ec2.Instance) bool {
|
func blockDeviceIsRoot(bd *ec2.InstanceBlockDeviceMapping, instance *ec2.Instance) bool {
|
||||||
return (bd.DeviceName != nil &&
|
return (bd.DeviceName != nil &&
|
||||||
instance.RootDeviceName != nil &&
|
instance.RootDeviceName != nil &&
|
||||||
*bd.DeviceName == *instance.RootDeviceName)
|
*bd.DeviceName == *instance.RootDeviceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchRootDeviceName(ami string, conn *ec2.EC2) (aws.StringValue, error) {
|
func fetchRootDeviceName(ami string, conn *ec2.EC2) (*string, error) {
|
||||||
if ami == "" {
|
if ami == "" {
|
||||||
return nil, fmt.Errorf("Cannot fetch root device name for blank AMI ID.")
|
return nil, fmt.Errorf("Cannot fetch root device name for blank AMI ID.")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Describing AMI %q to get root block device name", ami)
|
log.Printf("[DEBUG] Describing AMI %q to get root block device name", ami)
|
||||||
req := &ec2.DescribeImagesRequest{ImageIDs: []string{ami}}
|
req := &ec2.DescribeImagesInput{ImageIDs: []*string{aws.String(ami)}}
|
||||||
if res, err := conn.DescribeImages(req); err == nil {
|
if res, err := conn.DescribeImages(req); err == nil {
|
||||||
if len(res.Images) == 1 {
|
if len(res.Images) == 1 {
|
||||||
return res.Images[0].RootDeviceName, nil
|
return res.Images[0].RootDeviceName, nil
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"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/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
@ -43,9 +43,9 @@ func TestAccAWSInstance_normal(t *testing.T) {
|
||||||
Check: func(*terraform.State) error {
|
Check: func(*terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
var err error
|
var err error
|
||||||
vol, err = conn.CreateVolume(&ec2.CreateVolumeRequest{
|
vol, err = conn.CreateVolume(&ec2.CreateVolumeInput{
|
||||||
AvailabilityZone: aws.String("us-west-2a"),
|
AvailabilityZone: aws.String("us-west-2a"),
|
||||||
Size: aws.Integer(5),
|
Size: aws.Long(int64(5)),
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
@ -89,7 +89,8 @@ func TestAccAWSInstance_normal(t *testing.T) {
|
||||||
Config: testAccInstanceConfig,
|
Config: testAccInstanceConfig,
|
||||||
Check: func(*terraform.State) error {
|
Check: func(*terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
return conn.DeleteVolume(&ec2.DeleteVolumeRequest{VolumeID: vol.VolumeID})
|
_, err := conn.DeleteVolume(&ec2.DeleteVolumeInput{VolumeID: vol.VolumeID})
|
||||||
|
return err
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -103,7 +104,7 @@ func TestAccAWSInstance_blockDevices(t *testing.T) {
|
||||||
return func(*terraform.State) error {
|
return func(*terraform.State) error {
|
||||||
|
|
||||||
// Map out the block devices by name, which should be unique.
|
// Map out the block devices by name, which should be unique.
|
||||||
blockDevices := make(map[string]ec2.InstanceBlockDeviceMapping)
|
blockDevices := make(map[string]*ec2.InstanceBlockDeviceMapping)
|
||||||
for _, blockDevice := range v.BlockDeviceMappings {
|
for _, blockDevice := range v.BlockDeviceMappings {
|
||||||
blockDevices[*blockDevice.DeviceName] = blockDevice
|
blockDevices[*blockDevice.DeviceName] = blockDevice
|
||||||
}
|
}
|
||||||
|
@ -255,6 +256,25 @@ func TestAccAWSInstance_NetworkInstanceSecurityGroups(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs(t *testing.T) {
|
||||||
|
var v ec2.Instance
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccInstanceNetworkInstanceVPCSecurityGroupIDs,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckInstanceExists(
|
||||||
|
"aws_instance.foo_instance", &v),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAWSInstance_tags(t *testing.T) {
|
func TestAccAWSInstance_tags(t *testing.T) {
|
||||||
var v ec2.Instance
|
var v ec2.Instance
|
||||||
|
|
||||||
|
@ -267,9 +287,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),
|
||||||
testAccCheckTags(&v.Tags, "foo", "bar"),
|
testAccCheckTagsSDK(&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
|
||||||
testAccCheckTags(&v.Tags, "#", ""),
|
testAccCheckTagsSDK(&v.Tags, "#", ""),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -277,8 +297,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),
|
||||||
testAccCheckTags(&v.Tags, "foo", ""),
|
testAccCheckTagsSDK(&v.Tags, "foo", ""),
|
||||||
testAccCheckTags(&v.Tags, "bar", "baz"),
|
testAccCheckTagsSDK(&v.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -352,8 +372,8 @@ func testAccCheckInstanceDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the resource
|
// Try to find the resource
|
||||||
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||||
InstanceIDs: []string{rs.Primary.ID},
|
InstanceIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(resp.Reservations) > 0 {
|
if len(resp.Reservations) > 0 {
|
||||||
|
@ -388,8 +408,8 @@ func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFun
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesRequest{
|
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||||
InstanceIDs: []string{rs.Primary.ID},
|
InstanceIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -398,7 +418,7 @@ func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFun
|
||||||
return fmt.Errorf("Instance not found")
|
return fmt.Errorf("Instance not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*i = resp.Reservations[0].Instances[0]
|
*i = *resp.Reservations[0].Instances[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -645,3 +665,48 @@ resource "aws_eip" "foo_eip" {
|
||||||
depends_on = ["aws_internet_gateway.gw"]
|
depends_on = ["aws_internet_gateway.gw"]
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccInstanceNetworkInstanceVPCSecurityGroupIDs = `
|
||||||
|
resource "aws_internet_gateway" "gw" {
|
||||||
|
vpc_id = "${aws_vpc.foo.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_vpc" "foo" {
|
||||||
|
cidr_block = "10.1.0.0/16"
|
||||||
|
tags {
|
||||||
|
Name = "tf-network-test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_security_group" "tf_test_foo" {
|
||||||
|
name = "tf_test_foo"
|
||||||
|
description = "foo"
|
||||||
|
vpc_id="${aws_vpc.foo.id}"
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
protocol = "icmp"
|
||||||
|
from_port = -1
|
||||||
|
to_port = -1
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_subnet" "foo" {
|
||||||
|
cidr_block = "10.1.1.0/24"
|
||||||
|
vpc_id = "${aws_vpc.foo.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "foo_instance" {
|
||||||
|
ami = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
vpc_security_group_ids = ["${aws_security_group.tf_test_foo.id}"]
|
||||||
|
subnet_id = "${aws_subnet.foo.id}"
|
||||||
|
depends_on = ["aws_internet_gateway.gw"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_eip" "foo_eip" {
|
||||||
|
instance = "${aws_instance.foo_instance.id}"
|
||||||
|
vpc = true
|
||||||
|
depends_on = ["aws_internet_gateway.gw"]
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"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/helper/schema"
|
||||||
|
@ -245,7 +245,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
createLaunchConfigurationOpts := autoscaling.CreateLaunchConfigurationType{
|
createLaunchConfigurationOpts := autoscaling.CreateLaunchConfigurationInput{
|
||||||
LaunchConfigurationName: aws.String(d.Get("name").(string)),
|
LaunchConfigurationName: aws.String(d.Get("name").(string)),
|
||||||
ImageID: aws.String(d.Get("image_id").(string)),
|
ImageID: aws.String(d.Get("image_id").(string)),
|
||||||
InstanceType: aws.String(d.Get("instance_type").(string)),
|
InstanceType: aws.String(d.Get("instance_type").(string)),
|
||||||
|
@ -282,7 +282,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockDevices []autoscaling.BlockDeviceMapping
|
var blockDevices []*autoscaling.BlockDeviceMapping
|
||||||
|
|
||||||
if v, ok := d.GetOk("ebs_block_device"); ok {
|
if v, ok := d.GetOk("ebs_block_device"); ok {
|
||||||
vL := v.(*schema.Set).List()
|
vL := v.(*schema.Set).List()
|
||||||
|
@ -297,7 +297,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
||||||
ebs.VolumeSize = aws.Integer(v)
|
ebs.VolumeSize = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
||||||
|
@ -305,10 +305,10 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["iops"].(int); ok && v > 0 {
|
if v, ok := bd["iops"].(int); ok && v > 0 {
|
||||||
ebs.IOPS = aws.Integer(v)
|
ebs.IOPS = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDevices = append(blockDevices, autoscaling.BlockDeviceMapping{
|
blockDevices = append(blockDevices, &autoscaling.BlockDeviceMapping{
|
||||||
DeviceName: aws.String(bd["device_name"].(string)),
|
DeviceName: aws.String(bd["device_name"].(string)),
|
||||||
EBS: ebs,
|
EBS: ebs,
|
||||||
})
|
})
|
||||||
|
@ -319,7 +319,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
vL := v.(*schema.Set).List()
|
vL := v.(*schema.Set).List()
|
||||||
for _, v := range vL {
|
for _, v := range vL {
|
||||||
bd := v.(map[string]interface{})
|
bd := v.(map[string]interface{})
|
||||||
blockDevices = append(blockDevices, autoscaling.BlockDeviceMapping{
|
blockDevices = append(blockDevices, &autoscaling.BlockDeviceMapping{
|
||||||
DeviceName: aws.String(bd["device_name"].(string)),
|
DeviceName: aws.String(bd["device_name"].(string)),
|
||||||
VirtualName: aws.String(bd["virtual_name"].(string)),
|
VirtualName: aws.String(bd["virtual_name"].(string)),
|
||||||
})
|
})
|
||||||
|
@ -338,7 +338,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
if v, ok := bd["volume_size"].(int); ok && v != 0 {
|
||||||
ebs.VolumeSize = aws.Integer(v)
|
ebs.VolumeSize = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
if v, ok := bd["volume_type"].(string); ok && v != "" {
|
||||||
|
@ -346,11 +346,11 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := bd["iops"].(int); ok && v > 0 {
|
if v, ok := bd["iops"].(int); ok && v > 0 {
|
||||||
ebs.IOPS = aws.Integer(v)
|
ebs.IOPS = aws.Long(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
if dn, err := fetchRootDeviceName(d.Get("image_id").(string), ec2conn); err == nil {
|
if dn, err := fetchRootDeviceName(d.Get("image_id").(string), ec2conn); err == nil {
|
||||||
blockDevices = append(blockDevices, autoscaling.BlockDeviceMapping{
|
blockDevices = append(blockDevices, &autoscaling.BlockDeviceMapping{
|
||||||
DeviceName: dn,
|
DeviceName: dn,
|
||||||
EBS: ebs,
|
EBS: ebs,
|
||||||
})
|
})
|
||||||
|
@ -364,23 +364,25 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
||||||
createLaunchConfigurationOpts.BlockDeviceMappings = blockDevices
|
createLaunchConfigurationOpts.BlockDeviceMappings = blockDevices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var id string
|
||||||
if v, ok := d.GetOk("name"); ok {
|
if v, ok := d.GetOk("name"); ok {
|
||||||
createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(v.(string))
|
id = v.(string)
|
||||||
d.SetId(d.Get("name").(string))
|
|
||||||
} else {
|
} else {
|
||||||
hash := sha1.Sum([]byte(fmt.Sprintf("%#v", createLaunchConfigurationOpts)))
|
hash := sha1.Sum([]byte(fmt.Sprintf("%#v", createLaunchConfigurationOpts)))
|
||||||
config_name := fmt.Sprintf("terraform-%s", base64.URLEncoding.EncodeToString(hash[:]))
|
configName := fmt.Sprintf("terraform-%s", base64.URLEncoding.EncodeToString(hash[:]))
|
||||||
log.Printf("[DEBUG] Computed Launch config name: %s", config_name)
|
log.Printf("[DEBUG] Computed Launch config name: %s", configName)
|
||||||
createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(config_name)
|
id = configName
|
||||||
d.SetId(config_name)
|
|
||||||
}
|
}
|
||||||
|
createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(id)
|
||||||
|
|
||||||
log.Printf("[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts)
|
log.Printf(
|
||||||
err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
|
"[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts)
|
||||||
|
_, err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating launch configuration: %s", err)
|
return fmt.Errorf("Error creating launch configuration: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.SetId(id)
|
||||||
log.Printf("[INFO] launch configuration ID: %s", d.Id())
|
log.Printf("[INFO] launch configuration ID: %s", d.Id())
|
||||||
|
|
||||||
// We put a Retry here since sometimes eventual consistency bites
|
// We put a Retry here since sometimes eventual consistency bites
|
||||||
|
@ -394,8 +396,8 @@ func resourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface{}
|
||||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
describeOpts := autoscaling.LaunchConfigurationNamesType{
|
describeOpts := autoscaling.DescribeLaunchConfigurationsInput{
|
||||||
LaunchConfigurationNames: []string{d.Id()},
|
LaunchConfigurationNames: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] launch configuration describe configuration: %#v", describeOpts)
|
log.Printf("[DEBUG] launch configuration describe configuration: %#v", describeOpts)
|
||||||
|
@ -427,7 +429,7 @@ func resourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface{}
|
||||||
d.Set("spot_price", lc.SpotPrice)
|
d.Set("spot_price", lc.SpotPrice)
|
||||||
d.Set("security_groups", lc.SecurityGroups)
|
d.Set("security_groups", lc.SecurityGroups)
|
||||||
|
|
||||||
if err := readLCBlockDevices(d, &lc, ec2conn); err != nil {
|
if err := readLCBlockDevices(d, lc, ec2conn); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,8 +440,10 @@ func resourceAwsLaunchConfigurationDelete(d *schema.ResourceData, meta interface
|
||||||
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
autoscalingconn := meta.(*AWSClient).autoscalingconn
|
||||||
|
|
||||||
log.Printf("[DEBUG] Launch Configuration destroy: %v", d.Id())
|
log.Printf("[DEBUG] Launch Configuration destroy: %v", d.Id())
|
||||||
err := autoscalingconn.DeleteLaunchConfiguration(
|
_, err := autoscalingconn.DeleteLaunchConfiguration(
|
||||||
&autoscaling.LaunchConfigurationNameType{LaunchConfigurationName: aws.String(d.Id())})
|
&autoscaling.DeleteLaunchConfigurationInput{
|
||||||
|
LaunchConfigurationName: aws.String(d.Id()),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
autoscalingerr, ok := err.(aws.APIError)
|
autoscalingerr, ok := err.(aws.APIError)
|
||||||
if ok && autoscalingerr.Code == "InvalidConfiguration.NotFound" {
|
if ok && autoscalingerr.Code == "InvalidConfiguration.NotFound" {
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/autoscaling"
|
"github.com/awslabs/aws-sdk-go/service/autoscaling"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -107,8 +107,8 @@ func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe, err := conn.DescribeLaunchConfigurations(
|
describe, err := conn.DescribeLaunchConfigurations(
|
||||||
&autoscaling.LaunchConfigurationNamesType{
|
&autoscaling.DescribeLaunchConfigurationsInput{
|
||||||
LaunchConfigurationNames: []string{rs.Primary.ID},
|
LaunchConfigurationNames: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -146,7 +146,7 @@ func testAccCheckAWSLaunchConfigurationAttributes(conf *autoscaling.LaunchConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map out the block devices by name, which should be unique.
|
// Map out the block devices by name, which should be unique.
|
||||||
blockDevices := make(map[string]autoscaling.BlockDeviceMapping)
|
blockDevices := make(map[string]*autoscaling.BlockDeviceMapping)
|
||||||
for _, blockDevice := range conf.BlockDeviceMappings {
|
for _, blockDevice := range conf.BlockDeviceMappings {
|
||||||
blockDevices[*blockDevice.DeviceName] = blockDevice
|
blockDevices[*blockDevice.DeviceName] = blockDevice
|
||||||
}
|
}
|
||||||
|
@ -188,8 +188,8 @@ func testAccCheckAWSLaunchConfigurationExists(n string, res *autoscaling.LaunchC
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
||||||
|
|
||||||
describeOpts := autoscaling.LaunchConfigurationNamesType{
|
describeOpts := autoscaling.DescribeLaunchConfigurationsInput{
|
||||||
LaunchConfigurationNames: []string{rs.Primary.ID},
|
LaunchConfigurationNames: []*string{aws.String(rs.Primary.ID)},
|
||||||
}
|
}
|
||||||
describe, err := conn.DescribeLaunchConfigurations(&describeOpts)
|
describe, err := conn.DescribeLaunchConfigurations(&describeOpts)
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ func testAccCheckAWSLaunchConfigurationExists(n string, res *autoscaling.LaunchC
|
||||||
return fmt.Errorf("Launch Configuration Group not found")
|
return fmt.Errorf("Launch Configuration Group not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*res = describe.LaunchConfigurations[0]
|
*res = *describe.LaunchConfigurations[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,18 +40,18 @@ func resourceAwsMainRouteTableAssociation() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsMainRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsMainRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
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)
|
||||||
|
|
||||||
log.Printf("[INFO] Creating main route table association: %s => %s", vpcId, routeTableId)
|
log.Printf("[INFO] Creating main route table association: %s => %s", vpcId, routeTableId)
|
||||||
|
|
||||||
mainAssociation, err := findMainRouteTableAssociation(ec2conn, vpcId)
|
mainAssociation, err := findMainRouteTableAssociation(conn, vpcId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := ec2conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationRequest{
|
resp, err := conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{
|
||||||
AssociationID: mainAssociation.RouteTableAssociationID,
|
AssociationID: mainAssociation.RouteTableAssociationID,
|
||||||
RouteTableID: aws.String(routeTableId),
|
RouteTableID: aws.String(routeTableId),
|
||||||
})
|
})
|
||||||
|
@ -67,10 +67,10 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
mainAssociation, err := findMainRouteTableAssociation(
|
mainAssociation, err := findMainRouteTableAssociation(
|
||||||
ec2conn,
|
conn,
|
||||||
d.Get("vpc_id").(string))
|
d.Get("vpc_id").(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -88,13 +88,13 @@ 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).ec2conn
|
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)
|
||||||
|
|
||||||
log.Printf("[INFO] Updating main route table association: %s => %s", vpcId, routeTableId)
|
log.Printf("[INFO] Updating main route table association: %s => %s", vpcId, routeTableId)
|
||||||
|
|
||||||
resp, err := ec2conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationRequest{
|
resp, err := conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{
|
||||||
AssociationID: aws.String(d.Id()),
|
AssociationID: aws.String(d.Id()),
|
||||||
RouteTableID: aws.String(routeTableId),
|
RouteTableID: aws.String(routeTableId),
|
||||||
})
|
})
|
||||||
|
@ -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).ec2conn
|
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)
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ func resourceAwsMainRouteTableAssociationDelete(d *schema.ResourceData, meta int
|
||||||
vpcId,
|
vpcId,
|
||||||
originalRouteTableId)
|
originalRouteTableId)
|
||||||
|
|
||||||
resp, err := ec2conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationRequest{
|
resp, err := conn.ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{
|
||||||
AssociationID: aws.String(d.Id()),
|
AssociationID: aws.String(d.Id()),
|
||||||
RouteTableID: aws.String(originalRouteTableId),
|
RouteTableID: aws.String(originalRouteTableId),
|
||||||
})
|
})
|
||||||
|
@ -130,31 +130,31 @@ func resourceAwsMainRouteTableAssociationDelete(d *schema.ResourceData, meta int
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findMainRouteTableAssociation(ec2conn *ec2.EC2, vpcId string) (*ec2.RouteTableAssociation, error) {
|
func findMainRouteTableAssociation(conn *ec2.EC2, vpcId string) (*ec2.RouteTableAssociation, error) {
|
||||||
mainRouteTable, err := findMainRouteTable(ec2conn, vpcId)
|
mainRouteTable, err := findMainRouteTable(conn, vpcId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range mainRouteTable.Associations {
|
for _, a := range mainRouteTable.Associations {
|
||||||
if *a.Main {
|
if *a.Main {
|
||||||
return &a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Could not find main routing table association for VPC: %s", vpcId)
|
return nil, fmt.Errorf("Could not find main routing table association for VPC: %s", vpcId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func findMainRouteTable(ec2conn *ec2.EC2, vpcId string) (*ec2.RouteTable, error) {
|
func findMainRouteTable(conn *ec2.EC2, vpcId string) (*ec2.RouteTable, error) {
|
||||||
mainFilter := ec2.Filter{
|
mainFilter := &ec2.Filter{
|
||||||
aws.String("association.main"),
|
Name: aws.String("association.main"),
|
||||||
[]string{"true"},
|
Values: []*string{aws.String("true")},
|
||||||
}
|
}
|
||||||
vpcFilter := ec2.Filter{
|
vpcFilter := &ec2.Filter{
|
||||||
aws.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
[]string{vpcId},
|
Values: []*string{aws.String(vpcId)},
|
||||||
}
|
}
|
||||||
routeResp, err := ec2conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
routeResp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||||
Filters: []ec2.Filter{mainFilter, vpcFilter},
|
Filters: []*ec2.Filter{mainFilter, vpcFilter},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -165,5 +165,5 @@ func findMainRouteTable(ec2conn *ec2.EC2, vpcId string) (*ec2.RouteTable, error)
|
||||||
len(routeResp.RouteTables))
|
len(routeResp.RouteTables))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &routeResp.RouteTables[0], nil
|
return routeResp.RouteTables[0], nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)},
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsRoute53Record() *schema.Resource {
|
func resourceAwsRoute53Record() *schema.Resource {
|
||||||
|
@ -74,7 +74,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
conn := meta.(*AWSClient).r53conn
|
conn := meta.(*AWSClient).r53conn
|
||||||
zone := cleanZoneID(d.Get("zone_id").(string))
|
zone := cleanZoneID(d.Get("zone_id").(string))
|
||||||
|
|
||||||
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(zone)})
|
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -90,15 +90,15 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
// operation happening at the same time.
|
// operation happening at the same time.
|
||||||
changeBatch := &route53.ChangeBatch{
|
changeBatch := &route53.ChangeBatch{
|
||||||
Comment: aws.String("Managed by Terraform"),
|
Comment: aws.String("Managed by Terraform"),
|
||||||
Changes: []route53.Change{
|
Changes: []*route53.Change{
|
||||||
route53.Change{
|
&route53.Change{
|
||||||
Action: aws.String("UPSERT"),
|
Action: aws.String("UPSERT"),
|
||||||
ResourceRecordSet: rec,
|
ResourceRecordSet: rec,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &route53.ChangeResourceRecordSetsRequest{
|
req := &route53.ChangeResourceRecordSetsInput{
|
||||||
HostedZoneID: aws.String(cleanZoneID(*zoneRecord.HostedZone.ID)),
|
HostedZoneID: aws.String(cleanZoneID(*zoneRecord.HostedZone.ID)),
|
||||||
ChangeBatch: changeBatch,
|
ChangeBatch: changeBatch,
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
changeInfo := respRaw.(*route53.ChangeResourceRecordSetsResponse).ChangeInfo
|
changeInfo := respRaw.(*route53.ChangeResourceRecordSetsOutput).ChangeInfo
|
||||||
|
|
||||||
// Generate an ID
|
// Generate an ID
|
||||||
d.SetId(fmt.Sprintf("%s_%s_%s", zone, d.Get("name").(string), d.Get("type").(string)))
|
d.SetId(fmt.Sprintf("%s_%s_%s", zone, d.Get("name").(string), d.Get("type").(string)))
|
||||||
|
@ -146,7 +146,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
Timeout: 30 * time.Minute,
|
Timeout: 30 * time.Minute,
|
||||||
MinTimeout: 5 * time.Second,
|
MinTimeout: 5 * time.Second,
|
||||||
Refresh: func() (result interface{}, state string, err error) {
|
Refresh: func() (result interface{}, state string, err error) {
|
||||||
changeRequest := &route53.GetChangeRequest{
|
changeRequest := &route53.GetChangeInput{
|
||||||
ID: aws.String(cleanChangeID(*changeInfo.ID)),
|
ID: aws.String(cleanChangeID(*changeInfo.ID)),
|
||||||
}
|
}
|
||||||
return resourceAwsGoRoute53Wait(conn, changeRequest)
|
return resourceAwsGoRoute53Wait(conn, changeRequest)
|
||||||
|
@ -166,13 +166,13 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
zone := cleanZoneID(d.Get("zone_id").(string))
|
zone := cleanZoneID(d.Get("zone_id").(string))
|
||||||
|
|
||||||
// get expanded name
|
// get expanded name
|
||||||
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(zone)})
|
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
en := expandRecordName(d.Get("name").(string), *zoneRecord.HostedZone.Name)
|
en := expandRecordName(d.Get("name").(string), *zoneRecord.HostedZone.Name)
|
||||||
|
|
||||||
lopts := &route53.ListResourceRecordSetsRequest{
|
lopts := &route53.ListResourceRecordSetsInput{
|
||||||
HostedZoneID: aws.String(cleanZoneID(zone)),
|
HostedZoneID: aws.String(cleanZoneID(zone)),
|
||||||
StartRecordName: aws.String(en),
|
StartRecordName: aws.String(en),
|
||||||
StartRecordType: aws.String(d.Get("type").(string)),
|
StartRecordType: aws.String(d.Get("type").(string)),
|
||||||
|
@ -218,7 +218,7 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
|
||||||
zone := cleanZoneID(d.Get("zone_id").(string))
|
zone := cleanZoneID(d.Get("zone_id").(string))
|
||||||
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s",
|
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s",
|
||||||
zone, d.Get("name").(string))
|
zone, d.Get("name").(string))
|
||||||
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(zone)})
|
zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(zone)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -231,15 +231,15 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
|
||||||
// Create the new records
|
// Create the new records
|
||||||
changeBatch := &route53.ChangeBatch{
|
changeBatch := &route53.ChangeBatch{
|
||||||
Comment: aws.String("Deleted by Terraform"),
|
Comment: aws.String("Deleted by Terraform"),
|
||||||
Changes: []route53.Change{
|
Changes: []*route53.Change{
|
||||||
route53.Change{
|
&route53.Change{
|
||||||
Action: aws.String("DELETE"),
|
Action: aws.String("DELETE"),
|
||||||
ResourceRecordSet: rec,
|
ResourceRecordSet: rec,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &route53.ChangeResourceRecordSetsRequest{
|
req := &route53.ChangeResourceRecordSetsInput{
|
||||||
HostedZoneID: aws.String(cleanZoneID(zone)),
|
HostedZoneID: aws.String(cleanZoneID(zone)),
|
||||||
ChangeBatch: changeBatch,
|
ChangeBatch: changeBatch,
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
route53 "github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCleanRecordName(t *testing.T) {
|
func TestCleanRecordName(t *testing.T) {
|
||||||
|
@ -134,7 +134,7 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
|
||||||
name := parts[1]
|
name := parts[1]
|
||||||
rType := parts[2]
|
rType := parts[2]
|
||||||
|
|
||||||
lopts := &route53.ListResourceRecordSetsRequest{
|
lopts := &route53.ListResourceRecordSetsInput{
|
||||||
HostedZoneID: aws.String(cleanZoneID(zone)),
|
HostedZoneID: aws.String(cleanZoneID(zone)),
|
||||||
StartRecordName: aws.String(name),
|
StartRecordName: aws.String(name),
|
||||||
StartRecordType: aws.String(rType),
|
StartRecordType: aws.String(rType),
|
||||||
|
@ -174,7 +174,7 @@ func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
|
||||||
|
|
||||||
en := expandRecordName(name, "notexample.com")
|
en := expandRecordName(name, "notexample.com")
|
||||||
|
|
||||||
lopts := &route53.ListResourceRecordSetsRequest{
|
lopts := &route53.ListResourceRecordSetsInput{
|
||||||
HostedZoneID: aws.String(cleanZoneID(zone)),
|
HostedZoneID: aws.String(cleanZoneID(zone)),
|
||||||
StartRecordName: aws.String(en),
|
StartRecordName: aws.String(en),
|
||||||
StartRecordType: aws.String(rType),
|
StartRecordType: aws.String(rType),
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsRoute53Zone() *schema.Resource {
|
func resourceAwsRoute53Zone() *schema.Resource {
|
||||||
|
@ -51,7 +51,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
|
||||||
r53 := meta.(*AWSClient).r53conn
|
r53 := meta.(*AWSClient).r53conn
|
||||||
|
|
||||||
comment := &route53.HostedZoneConfig{Comment: aws.String("Managed by Terraform")}
|
comment := &route53.HostedZoneConfig{Comment: aws.String("Managed by Terraform")}
|
||||||
req := &route53.CreateHostedZoneRequest{
|
req := &route53.CreateHostedZoneInput{
|
||||||
Name: aws.String(d.Get("name").(string)),
|
Name: aws.String(d.Get("name").(string)),
|
||||||
HostedZoneConfig: comment,
|
HostedZoneConfig: comment,
|
||||||
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
||||||
|
@ -76,7 +76,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: 10 * time.Minute,
|
||||||
MinTimeout: 2 * time.Second,
|
MinTimeout: 2 * time.Second,
|
||||||
Refresh: func() (result interface{}, state string, err error) {
|
Refresh: func() (result interface{}, state string, err error) {
|
||||||
changeRequest := &route53.GetChangeRequest{
|
changeRequest := &route53.GetChangeInput{
|
||||||
ID: aws.String(cleanChangeID(*resp.ChangeInfo.ID)),
|
ID: aws.String(cleanChangeID(*resp.ChangeInfo.ID)),
|
||||||
}
|
}
|
||||||
return resourceAwsGoRoute53Wait(r53, changeRequest)
|
return resourceAwsGoRoute53Wait(r53, changeRequest)
|
||||||
|
@ -91,7 +91,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
|
||||||
|
|
||||||
func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
r53 := meta.(*AWSClient).r53conn
|
r53 := meta.(*AWSClient).r53conn
|
||||||
zone, err := r53.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(d.Id())})
|
zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(d.Id())})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Handle a deleted zone
|
// Handle a deleted zone
|
||||||
if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" {
|
if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" {
|
||||||
|
@ -101,13 +101,16 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ns := zone.DelegationSet.NameServers
|
ns := make([]string, len(zone.DelegationSet.NameServers))
|
||||||
|
for i := range zone.DelegationSet.NameServers {
|
||||||
|
ns[i] = *zone.DelegationSet.NameServers[i]
|
||||||
|
}
|
||||||
if err := d.Set("name_servers", ns); err != nil {
|
if err := d.Set("name_servers", ns); err != nil {
|
||||||
return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err)
|
return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get tags
|
// get tags
|
||||||
req := &route53.ListTagsForResourceRequest{
|
req := &route53.ListTagsForResourceInput{
|
||||||
ResourceID: aws.String(d.Id()),
|
ResourceID: aws.String(d.Id()),
|
||||||
ResourceType: aws.String("hostedzone"),
|
ResourceType: aws.String("hostedzone"),
|
||||||
}
|
}
|
||||||
|
@ -117,7 +120,7 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var tags []route53.Tag
|
var tags []*route53.Tag
|
||||||
if resp.ResourceTagSet != nil {
|
if resp.ResourceTagSet != nil {
|
||||||
tags = resp.ResourceTagSet.Tags
|
tags = resp.ResourceTagSet.Tags
|
||||||
}
|
}
|
||||||
|
@ -146,7 +149,7 @@ func resourceAwsRoute53ZoneDelete(d *schema.ResourceData, meta interface{}) erro
|
||||||
|
|
||||||
log.Printf("[DEBUG] Deleting Route53 hosted zone: %s (ID: %s)",
|
log.Printf("[DEBUG] Deleting Route53 hosted zone: %s (ID: %s)",
|
||||||
d.Get("name").(string), d.Id())
|
d.Get("name").(string), d.Id())
|
||||||
_, err := r53.DeleteHostedZone(&route53.DeleteHostedZoneRequest{ID: aws.String(d.Id())})
|
_, err := r53.DeleteHostedZone(&route53.DeleteHostedZoneInput{ID: aws.String(d.Id())})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -154,7 +157,7 @@ func resourceAwsRoute53ZoneDelete(d *schema.ResourceData, meta interface{}) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsGoRoute53Wait(r53 *route53.Route53, ref *route53.GetChangeRequest) (result interface{}, state string, err error) {
|
func resourceAwsGoRoute53Wait(r53 *route53.Route53, ref *route53.GetChangeInput) (result interface{}, state string, err error) {
|
||||||
|
|
||||||
status, err := r53.GetChange(ref)
|
status, err := r53.GetChange(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCleanPrefix(t *testing.T) {
|
func TestCleanPrefix(t *testing.T) {
|
||||||
|
@ -91,7 +91,7 @@ func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(rs.Primary.ID)})
|
_, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(rs.Primary.ID)})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("Hosted zone still exists")
|
return fmt.Errorf("Hosted zone still exists")
|
||||||
}
|
}
|
||||||
|
@ -111,15 +111,15 @@ func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||||
resp, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(rs.Primary.ID)})
|
resp, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(rs.Primary.ID)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Hosted zone err: %v", err)
|
return fmt.Errorf("Hosted zone err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ns := range resp.DelegationSet.NameServers {
|
for _, ns := range resp.DelegationSet.NameServers {
|
||||||
attribute := fmt.Sprintf("name_servers.%d", hashcode.String(ns))
|
attribute := fmt.Sprintf("name_servers.%d", hashcode.String(*ns))
|
||||||
dsns := rs.Primary.Attributes[attribute]
|
dsns := rs.Primary.Attributes[attribute]
|
||||||
if dsns != ns {
|
if dsns != *ns {
|
||||||
return fmt.Errorf("Got: %v for %v, Expected: %v", dsns, attribute, ns)
|
return fmt.Errorf("Got: %v for %v, Expected: %v", dsns, attribute, ns)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func testAccLoadTagsR53(zone *route53.HostedZone, td *route53.ResourceTagSet) re
|
||||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||||
|
|
||||||
zone := cleanZoneID(*zone.ID)
|
zone := cleanZoneID(*zone.ID)
|
||||||
req := &route53.ListTagsForResourceRequest{
|
req := &route53.ListTagsForResourceInput{
|
||||||
ResourceID: aws.String(zone),
|
ResourceID: aws.String(zone),
|
||||||
ResourceType: aws.String("hostedzone"),
|
ResourceType: aws.String("hostedzone"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/hashcode"
|
"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/helper/schema"
|
||||||
|
@ -62,15 +62,15 @@ func resourceAwsRouteTable() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Create the routing table
|
// Create the routing table
|
||||||
createOpts := &ec2.CreateRouteTableRequest{
|
createOpts := &ec2.CreateRouteTableInput{
|
||||||
VPCID: aws.String(d.Get("vpc_id").(string)),
|
VPCID: aws.String(d.Get("vpc_id").(string)),
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] RouteTable create config: %#v", createOpts)
|
log.Printf("[DEBUG] RouteTable create config: %#v", createOpts)
|
||||||
|
|
||||||
resp, err := ec2conn.CreateRouteTable(createOpts)
|
resp, err := conn.CreateRouteTable(createOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating route table: %s", err)
|
return fmt.Errorf("Error creating route table: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"pending"},
|
Pending: []string{"pending"},
|
||||||
Target: "ready",
|
Target: "ready",
|
||||||
Refresh: resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id()),
|
Refresh: resourceAwsRouteTableStateRefreshFunc(conn, d.Id()),
|
||||||
Timeout: 1 * time.Minute,
|
Timeout: 1 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -100,9 +100,9 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id())()
|
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -147,13 +147,13 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("route", route)
|
d.Set("route", route)
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
d.Set("tags", tagsToMap(rt.Tags))
|
d.Set("tags", tagsToMapSDK(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).ec2conn
|
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") {
|
||||||
|
@ -169,7 +169,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Deleting route from %s: %s",
|
"[INFO] Deleting route from %s: %s",
|
||||||
d.Id(), m["cidr_block"].(string))
|
d.Id(), m["cidr_block"].(string))
|
||||||
err := ec2conn.DeleteRoute(&ec2.DeleteRouteRequest{
|
_, err := conn.DeleteRoute(&ec2.DeleteRouteInput{
|
||||||
RouteTableID: aws.String(d.Id()),
|
RouteTableID: aws.String(d.Id()),
|
||||||
DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
|
DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
|
||||||
})
|
})
|
||||||
|
@ -186,7 +186,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
for _, route := range nrs.List() {
|
for _, route := range nrs.List() {
|
||||||
m := route.(map[string]interface{})
|
m := route.(map[string]interface{})
|
||||||
|
|
||||||
opts := ec2.CreateRouteRequest{
|
opts := ec2.CreateRouteInput{
|
||||||
RouteTableID: aws.String(d.Id()),
|
RouteTableID: aws.String(d.Id()),
|
||||||
DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
|
DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
|
||||||
GatewayID: aws.String(m["gateway_id"].(string)),
|
GatewayID: aws.String(m["gateway_id"].(string)),
|
||||||
|
@ -195,7 +195,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts)
|
log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts)
|
||||||
if err := ec2conn.CreateRoute(&opts); err != nil {
|
if _, err := conn.CreateRoute(&opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setTags(ec2conn, d); err != nil {
|
if err := setTagsSDK(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -214,11 +214,11 @@ 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).ec2conn
|
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.
|
||||||
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id())()
|
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
// Do all the disassociations
|
// Do all the disassociations
|
||||||
for _, a := range rt.Associations {
|
for _, a := range rt.Associations {
|
||||||
log.Printf("[INFO] Disassociating association: %s", *a.RouteTableAssociationID)
|
log.Printf("[INFO] Disassociating association: %s", *a.RouteTableAssociationID)
|
||||||
err := ec2conn.DisassociateRouteTable(&ec2.DisassociateRouteTableRequest{
|
_, err := conn.DisassociateRouteTable(&ec2.DisassociateRouteTableInput{
|
||||||
AssociationID: a.RouteTableAssociationID,
|
AssociationID: a.RouteTableAssociationID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -240,7 +240,7 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
// Delete the route table
|
// Delete the route table
|
||||||
log.Printf("[INFO] Deleting Route Table: %s", d.Id())
|
log.Printf("[INFO] Deleting Route Table: %s", d.Id())
|
||||||
err = ec2conn.DeleteRouteTable(&ec2.DeleteRouteTableRequest{
|
_, err = conn.DeleteRouteTable(&ec2.DeleteRouteTableInput{
|
||||||
RouteTableID: aws.String(d.Id()),
|
RouteTableID: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -260,7 +260,7 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"ready"},
|
Pending: []string{"ready"},
|
||||||
Target: "",
|
Target: "",
|
||||||
Refresh: resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id()),
|
Refresh: resourceAwsRouteTableStateRefreshFunc(conn, d.Id()),
|
||||||
Timeout: 1 * time.Minute,
|
Timeout: 1 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -296,8 +296,8 @@ func resourceAwsRouteTableHash(v interface{}) int {
|
||||||
// a RouteTable.
|
// a RouteTable.
|
||||||
func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||||
RouteTableIDs: []string{id},
|
RouteTableIDs: []*string{aws.String(id)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidRouteTableID.NotFound" {
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidRouteTableID.NotFound" {
|
||||||
|
@ -314,7 +314,7 @@ func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.St
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rt := &resp.RouteTables[0]
|
rt := resp.RouteTables[0]
|
||||||
return rt, "ready", nil
|
return rt, "ready", nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,14 +32,14 @@ func resourceAwsRouteTableAssociation() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Creating route table association: %s => %s",
|
"[INFO] Creating route table association: %s => %s",
|
||||||
d.Get("subnet_id").(string),
|
d.Get("subnet_id").(string),
|
||||||
d.Get("route_table_id").(string))
|
d.Get("route_table_id").(string))
|
||||||
|
|
||||||
resp, err := ec2conn.AssociateRouteTable(&ec2.AssociateRouteTableRequest{
|
resp, err := conn.AssociateRouteTable(&ec2.AssociateRouteTableInput{
|
||||||
RouteTableID: aws.String(d.Get("route_table_id").(string)),
|
RouteTableID: aws.String(d.Get("route_table_id").(string)),
|
||||||
SubnetID: aws.String(d.Get("subnet_id").(string)),
|
SubnetID: aws.String(d.Get("subnet_id").(string)),
|
||||||
})
|
})
|
||||||
|
@ -56,11 +56,11 @@ 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).ec2conn
|
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(
|
||||||
ec2conn, d.Get("route_table_id").(string))()
|
conn, d.Get("route_table_id").(string))()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -88,18 +88,18 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Creating route table association: %s => %s",
|
"[INFO] Creating route table association: %s => %s",
|
||||||
d.Get("subnet_id").(string),
|
d.Get("subnet_id").(string),
|
||||||
d.Get("route_table_id").(string))
|
d.Get("route_table_id").(string))
|
||||||
|
|
||||||
req := &ec2.ReplaceRouteTableAssociationRequest{
|
req := &ec2.ReplaceRouteTableAssociationInput{
|
||||||
AssociationID: aws.String(d.Id()),
|
AssociationID: aws.String(d.Id()),
|
||||||
RouteTableID: aws.String(d.Get("route_table_id").(string)),
|
RouteTableID: aws.String(d.Get("route_table_id").(string)),
|
||||||
}
|
}
|
||||||
resp, err := ec2conn.ReplaceRouteTableAssociation(req)
|
resp, err := conn.ReplaceRouteTableAssociation(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec2err, ok := err.(aws.APIError)
|
ec2err, ok := err.(aws.APIError)
|
||||||
|
@ -119,10 +119,10 @@ 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).ec2conn
|
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 := ec2conn.DisassociateRouteTable(&ec2.DisassociateRouteTableRequest{
|
_, err := conn.DisassociateRouteTable(&ec2.DisassociateRouteTableInput{
|
||||||
AssociationID: aws.String(d.Id()),
|
AssociationID: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,8 +4,8 @@ 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/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -46,8 +46,8 @@ func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the resource
|
// Try to find the resource
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||||
RouteTableIDs: []string{rs.Primary.Attributes["route_table_id"]},
|
RouteTableIDs: []*string{aws.String(rs.Primary.Attributes["route_table_id"])},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Verify the error is what we want
|
// Verify the error is what we want
|
||||||
|
@ -84,8 +84,8 @@ func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resour
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||||
RouteTableIDs: []string{rs.Primary.Attributes["route_table_id"]},
|
RouteTableIDs: []*string{aws.String(rs.Primary.Attributes["route_table_id"])},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -94,7 +94,7 @@ func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resour
|
||||||
return fmt.Errorf("RouteTable not found")
|
return fmt.Errorf("RouteTable not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = resp.RouteTables[0]
|
*v = *resp.RouteTables[0]
|
||||||
|
|
||||||
if len(v.Associations) == 0 {
|
if len(v.Associations) == 0 {
|
||||||
return fmt.Errorf("no associations")
|
return fmt.Errorf("no associations")
|
||||||
|
|
|
@ -4,8 +4,8 @@ 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/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,7 @@ func TestAccAWSRouteTable_normal(t *testing.T) {
|
||||||
return fmt.Errorf("bad routes: %#v", v.Routes)
|
return fmt.Errorf("bad routes: %#v", v.Routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := make(map[string]ec2.Route)
|
routes := make(map[string]*ec2.Route)
|
||||||
for _, r := range v.Routes {
|
for _, r := range v.Routes {
|
||||||
routes[*r.DestinationCIDRBlock] = r
|
routes[*r.DestinationCIDRBlock] = r
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func TestAccAWSRouteTable_normal(t *testing.T) {
|
||||||
return fmt.Errorf("bad routes: %#v", v.Routes)
|
return fmt.Errorf("bad routes: %#v", v.Routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := make(map[string]ec2.Route)
|
routes := make(map[string]*ec2.Route)
|
||||||
for _, r := range v.Routes {
|
for _, r := range v.Routes {
|
||||||
routes[*r.DestinationCIDRBlock] = r
|
routes[*r.DestinationCIDRBlock] = r
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func TestAccAWSRouteTable_instance(t *testing.T) {
|
||||||
return fmt.Errorf("bad routes: %#v", v.Routes)
|
return fmt.Errorf("bad routes: %#v", v.Routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := make(map[string]ec2.Route)
|
routes := make(map[string]*ec2.Route)
|
||||||
for _, r := range v.Routes {
|
for _, r := range v.Routes {
|
||||||
routes[*r.DestinationCIDRBlock] = r
|
routes[*r.DestinationCIDRBlock] = r
|
||||||
}
|
}
|
||||||
|
@ -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),
|
||||||
testAccCheckTags(&route_table.Tags, "foo", "bar"),
|
testAccCheckTagsSDK(&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),
|
||||||
testAccCheckTags(&route_table.Tags, "foo", ""),
|
testAccCheckTagsSDK(&route_table.Tags, "foo", ""),
|
||||||
testAccCheckTags(&route_table.Tags, "bar", "baz"),
|
testAccCheckTagsSDK(&route_table.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -159,8 +159,8 @@ func testAccCheckRouteTableDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the resource
|
// Try to find the resource
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||||
RouteTableIDs: []string{rs.Primary.ID},
|
RouteTableIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(resp.RouteTables) > 0 {
|
if len(resp.RouteTables) > 0 {
|
||||||
|
@ -195,8 +195,8 @@ func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestChec
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{
|
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
|
||||||
RouteTableIDs: []string{rs.Primary.ID},
|
RouteTableIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -205,7 +205,7 @@ func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestChec
|
||||||
return fmt.Errorf("RouteTable not found")
|
return fmt.Errorf("RouteTable not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = resp.RouteTables[0]
|
*v = *resp.RouteTables[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ func _TestAccAWSRouteTable_vpcPeering(t *testing.T) {
|
||||||
return fmt.Errorf("bad routes: %#v", v.Routes)
|
return fmt.Errorf("bad routes: %#v", v.Routes)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := make(map[string]ec2.Route)
|
routes := make(map[string]*ec2.Route)
|
||||||
for _, r := range v.Routes {
|
for _, r := range v.Routes {
|
||||||
routes[*r.DestinationCIDRBlock] = r
|
routes[*r.DestinationCIDRBlock] = r
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsS3Bucket() *schema.Resource {
|
func resourceAwsS3Bucket() *schema.Resource {
|
||||||
|
@ -46,7 +46,7 @@ func resourceAwsS3BucketCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
log.Printf("[DEBUG] S3 bucket create: %s, ACL: %s", bucket, acl)
|
log.Printf("[DEBUG] S3 bucket create: %s, ACL: %s", bucket, acl)
|
||||||
|
|
||||||
req := &s3.CreateBucketRequest{
|
req := &s3.CreateBucketInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
ACL: aws.String(acl),
|
ACL: aws.String(acl),
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func resourceAwsS3BucketUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
s3conn := meta.(*AWSClient).s3conn
|
s3conn := meta.(*AWSClient).s3conn
|
||||||
|
|
||||||
err := s3conn.HeadBucket(&s3.HeadBucketRequest{
|
_, err := s3conn.HeadBucket(&s3.HeadBucketInput{
|
||||||
Bucket: aws.String(d.Id()),
|
Bucket: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,7 +104,7 @@ func resourceAwsS3BucketDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
s3conn := meta.(*AWSClient).s3conn
|
s3conn := meta.(*AWSClient).s3conn
|
||||||
|
|
||||||
log.Printf("[DEBUG] S3 Delete Bucket: %s", d.Id())
|
log.Printf("[DEBUG] S3 Delete Bucket: %s", d.Id())
|
||||||
err := s3conn.DeleteBucket(&s3.DeleteBucketRequest{
|
_, err := s3conn.DeleteBucket(&s3.DeleteBucketInput{
|
||||||
Bucket: aws.String(d.Id()),
|
Bucket: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSS3Bucket(t *testing.T) {
|
func TestAccAWSS3Bucket(t *testing.T) {
|
||||||
|
@ -37,7 +37,7 @@ func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
|
||||||
if rs.Type != "aws_s3_bucket" {
|
if rs.Type != "aws_s3_bucket" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := conn.DeleteBucket(&s3.DeleteBucketRequest{
|
_, err := conn.DeleteBucket(&s3.DeleteBucketInput{
|
||||||
Bucket: aws.String(rs.Primary.ID),
|
Bucket: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -59,7 +59,7 @@ func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
conn := testAccProvider.Meta().(*AWSClient).s3conn
|
||||||
err := conn.HeadBucket(&s3.HeadBucketRequest{
|
_, err := conn.HeadBucket(&s3.HeadBucketInput{
|
||||||
Bucket: aws.String(rs.Primary.ID),
|
Bucket: 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)},
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -64,18 +64,18 @@ func resourceAwsVpc() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
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)
|
||||||
}
|
}
|
||||||
// Create the VPC
|
// Create the VPC
|
||||||
createOpts := &ec2.CreateVPCRequest{
|
createOpts := &ec2.CreateVPCInput{
|
||||||
CIDRBlock: aws.String(d.Get("cidr_block").(string)),
|
CIDRBlock: aws.String(d.Get("cidr_block").(string)),
|
||||||
InstanceTenancy: aws.String(instance_tenancy),
|
InstanceTenancy: aws.String(instance_tenancy),
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] VPC create config: %#v", *createOpts)
|
log.Printf("[DEBUG] VPC create config: %#v", *createOpts)
|
||||||
vpcResp, err := ec2conn.CreateVPC(createOpts)
|
vpcResp, err := conn.CreateVPC(createOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating VPC: %s", err)
|
return fmt.Errorf("Error creating VPC: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"pending"},
|
Pending: []string{"pending"},
|
||||||
Target: "available",
|
Target: "available",
|
||||||
Refresh: VPCStateRefreshFunc(ec2conn, d.Id()),
|
Refresh: VPCStateRefreshFunc(conn, d.Id()),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: 10 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -110,10 +110,10 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Refresh the VPC state
|
// Refresh the VPC state
|
||||||
vpcRaw, _, err := VPCStateRefreshFunc(ec2conn, d.Id())()
|
vpcRaw, _, err := VPCStateRefreshFunc(conn, d.Id())()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -128,25 +128,25 @@ 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", tagsToMap(vpc.Tags))
|
d.Set("tags", tagsToMapSDK(vpc.Tags))
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
attribute := "enableDnsSupport"
|
attribute := "enableDnsSupport"
|
||||||
DescribeAttrOpts := &ec2.DescribeVPCAttributeRequest{
|
DescribeAttrOpts := &ec2.DescribeVPCAttributeInput{
|
||||||
Attribute: aws.String(attribute),
|
Attribute: aws.String(attribute),
|
||||||
VPCID: aws.String(vpcid),
|
VPCID: aws.String(vpcid),
|
||||||
}
|
}
|
||||||
resp, err := ec2conn.DescribeVPCAttribute(DescribeAttrOpts)
|
resp, err := conn.DescribeVPCAttribute(DescribeAttrOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
d.Set("enable_dns_support", *resp.EnableDNSSupport)
|
d.Set("enable_dns_support", *resp.EnableDNSSupport)
|
||||||
attribute = "enableDnsHostnames"
|
attribute = "enableDnsHostnames"
|
||||||
DescribeAttrOpts = &ec2.DescribeVPCAttributeRequest{
|
DescribeAttrOpts = &ec2.DescribeVPCAttributeInput{
|
||||||
Attribute: &attribute,
|
Attribute: &attribute,
|
||||||
VPCID: &vpcid,
|
VPCID: &vpcid,
|
||||||
}
|
}
|
||||||
resp, err = ec2conn.DescribeVPCAttribute(DescribeAttrOpts)
|
resp, err = conn.DescribeVPCAttribute(DescribeAttrOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -156,16 +156,16 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
// Really Ugly need to make this better - rmenn
|
// Really Ugly need to make this better - rmenn
|
||||||
filter1 := &ec2.Filter{
|
filter1 := &ec2.Filter{
|
||||||
Name: aws.String("association.main"),
|
Name: aws.String("association.main"),
|
||||||
Values: []string{("true")},
|
Values: []*string{aws.String("true")},
|
||||||
}
|
}
|
||||||
filter2 := &ec2.Filter{
|
filter2 := &ec2.Filter{
|
||||||
Name: aws.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
Values: []string{(d.Id())},
|
Values: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
DescribeRouteOpts := &ec2.DescribeRouteTablesRequest{
|
DescribeRouteOpts := &ec2.DescribeRouteTablesInput{
|
||||||
Filters: []ec2.Filter{*filter1, *filter2},
|
Filters: []*ec2.Filter{filter1, filter2},
|
||||||
}
|
}
|
||||||
routeResp, err := ec2conn.DescribeRouteTables(DescribeRouteOpts)
|
routeResp, err := conn.DescribeRouteTables(DescribeRouteOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -173,21 +173,21 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("main_route_table_id", *v[0].RouteTableID)
|
d.Set("main_route_table_id", *v[0].RouteTableID)
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceAwsVpcSetDefaultNetworkAcl(ec2conn, d)
|
resourceAwsVpcSetDefaultNetworkAcl(conn, d)
|
||||||
resourceAwsVpcSetDefaultSecurityGroup(ec2conn, d)
|
resourceAwsVpcSetDefaultSecurityGroup(conn, d)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Turn on partial mode
|
// Turn on partial mode
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
vpcid := d.Id()
|
vpcid := d.Id()
|
||||||
if d.HasChange("enable_dns_hostnames") {
|
if d.HasChange("enable_dns_hostnames") {
|
||||||
val := d.Get("enable_dns_hostnames").(bool)
|
val := d.Get("enable_dns_hostnames").(bool)
|
||||||
modifyOpts := &ec2.ModifyVPCAttributeRequest{
|
modifyOpts := &ec2.ModifyVPCAttributeInput{
|
||||||
VPCID: &vpcid,
|
VPCID: &vpcid,
|
||||||
EnableDNSHostnames: &ec2.AttributeBooleanValue{
|
EnableDNSHostnames: &ec2.AttributeBooleanValue{
|
||||||
Value: &val,
|
Value: &val,
|
||||||
|
@ -197,7 +197,7 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Modifying enable_dns_support vpc attribute for %s: %#v",
|
"[INFO] Modifying enable_dns_support vpc attribute for %s: %#v",
|
||||||
d.Id(), modifyOpts)
|
d.Id(), modifyOpts)
|
||||||
if err := ec2conn.ModifyVPCAttribute(modifyOpts); err != nil {
|
if _, err := conn.ModifyVPCAttribute(modifyOpts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
if d.HasChange("enable_dns_support") {
|
if d.HasChange("enable_dns_support") {
|
||||||
val := d.Get("enable_dns_support").(bool)
|
val := d.Get("enable_dns_support").(bool)
|
||||||
modifyOpts := &ec2.ModifyVPCAttributeRequest{
|
modifyOpts := &ec2.ModifyVPCAttributeInput{
|
||||||
VPCID: &vpcid,
|
VPCID: &vpcid,
|
||||||
EnableDNSSupport: &ec2.AttributeBooleanValue{
|
EnableDNSSupport: &ec2.AttributeBooleanValue{
|
||||||
Value: &val,
|
Value: &val,
|
||||||
|
@ -216,14 +216,14 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Modifying enable_dns_support vpc attribute for %s: %#v",
|
"[INFO] Modifying enable_dns_support vpc attribute for %s: %#v",
|
||||||
d.Id(), modifyOpts)
|
d.Id(), modifyOpts)
|
||||||
if err := ec2conn.ModifyVPCAttribute(modifyOpts); err != nil {
|
if _, err := conn.ModifyVPCAttribute(modifyOpts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetPartial("enable_dns_support")
|
d.SetPartial("enable_dns_support")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setTags(ec2conn, d); err != nil {
|
if err := setTagsSDK(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -234,13 +234,13 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
vpcID := d.Id()
|
vpcID := d.Id()
|
||||||
DeleteVpcOpts := &ec2.DeleteVPCRequest{
|
DeleteVpcOpts := &ec2.DeleteVPCInput{
|
||||||
VPCID: &vpcID,
|
VPCID: &vpcID,
|
||||||
}
|
}
|
||||||
log.Printf("[INFO] Deleting VPC: %s", d.Id())
|
log.Printf("[INFO] Deleting VPC: %s", d.Id())
|
||||||
if err := ec2conn.DeleteVPC(DeleteVpcOpts); err != nil {
|
if _, err := conn.DeleteVPC(DeleteVpcOpts); err != nil {
|
||||||
ec2err, ok := err.(aws.APIError)
|
ec2err, ok := err.(aws.APIError)
|
||||||
if ok && ec2err.Code == "InvalidVpcID.NotFound" {
|
if ok && ec2err.Code == "InvalidVpcID.NotFound" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -256,8 +256,8 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
// a VPC.
|
// a VPC.
|
||||||
func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
DescribeVpcOpts := &ec2.DescribeVPCsRequest{
|
DescribeVpcOpts := &ec2.DescribeVPCsInput{
|
||||||
VPCIDs: []string{id},
|
VPCIDs: []*string{aws.String(id)},
|
||||||
}
|
}
|
||||||
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -275,7 +275,7 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vpc := &resp.VPCs[0]
|
vpc := resp.VPCs[0]
|
||||||
return vpc, *vpc.State, nil
|
return vpc, *vpc.State, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,14 +283,14 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
||||||
func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error {
|
func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||||
filter1 := &ec2.Filter{
|
filter1 := &ec2.Filter{
|
||||||
Name: aws.String("default"),
|
Name: aws.String("default"),
|
||||||
Values: []string{("true")},
|
Values: []*string{aws.String("true")},
|
||||||
}
|
}
|
||||||
filter2 := &ec2.Filter{
|
filter2 := &ec2.Filter{
|
||||||
Name: aws.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
Values: []string{(d.Id())},
|
Values: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
DescribeNetworkACLOpts := &ec2.DescribeNetworkACLsRequest{
|
DescribeNetworkACLOpts := &ec2.DescribeNetworkACLsInput{
|
||||||
Filters: []ec2.Filter{*filter1, *filter2},
|
Filters: []*ec2.Filter{filter1, filter2},
|
||||||
}
|
}
|
||||||
networkAclResp, err := conn.DescribeNetworkACLs(DescribeNetworkACLOpts)
|
networkAclResp, err := conn.DescribeNetworkACLs(DescribeNetworkACLOpts)
|
||||||
|
|
||||||
|
@ -307,14 +307,14 @@ func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) e
|
||||||
func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error {
|
func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||||
filter1 := &ec2.Filter{
|
filter1 := &ec2.Filter{
|
||||||
Name: aws.String("group-name"),
|
Name: aws.String("group-name"),
|
||||||
Values: []string{("default")},
|
Values: []*string{aws.String("default")},
|
||||||
}
|
}
|
||||||
filter2 := &ec2.Filter{
|
filter2 := &ec2.Filter{
|
||||||
Name: aws.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
Values: []string{(d.Id())},
|
Values: []*string{aws.String(d.Id())},
|
||||||
}
|
}
|
||||||
DescribeSgOpts := &ec2.DescribeSecurityGroupsRequest{
|
DescribeSgOpts := &ec2.DescribeSecurityGroupsInput{
|
||||||
Filters: []ec2.Filter{*filter1, *filter2},
|
Filters: []*ec2.Filter{filter1, filter2},
|
||||||
}
|
}
|
||||||
securityGroupResp, err := conn.DescribeSecurityGroups(DescribeSgOpts)
|
securityGroupResp, err := conn.DescribeSecurityGroups(DescribeSgOpts)
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -41,16 +41,16 @@ func resourceAwsVpcPeeringConnection() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
// Create the vpc peering connection
|
// Create the vpc peering connection
|
||||||
createOpts := &ec2.CreateVPCPeeringConnectionRequest{
|
createOpts := &ec2.CreateVPCPeeringConnectionInput{
|
||||||
PeerOwnerID: aws.String(d.Get("peer_owner_id").(string)),
|
PeerOwnerID: aws.String(d.Get("peer_owner_id").(string)),
|
||||||
PeerVPCID: aws.String(d.Get("peer_vpc_id").(string)),
|
PeerVPCID: aws.String(d.Get("peer_vpc_id").(string)),
|
||||||
VPCID: aws.String(d.Get("vpc_id").(string)),
|
VPCID: aws.String(d.Get("vpc_id").(string)),
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] VpcPeeringCreate create config: %#v", createOpts)
|
log.Printf("[DEBUG] VpcPeeringCreate create config: %#v", createOpts)
|
||||||
resp, err := ec2conn.CreateVPCPeeringConnection(createOpts)
|
resp, err := conn.CreateVPCPeeringConnection(createOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating vpc peering connection: %s", err)
|
return fmt.Errorf("Error creating vpc peering connection: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"pending"},
|
Pending: []string{"pending"},
|
||||||
Target: "ready",
|
Target: "ready",
|
||||||
Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id()),
|
Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id()),
|
||||||
Timeout: 1 * time.Minute,
|
Timeout: 1 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -80,8 +80,8 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())()
|
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, 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", tagsToMap(pc.Tags))
|
d.Set("tags", tagsToMapSDK(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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
if err := setTags(ec2conn, d); err != nil {
|
if err := setTagsSDK(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("tags")
|
d.SetPartial("tags")
|
||||||
|
@ -113,10 +113,10 @@ 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).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
_, err := ec2conn.DeleteVPCPeeringConnection(
|
_, err := conn.DeleteVPCPeeringConnection(
|
||||||
&ec2.DeleteVPCPeeringConnectionRequest{
|
&ec2.DeleteVPCPeeringConnectionInput{
|
||||||
VPCPeeringConnectionID: aws.String(d.Id()),
|
VPCPeeringConnectionID: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
@ -127,8 +127,8 @@ func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
|
|
||||||
resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsRequest{
|
resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsInput{
|
||||||
VPCPeeringConnectionIDs: []string{id},
|
VPCPeeringConnectionIDs: []*string{aws.String(id)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcPeeringConnectionID.NotFound" {
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcPeeringConnectionID.NotFound" {
|
||||||
|
@ -145,7 +145,7 @@ func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pc := &resp.VPCPeeringConnections[0]
|
pc := resp.VPCPeeringConnections[0]
|
||||||
|
|
||||||
return pc, "ready", nil
|
return pc, "ready", nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
|
"github.com/awslabs/aws-sdk-go/service/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -42,8 +43,8 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe, err := conn.DescribeVPCPeeringConnections(
|
describe, err := conn.DescribeVPCPeeringConnections(
|
||||||
&ec2.DescribeVPCPeeringConnectionsRequest{
|
&ec2.DescribeVPCPeeringConnectionsInput{
|
||||||
VPCPeeringConnectionIDs: []string{rs.Primary.ID},
|
VPCPeeringConnectionIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -4,8 +4,8 @@ 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/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -66,7 +66,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"),
|
||||||
testAccCheckTags(&vpc.Tags, "foo", "bar"),
|
testAccCheckTagsSDK(&vpc.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -74,8 +74,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),
|
||||||
testAccCheckTags(&vpc.Tags, "foo", ""),
|
testAccCheckTagsSDK(&vpc.Tags, "foo", ""),
|
||||||
testAccCheckTags(&vpc.Tags, "bar", "baz"),
|
testAccCheckTagsSDK(&vpc.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -120,8 +120,8 @@ func testAccCheckVpcDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the VPC
|
// Try to find the VPC
|
||||||
DescribeVpcOpts := &ec2.DescribeVPCsRequest{
|
DescribeVpcOpts := &ec2.DescribeVPCsInput{
|
||||||
VPCIDs: []string{rs.Primary.ID},
|
VPCIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
}
|
}
|
||||||
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -168,8 +168,8 @@ func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
DescribeVpcOpts := &ec2.DescribeVPCsRequest{
|
DescribeVpcOpts := &ec2.DescribeVPCsInput{
|
||||||
VPCIDs: []string{rs.Primary.ID},
|
VPCIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
}
|
}
|
||||||
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -179,7 +179,7 @@ func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc {
|
||||||
return fmt.Errorf("VPC not found")
|
return fmt.Errorf("VPC not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*vpc = resp.VPCs[0]
|
*vpc = *resp.VPCs[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -36,16 +36,16 @@ func resourceAwsVpnGateway() *schema.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
createOpts := &ec2.CreateVPNGatewayRequest{
|
createOpts := &ec2.CreateVPNGatewayInput{
|
||||||
AvailabilityZone: aws.String(d.Get("availability_zone").(string)),
|
AvailabilityZone: aws.String(d.Get("availability_zone").(string)),
|
||||||
Type: aws.String("ipsec.1"),
|
Type: aws.String("ipsec.1"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the VPN gateway
|
// Create the VPN gateway
|
||||||
log.Printf("[DEBUG] Creating VPN gateway")
|
log.Printf("[DEBUG] Creating VPN gateway")
|
||||||
resp, err := ec2conn.CreateVPNGateway(createOpts)
|
resp, err := conn.CreateVPNGateway(createOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating VPN gateway: %s", err)
|
return fmt.Errorf("Error creating VPN gateway: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -60,19 +60,28 @@ func resourceAwsVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
vpnGatewayRaw, _, err := vpnGatewayStateRefreshFunc(ec2conn, d.Id())()
|
resp, err := conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysInput{
|
||||||
|
VPNGatewayIDs: []*string{aws.String(d.Id())},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnGatewayID.NotFound" {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
log.Printf("[ERROR] Error finding VpnGateway: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if vpnGatewayRaw == nil {
|
|
||||||
|
vpnGateway := resp.VPNGateways[0]
|
||||||
|
if vpnGateway == nil {
|
||||||
// Seems we have lost our VPN gateway
|
// Seems we have lost our VPN gateway
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vpnGateway := vpnGatewayRaw.(*ec2.VPNGateway)
|
|
||||||
if len(vpnGateway.VPCAttachments) == 0 {
|
if len(vpnGateway.VPCAttachments) == 0 {
|
||||||
// Gateway exists but not attached to the VPC
|
// Gateway exists but not attached to the VPC
|
||||||
d.Set("vpc_id", "")
|
d.Set("vpc_id", "")
|
||||||
|
@ -80,7 +89,7 @@ func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("vpc_id", vpnGateway.VPCAttachments[0].VPCID)
|
d.Set("vpc_id", vpnGateway.VPCAttachments[0].VPCID)
|
||||||
}
|
}
|
||||||
d.Set("availability_zone", vpnGateway.AvailabilityZone)
|
d.Set("availability_zone", vpnGateway.AvailabilityZone)
|
||||||
d.Set("tags", tagsToMap(vpnGateway.Tags))
|
d.Set("tags", tagsToMapSDK(vpnGateway.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -98,9 +107,9 @@ func resourceAwsVpnGatewayUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
if err := setTags(ec2conn, d); err != nil {
|
if err := setTagsSDK(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,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 {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
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 {
|
||||||
|
@ -120,7 +129,7 @@ func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
log.Printf("[INFO] Deleting VPN gateway: %s", d.Id())
|
log.Printf("[INFO] Deleting VPN gateway: %s", d.Id())
|
||||||
|
|
||||||
return resource.Retry(5*time.Minute, func() error {
|
return resource.Retry(5*time.Minute, func() error {
|
||||||
err := ec2conn.DeleteVPNGateway(&ec2.DeleteVPNGatewayRequest{
|
_, err := conn.DeleteVPNGateway(&ec2.DeleteVPNGatewayInput{
|
||||||
VPNGatewayID: aws.String(d.Id()),
|
VPNGatewayID: aws.String(d.Id()),
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -144,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 {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
if d.Get("vpc_id").(string) == "" {
|
if d.Get("vpc_id").(string) == "" {
|
||||||
log.Printf(
|
log.Printf(
|
||||||
|
@ -158,7 +167,7 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error
|
||||||
d.Id(),
|
d.Id(),
|
||||||
d.Get("vpc_id").(string))
|
d.Get("vpc_id").(string))
|
||||||
|
|
||||||
_, err := ec2conn.AttachVPNGateway(&ec2.AttachVPNGatewayRequest{
|
_, err := conn.AttachVPNGateway(&ec2.AttachVPNGatewayInput{
|
||||||
VPNGatewayID: aws.String(d.Id()),
|
VPNGatewayID: aws.String(d.Id()),
|
||||||
VPCID: aws.String(d.Get("vpc_id").(string)),
|
VPCID: aws.String(d.Get("vpc_id").(string)),
|
||||||
})
|
})
|
||||||
|
@ -176,7 +185,7 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"detached", "attaching"},
|
Pending: []string{"detached", "attaching"},
|
||||||
Target: "available",
|
Target: "available",
|
||||||
Refresh: VpnGatewayAttachStateRefreshFunc(ec2conn, d.Id(), "available"),
|
Refresh: vpnGatewayAttachStateRefreshFunc(conn, d.Id(), "available"),
|
||||||
Timeout: 1 * time.Minute,
|
Timeout: 1 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -189,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 {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
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")
|
||||||
|
@ -207,7 +216,7 @@ func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error
|
||||||
vpcID.(string))
|
vpcID.(string))
|
||||||
|
|
||||||
wait := true
|
wait := true
|
||||||
err := ec2conn.DetachVPNGateway(&ec2.DetachVPNGatewayRequest{
|
_, err := conn.DetachVPNGateway(&ec2.DetachVPNGatewayInput{
|
||||||
VPNGatewayID: aws.String(d.Id()),
|
VPNGatewayID: aws.String(d.Id()),
|
||||||
VPCID: aws.String(d.Get("vpc_id").(string)),
|
VPCID: aws.String(d.Get("vpc_id").(string)),
|
||||||
})
|
})
|
||||||
|
@ -237,7 +246,7 @@ func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"attached", "detaching", "available"},
|
Pending: []string{"attached", "detaching", "available"},
|
||||||
Target: "detached",
|
Target: "detached",
|
||||||
Refresh: VpnGatewayAttachStateRefreshFunc(ec2conn, d.Id(), "detached"),
|
Refresh: vpnGatewayAttachStateRefreshFunc(conn, d.Id(), "detached"),
|
||||||
Timeout: 1 * time.Minute,
|
Timeout: 1 * time.Minute,
|
||||||
}
|
}
|
||||||
if _, err := stateConf.WaitForState(); err != nil {
|
if _, err := stateConf.WaitForState(); err != nil {
|
||||||
|
@ -249,43 +258,17 @@ func resourceAwsVpnGatewayDetach(d *schema.ResourceData, meta interface{}) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// vpnGatewayStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch a VPNGateway.
|
// vpnGatewayAttachStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
|
||||||
func vpnGatewayStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
|
||||||
return func() (interface{}, string, error) {
|
|
||||||
resp, err := conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysRequest{
|
|
||||||
VPNGatewayIDs: []string{id},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnGatewayID.NotFound" {
|
|
||||||
resp = nil
|
|
||||||
} else {
|
|
||||||
log.Printf("[ERROR] Error on VpnGatewayStateRefresh: %s", err)
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp == nil {
|
|
||||||
// Sometimes AWS just has consistency issues and doesn't see
|
|
||||||
// our instance yet. Return an empty state.
|
|
||||||
return nil, "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
vpnGateway := &resp.VPNGateways[0]
|
|
||||||
return vpnGateway, *vpnGateway.State, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// VpnGatewayAttachStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
|
|
||||||
// the state of a VPN gateway's attachment
|
// the state of a VPN gateway's attachment
|
||||||
func VpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) resource.StateRefreshFunc {
|
func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) resource.StateRefreshFunc {
|
||||||
var start time.Time
|
var start time.Time
|
||||||
return func() (interface{}, string, error) {
|
return func() (interface{}, string, error) {
|
||||||
if start.IsZero() {
|
if start.IsZero() {
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysRequest{
|
resp, err := conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysInput{
|
||||||
VPNGatewayIDs: []string{id},
|
VPNGatewayIDs: []*string{aws.String(id)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnGatewayID.NotFound" {
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpnGatewayID.NotFound" {
|
||||||
|
@ -302,7 +285,7 @@ func VpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string)
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vpnGateway := &resp.VPNGateways[0]
|
vpnGateway := resp.VPNGateways[0]
|
||||||
|
|
||||||
if time.Now().Sub(start) > 10*time.Second {
|
if time.Now().Sub(start) > 10*time.Second {
|
||||||
return vpnGateway, expected, nil
|
return vpnGateway, expected, nil
|
||||||
|
|
|
@ -4,13 +4,13 @@ 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/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSVpnGateway(t *testing.T) {
|
func TestAccAWSVpnGateway_basic(t *testing.T) {
|
||||||
var v, v2 ec2.VPNGateway
|
var v, v2 ec2.VPNGateway
|
||||||
|
|
||||||
testNotEqual := func(*terraform.State) error {
|
testNotEqual := func(*terraform.State) error {
|
||||||
|
@ -98,7 +98,7 @@ func TestAccVpnGateway_tags(t *testing.T) {
|
||||||
Config: testAccCheckVpnGatewayConfigTags,
|
Config: testAccCheckVpnGatewayConfigTags,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v),
|
testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v),
|
||||||
testAccCheckTags(&v.Tags, "foo", "bar"),
|
testAccCheckTagsSDK(&v.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ func TestAccVpnGateway_tags(t *testing.T) {
|
||||||
Config: testAccCheckVpnGatewayConfigTagsUpdate,
|
Config: testAccCheckVpnGatewayConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v),
|
testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v),
|
||||||
testAccCheckTags(&v.Tags, "foo", ""),
|
testAccCheckTagsSDK(&v.Tags, "foo", ""),
|
||||||
testAccCheckTags(&v.Tags, "bar", "baz"),
|
testAccCheckTagsSDK(&v.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -123,8 +123,8 @@ func testAccCheckVpnGatewayDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the resource
|
// Try to find the resource
|
||||||
resp, err := ec2conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysRequest{
|
resp, err := ec2conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysInput{
|
||||||
VPNGatewayIDs: []string{rs.Primary.ID},
|
VPNGatewayIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(resp.VPNGateways) > 0 {
|
if len(resp.VPNGateways) > 0 {
|
||||||
|
@ -159,8 +159,8 @@ func testAccCheckVpnGatewayExists(n string, ig *ec2.VPNGateway) resource.TestChe
|
||||||
}
|
}
|
||||||
|
|
||||||
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
resp, err := ec2conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysRequest{
|
resp, err := ec2conn.DescribeVPNGateways(&ec2.DescribeVPNGatewaysInput{
|
||||||
VPNGatewayIDs: []string{rs.Primary.ID},
|
VPNGatewayIDs: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -169,7 +169,7 @@ func testAccCheckVpnGatewayExists(n string, ig *ec2.VPNGateway) resource.TestChe
|
||||||
return fmt.Errorf("VPNGateway not found")
|
return fmt.Errorf("VPNGateway not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
*ig = resp.VPNGateways[0]
|
*ig = *resp.VPNGateways[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/xml"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +20,7 @@ func setTagsS3(conn *s3.S3, 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)
|
||||||
err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingRequest{
|
_, err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{
|
||||||
Bucket: aws.String(d.Get("bucket").(string)),
|
Bucket: aws.String(d.Get("bucket").(string)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,30 +29,14 @@ func setTagsS3(conn *s3.S3, 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)
|
||||||
tagging := s3.Tagging{
|
req := &s3.PutBucketTaggingInput{
|
||||||
TagSet: create,
|
Bucket: aws.String(d.Get("bucket").(string)),
|
||||||
XMLName: xml.Name{
|
Tagging: &s3.Tagging{
|
||||||
Space: "http://s3.amazonaws.com/doc/2006-03-01/",
|
TagSet: create,
|
||||||
Local: "Tagging",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// AWS S3 API requires us to send a base64 encoded md5 hash of the
|
|
||||||
// content, which we need to build ourselves since aws-sdk-go does not.
|
|
||||||
b, err := xml.Marshal(tagging)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
h := md5.New()
|
|
||||||
h.Write(b)
|
|
||||||
base := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
|
||||||
|
|
||||||
req := &s3.PutBucketTaggingRequest{
|
_, err := conn.PutBucketTagging(req)
|
||||||
Bucket: aws.String(d.Get("bucket").(string)),
|
|
||||||
ContentMD5: aws.String(base),
|
|
||||||
Tagging: &tagging,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = conn.PutBucketTagging(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -68,7 +49,7 @@ func setTagsS3(conn *s3.S3, 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 diffTagsS3(oldTags, newTags []s3.Tag) ([]s3.Tag, []s3.Tag) {
|
func diffTagsS3(oldTags, newTags []*s3.Tag) ([]*s3.Tag, []*s3.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 {
|
||||||
|
@ -76,7 +57,7 @@ func diffTagsS3(oldTags, newTags []s3.Tag) ([]s3.Tag, []s3.Tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of what to remove
|
// Build the list of what to remove
|
||||||
var remove []s3.Tag
|
var remove []*s3.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 {
|
||||||
|
@ -89,10 +70,10 @@ func diffTagsS3(oldTags, newTags []s3.Tag) ([]s3.Tag, []s3.Tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsFromMap returns the tags for the given map of data.
|
// tagsFromMap returns the tags for the given map of data.
|
||||||
func tagsFromMapS3(m map[string]interface{}) []s3.Tag {
|
func tagsFromMapS3(m map[string]interface{}) []*s3.Tag {
|
||||||
result := make([]s3.Tag, 0, len(m))
|
result := make([]*s3.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
result = append(result, s3.Tag{
|
result = append(result, &s3.Tag{
|
||||||
Key: aws.String(k),
|
Key: aws.String(k),
|
||||||
Value: aws.String(v.(string)),
|
Value: aws.String(v.(string)),
|
||||||
})
|
})
|
||||||
|
@ -102,7 +83,7 @@ func tagsFromMapS3(m map[string]interface{}) []s3.Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsToMap turns the list of tags into a map.
|
// tagsToMap turns the list of tags into a map.
|
||||||
func tagsToMapS3(ts []s3.Tag) map[string]string {
|
func tagsToMapS3(ts []*s3.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
|
||||||
|
@ -114,15 +95,15 @@ func tagsToMapS3(ts []s3.Tag) map[string]string {
|
||||||
// return a slice of s3 tags associated with the given s3 bucket. Essentially
|
// return a slice of s3 tags associated with the given s3 bucket. Essentially
|
||||||
// s3.GetBucketTagging, except returns an empty slice instead of an error when
|
// s3.GetBucketTagging, except returns an empty slice instead of an error when
|
||||||
// there are no tags.
|
// there are no tags.
|
||||||
func getTagSetS3(s3conn *s3.S3, bucket string) ([]s3.Tag, error) {
|
func getTagSetS3(s3conn *s3.S3, bucket string) ([]*s3.Tag, error) {
|
||||||
request := &s3.GetBucketTaggingRequest{
|
request := &s3.GetBucketTaggingInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s3conn.GetBucketTagging(request)
|
response, err := s3conn.GetBucketTagging(request)
|
||||||
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "NoSuchTagSet" {
|
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "NoSuchTagSet" {
|
||||||
// There is no tag set associated with the bucket.
|
// There is no tag set associated with the bucket.
|
||||||
return []s3.Tag{}, nil
|
return []*s3.Tag{}, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/s3"
|
"github.com/awslabs/aws-sdk-go/service/s3"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,7 @@ func TestDiffTagsS3(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 testAccCheckTagsS3(
|
func testAccCheckTagsS3(
|
||||||
ts *[]s3.Tag, key string, value string) resource.TestCheckFunc {
|
ts *[]*s3.Tag, key string, value string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
m := tagsToMapS3(*ts)
|
m := tagsToMapS3(*ts)
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
|
|
|
@ -4,28 +4,30 @@ import (
|
||||||
"fmt"
|
"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/hashicorp/aws-sdk-go/gen/route53"
|
"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)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,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
|
||||||
|
@ -70,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),
|
||||||
}
|
}
|
||||||
|
@ -91,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
|
||||||
|
@ -105,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)),
|
||||||
|
@ -143,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)
|
||||||
|
@ -152,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)
|
||||||
|
@ -161,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{}{
|
||||||
|
@ -189,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{}{
|
||||||
|
@ -202,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
|
||||||
|
@ -221,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
|
||||||
|
@ -231,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)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +256,7 @@ func flattenAttachment(a *ec2.NetworkInterfaceAttachment) map[string]interface{}
|
||||||
return att
|
return att
|
||||||
}
|
}
|
||||||
|
|
||||||
func flattenResourceRecords(recs []route53.ResourceRecord) []string {
|
func flattenResourceRecords(recs []*route53.ResourceRecord) []string {
|
||||||
strs := make([]string, 0, len(recs))
|
strs := make([]string, 0, len(recs))
|
||||||
for _, r := range recs {
|
for _, r := range recs {
|
||||||
if r.Value != nil {
|
if r.Value != nil {
|
||||||
|
@ -265,16 +267,16 @@ func flattenResourceRecords(recs []route53.ResourceRecord) []string {
|
||||||
return strs
|
return strs
|
||||||
}
|
}
|
||||||
|
|
||||||
func expandResourceRecords(recs []interface{}, typeStr string) []route53.ResourceRecord {
|
func expandResourceRecords(recs []interface{}, typeStr string) []*route53.ResourceRecord {
|
||||||
records := make([]route53.ResourceRecord, 0, len(recs))
|
records := make([]*route53.ResourceRecord, 0, len(recs))
|
||||||
for _, r := range recs {
|
for _, r := range recs {
|
||||||
s := r.(string)
|
s := r.(string)
|
||||||
switch typeStr {
|
switch typeStr {
|
||||||
case "TXT":
|
case "TXT":
|
||||||
str := fmt.Sprintf("\"%s\"", s)
|
str := fmt.Sprintf("\"%s\"", s)
|
||||||
records = append(records, route53.ResourceRecord{Value: aws.String(str)})
|
records = append(records, &route53.ResourceRecord{Value: aws.String(str)})
|
||||||
default:
|
default:
|
||||||
records = append(records, route53.ResourceRecord{Value: aws.String(s)})
|
records = append(records, &route53.ResourceRecord{Value: aws.String(s)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return records
|
return records
|
||||||
|
|
|
@ -1,255 +0,0 @@
|
||||||
package aws
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/awslabs/aws-sdk-go/aws"
|
|
||||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
|
||||||
"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 := data["instance_port"].(int)
|
|
||||||
lp := 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{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
|
|
||||||
}
|
|
|
@ -1,444 +0,0 @@
|
||||||
package aws
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/awslabs/aws-sdk-go/service/ec2"
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
|
||||||
"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(1),
|
|
||||||
ToPort: aws.Long(-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(1),
|
|
||||||
ToPort: aws.Long(-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(1),
|
|
||||||
ToPort: aws.Long(-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(1),
|
|
||||||
ToPort: aws.Long(-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.Integer(8000),
|
|
||||||
LoadBalancerPort: aws.Integer(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.Integer(10),
|
|
||||||
HealthyThreshold: aws.Integer(10),
|
|
||||||
Target: aws.String("HTTP:80/"),
|
|
||||||
Timeout: aws.Integer(30),
|
|
||||||
Interval: aws.Integer(30),
|
|
||||||
},
|
|
||||||
Output: []map[string]interface{}{
|
|
||||||
map[string]interface{}{
|
|
||||||
"unhealthy_threshold": 10,
|
|
||||||
"healthy_threshold": 10,
|
|
||||||
"target": "HTTP:80/",
|
|
||||||
"timeout": 30,
|
|
||||||
"interval": 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{aws.String("test-one")},
|
|
||||||
elb.Instance{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(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"])
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,11 +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/hashicorp/aws-sdk-go/gen/route53"
|
"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"
|
||||||
|
@ -37,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))
|
||||||
}
|
}
|
||||||
|
@ -60,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"),
|
||||||
}
|
}
|
||||||
|
@ -69,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"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -143,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)
|
||||||
|
@ -151,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"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -193,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,
|
||||||
|
@ -207,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"),
|
||||||
}
|
}
|
||||||
|
@ -223,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)
|
||||||
}
|
}
|
||||||
|
@ -259,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) {
|
||||||
|
@ -273,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",
|
||||||
|
@ -286,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"),
|
||||||
|
@ -300,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"),
|
||||||
},
|
},
|
||||||
|
@ -329,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{}{
|
||||||
|
@ -348,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)
|
||||||
|
@ -373,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)
|
||||||
|
@ -394,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"
|
||||||
|
@ -418,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"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,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"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,11 +445,11 @@ func TestFlattenAttachment(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlattenResourceRecords(t *testing.T) {
|
func TestFlattenResourceRecords(t *testing.T) {
|
||||||
expanded := []route53.ResourceRecord{
|
expanded := []*route53.ResourceRecord{
|
||||||
route53.ResourceRecord{
|
&route53.ResourceRecord{
|
||||||
Value: aws.String("127.0.0.1"),
|
Value: aws.String("127.0.0.1"),
|
||||||
},
|
},
|
||||||
route53.ResourceRecord{
|
&route53.ResourceRecord{
|
||||||
Value: aws.String("127.0.0.3"),
|
Value: aws.String("127.0.0.3"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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/elb"
|
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ func setTagsELB(conn *elb.ELB, 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)
|
||||||
k := make([]elb.TagKeyOnly, 0, len(remove))
|
k := make([]*elb.TagKeyOnly, 0, len(remove))
|
||||||
for _, t := range remove {
|
for _, t := range remove {
|
||||||
k = append(k, elb.TagKeyOnly{Key: t.Key})
|
k = append(k, &elb.TagKeyOnly{Key: t.Key})
|
||||||
}
|
}
|
||||||
_, err := conn.RemoveTags(&elb.RemoveTagsInput{
|
_, err := conn.RemoveTags(&elb.RemoveTagsInput{
|
||||||
LoadBalancerNames: []string{d.Get("name").(string)},
|
LoadBalancerNames: []*string{aws.String(d.Get("name").(string))},
|
||||||
Tags: k,
|
Tags: k,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,7 +35,7 @@ func setTagsELB(conn *elb.ELB, 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.AddTags(&elb.AddTagsInput{
|
_, err := conn.AddTags(&elb.AddTagsInput{
|
||||||
LoadBalancerNames: []string{d.Get("name").(string)},
|
LoadBalancerNames: []*string{aws.String(d.Get("name").(string))},
|
||||||
Tags: create,
|
Tags: create,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ func setTagsELB(conn *elb.ELB, 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 diffTagsELB(oldTags, newTags []elb.Tag) ([]elb.Tag, []elb.Tag) {
|
func diffTagsELB(oldTags, newTags []*elb.Tag) ([]*elb.Tag, []*elb.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 {
|
||||||
|
@ -58,7 +58,7 @@ func diffTagsELB(oldTags, newTags []elb.Tag) ([]elb.Tag, []elb.Tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of what to remove
|
// Build the list of what to remove
|
||||||
var remove []elb.Tag
|
var remove []*elb.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 {
|
||||||
|
@ -71,10 +71,10 @@ func diffTagsELB(oldTags, newTags []elb.Tag) ([]elb.Tag, []elb.Tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsFromMap returns the tags for the given map of data.
|
// tagsFromMap returns the tags for the given map of data.
|
||||||
func tagsFromMapELB(m map[string]interface{}) []elb.Tag {
|
func tagsFromMapELB(m map[string]interface{}) []*elb.Tag {
|
||||||
result := make([]elb.Tag, 0, len(m))
|
result := make([]*elb.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
result = append(result, elb.Tag{
|
result = append(result, &elb.Tag{
|
||||||
Key: aws.String(k),
|
Key: aws.String(k),
|
||||||
Value: aws.String(v.(string)),
|
Value: aws.String(v.(string)),
|
||||||
})
|
})
|
||||||
|
@ -84,7 +84,7 @@ func tagsFromMapELB(m map[string]interface{}) []elb.Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsToMap turns the list of tags into a map.
|
// tagsToMap turns the list of tags into a map.
|
||||||
func tagsToMapELB(ts []elb.Tag) map[string]string {
|
func tagsToMapELB(ts []*elb.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
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/elb"
|
"github.com/awslabs/aws-sdk-go/service/elb"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,7 @@ func TestDiffELBTags(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 testAccCheckELBTags(
|
func testAccCheckELBTags(
|
||||||
ts *[]elb.Tag, key string, value string) resource.TestCheckFunc {
|
ts *[]*elb.Tag, key string, value string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
m := tagsToMapELB(*ts)
|
m := tagsToMapELB(*ts)
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
|
|
|
@ -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/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ func setTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) 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)
|
||||||
k := make([]string, len(remove), len(remove))
|
k := make([]*string, len(remove), len(remove))
|
||||||
for i, t := range remove {
|
for i, t := range remove {
|
||||||
k[i] = *t.Key
|
k[i] = t.Key
|
||||||
}
|
}
|
||||||
|
|
||||||
err := conn.RemoveTagsFromResource(&rds.RemoveTagsFromResourceMessage{
|
_, err := conn.RemoveTagsFromResource(&rds.RemoveTagsFromResourceInput{
|
||||||
ResourceName: aws.String(arn),
|
ResourceName: aws.String(arn),
|
||||||
TagKeys: k,
|
TagKeys: k,
|
||||||
})
|
})
|
||||||
|
@ -35,7 +35,7 @@ func setTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) 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.AddTagsToResource(&rds.AddTagsToResourceMessage{
|
_, err := conn.AddTagsToResource(&rds.AddTagsToResourceInput{
|
||||||
ResourceName: aws.String(arn),
|
ResourceName: aws.String(arn),
|
||||||
Tags: create,
|
Tags: create,
|
||||||
})
|
})
|
||||||
|
@ -51,7 +51,7 @@ func setTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) 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 diffTagsRDS(oldTags, newTags []rds.Tag) ([]rds.Tag, []rds.Tag) {
|
func diffTagsRDS(oldTags, newTags []*rds.Tag) ([]*rds.Tag, []*rds.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 {
|
||||||
|
@ -59,7 +59,7 @@ func diffTagsRDS(oldTags, newTags []rds.Tag) ([]rds.Tag, []rds.Tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of what to remove
|
// Build the list of what to remove
|
||||||
var remove []rds.Tag
|
var remove []*rds.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,10 +72,10 @@ func diffTagsRDS(oldTags, newTags []rds.Tag) ([]rds.Tag, []rds.Tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsFromMap returns the tags for the given map of data.
|
// tagsFromMap returns the tags for the given map of data.
|
||||||
func tagsFromMapRDS(m map[string]interface{}) []rds.Tag {
|
func tagsFromMapRDS(m map[string]interface{}) []*rds.Tag {
|
||||||
result := make([]rds.Tag, 0, len(m))
|
result := make([]*rds.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
result = append(result, rds.Tag{
|
result = append(result, &rds.Tag{
|
||||||
Key: aws.String(k),
|
Key: aws.String(k),
|
||||||
Value: aws.String(v.(string)),
|
Value: aws.String(v.(string)),
|
||||||
})
|
})
|
||||||
|
@ -85,7 +85,7 @@ func tagsFromMapRDS(m map[string]interface{}) []rds.Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsToMap turns the list of tags into a map.
|
// tagsToMap turns the list of tags into a map.
|
||||||
func tagsToMapRDS(ts []rds.Tag) map[string]string {
|
func tagsToMapRDS(ts []*rds.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
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
"github.com/awslabs/aws-sdk-go/service/rds"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -63,9 +63,9 @@ func TestDiffRDSTags(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 testAccCheckRDSTags(
|
func testAccCheckRDSTags(
|
||||||
ts *[]rds.Tag, key string, value string) resource.TestCheckFunc {
|
ts []*rds.Tag, key string, value string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
m := tagsToMapRDS(*ts)
|
m := tagsToMapRDS(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)
|
||||||
|
|
|
@ -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/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,16 +18,21 @@ func setTagsR53(conn *route53.Route53, d *schema.ResourceData) error {
|
||||||
create, remove := diffTagsR53(tagsFromMapR53(o), tagsFromMapR53(n))
|
create, remove := diffTagsR53(tagsFromMapR53(o), tagsFromMapR53(n))
|
||||||
|
|
||||||
// Set tags
|
// Set tags
|
||||||
r := make([]string, len(remove))
|
r := make([]*string, len(remove))
|
||||||
for i, t := range remove {
|
for i, t := range remove {
|
||||||
r[i] = *t.Key
|
r[i] = t.Key
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] Changing tags: \n\tadding: %#v\n\tremoving:%#v", create, remove)
|
log.Printf("[DEBUG] Changing tags: \n\tadding: %#v\n\tremoving:%#v", create, remove)
|
||||||
req := &route53.ChangeTagsForResourceRequest{
|
req := &route53.ChangeTagsForResourceInput{
|
||||||
AddTags: create,
|
ResourceID: aws.String(d.Id()),
|
||||||
RemoveTagKeys: r,
|
ResourceType: aws.String("hostedzone"),
|
||||||
ResourceID: aws.String(d.Id()),
|
}
|
||||||
ResourceType: aws.String("hostedzone"),
|
|
||||||
|
if len(create) > 0 {
|
||||||
|
req.AddTags = create
|
||||||
|
}
|
||||||
|
if len(r) > 0 {
|
||||||
|
req.RemoveTagKeys = r
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.ChangeTagsForResource(req)
|
_, err := conn.ChangeTagsForResource(req)
|
||||||
|
@ -42,7 +47,7 @@ func setTagsR53(conn *route53.Route53, 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 diffTagsR53(oldTags, newTags []route53.Tag) ([]route53.Tag, []route53.Tag) {
|
func diffTagsR53(oldTags, newTags []*route53.Tag) ([]*route53.Tag, []*route53.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 {
|
||||||
|
@ -50,7 +55,7 @@ func diffTagsR53(oldTags, newTags []route53.Tag) ([]route53.Tag, []route53.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of what to remove
|
// Build the list of what to remove
|
||||||
var remove []route53.Tag
|
var remove []*route53.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 {
|
||||||
|
@ -63,10 +68,10 @@ func diffTagsR53(oldTags, newTags []route53.Tag) ([]route53.Tag, []route53.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsFromMap returns the tags for the given map of data.
|
// tagsFromMap returns the tags for the given map of data.
|
||||||
func tagsFromMapR53(m map[string]interface{}) []route53.Tag {
|
func tagsFromMapR53(m map[string]interface{}) []*route53.Tag {
|
||||||
result := make([]route53.Tag, 0, len(m))
|
result := make([]*route53.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
result = append(result, route53.Tag{
|
result = append(result, &route53.Tag{
|
||||||
Key: aws.String(k),
|
Key: aws.String(k),
|
||||||
Value: aws.String(v.(string)),
|
Value: aws.String(v.(string)),
|
||||||
})
|
})
|
||||||
|
@ -76,7 +81,7 @@ func tagsFromMapR53(m map[string]interface{}) []route53.Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsToMap turns the list of tags into a map.
|
// tagsToMap turns the list of tags into a map.
|
||||||
func tagsToMapR53(ts []route53.Tag) map[string]string {
|
func tagsToMapR53(ts []*route53.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
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
"github.com/awslabs/aws-sdk-go/service/route53"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,7 @@ func TestDiffTagsR53(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 testAccCheckTagsR53(
|
func testAccCheckTagsR53(
|
||||||
ts *[]route53.Tag, key string, value string) resource.TestCheckFunc {
|
ts *[]*route53.Tag, key string, value string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
m := tagsToMapR53(*ts)
|
m := tagsToMapR53(*ts)
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -6,7 +6,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
// TODO(dcunnin): Use version code from version.go
|
||||||
|
// "github.com/hashicorp/terraform"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
"golang.org/x/oauth2/jwt"
|
"golang.org/x/oauth2/jwt"
|
||||||
|
@ -83,6 +86,17 @@ func (c *Config) loadAndValidate() error {
|
||||||
log.Printf("[INFO] Instantiating GCE client...")
|
log.Printf("[INFO] Instantiating GCE client...")
|
||||||
var err error
|
var err error
|
||||||
c.clientCompute, err = compute.New(client)
|
c.clientCompute, err = compute.New(client)
|
||||||
|
|
||||||
|
// Set UserAgent
|
||||||
|
versionString := "0.0.0"
|
||||||
|
// TODO(dcunnin): Use Terraform's version code from version.go
|
||||||
|
// versionString := main.Version
|
||||||
|
// if main.VersionPrerelease != "" {
|
||||||
|
// versionString = fmt.Sprintf("%s-%s", versionString, main.VersionPrerelease)
|
||||||
|
// }
|
||||||
|
c.clientCompute.UserAgent = fmt.Sprintf(
|
||||||
|
"(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, versionString)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ func resourceComputeInstance() *schema.Resource {
|
||||||
Update: resourceComputeInstanceUpdate,
|
Update: resourceComputeInstanceUpdate,
|
||||||
Delete: resourceComputeInstanceDelete,
|
Delete: resourceComputeInstanceDelete,
|
||||||
|
|
||||||
|
SchemaVersion: 1,
|
||||||
|
MigrateState: resourceComputeInstanceMigrateState,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -168,11 +171,9 @@ func resourceComputeInstance() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
"metadata": &schema.Schema{
|
"metadata": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeMap,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Schema{
|
Elem: schema.TypeString,
|
||||||
Type: schema.TypeMap,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"service_account": &schema.Schema{
|
"service_account": &schema.Schema{
|
||||||
|
@ -735,6 +736,7 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err
|
||||||
config := meta.(*Config)
|
config := meta.(*Config)
|
||||||
|
|
||||||
zone := d.Get("zone").(string)
|
zone := d.Get("zone").(string)
|
||||||
|
log.Printf("[INFO] Requesting instance deletion: %s", d.Id())
|
||||||
op, err := config.clientCompute.Instances.Delete(config.Project, zone, d.Id()).Do()
|
op, err := config.clientCompute.Instances.Delete(config.Project, zone, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error deleting instance: %s", err)
|
return fmt.Errorf("Error deleting instance: %s", err)
|
||||||
|
@ -751,32 +753,22 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceInstanceMetadata(d *schema.ResourceData) *compute.Metadata {
|
func resourceInstanceMetadata(d *schema.ResourceData) *compute.Metadata {
|
||||||
var metadata *compute.Metadata
|
m := &compute.Metadata{}
|
||||||
if metadataList := d.Get("metadata").([]interface{}); len(metadataList) > 0 {
|
if mdMap := d.Get("metadata").(map[string]interface{}); len(mdMap) > 0 {
|
||||||
m := new(compute.Metadata)
|
m.Items = make([]*compute.MetadataItems, 0, len(mdMap))
|
||||||
m.Items = make([]*compute.MetadataItems, 0, len(metadataList))
|
for key, val := range mdMap {
|
||||||
for _, metadataMap := range metadataList {
|
m.Items = append(m.Items, &compute.MetadataItems{
|
||||||
for key, val := range metadataMap.(map[string]interface{}) {
|
Key: key,
|
||||||
// TODO: fix https://github.com/hashicorp/terraform/issues/883
|
Value: val.(string),
|
||||||
// and remove this workaround <3 phinze
|
})
|
||||||
if key == "#" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
m.Items = append(m.Items, &compute.MetadataItems{
|
|
||||||
Key: key,
|
|
||||||
Value: val.(string),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the fingerprint. If the metadata has never been set before
|
// Set the fingerprint. If the metadata has never been set before
|
||||||
// then this will just be blank.
|
// then this will just be blank.
|
||||||
m.Fingerprint = d.Get("metadata_fingerprint").(string)
|
m.Fingerprint = d.Get("metadata_fingerprint").(string)
|
||||||
|
|
||||||
metadata = m
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadata
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceInstanceTags(d *schema.ResourceData) *compute.Tags {
|
func resourceInstanceTags(d *schema.ResourceData) *compute.Tags {
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resourceComputeInstanceMigrateState(
|
||||||
|
v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
|
||||||
|
if is.Empty() {
|
||||||
|
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
|
||||||
|
return is, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v {
|
||||||
|
case 0:
|
||||||
|
log.Println("[INFO] Found Compute Instance State v0; migrating to v1")
|
||||||
|
return migrateStateV0toV1(is)
|
||||||
|
default:
|
||||||
|
return is, fmt.Errorf("Unexpected schema version: %d", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func migrateStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||||
|
log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
|
||||||
|
|
||||||
|
// Delete old count
|
||||||
|
delete(is.Attributes, "metadata.#")
|
||||||
|
|
||||||
|
newMetadata := make(map[string]string)
|
||||||
|
|
||||||
|
for k, v := range is.Attributes {
|
||||||
|
if !strings.HasPrefix(k, "metadata.") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have a key that looks like "metadata.*" and we know it's not
|
||||||
|
// metadata.# because we deleted it above, so it must be metadata.<N>.<key>
|
||||||
|
// from the List of Maps. Just need to convert it to a single Map by
|
||||||
|
// ditching the '<N>' field.
|
||||||
|
kParts := strings.SplitN(k, ".", 3)
|
||||||
|
|
||||||
|
// Sanity check: all three parts should be there and <N> should be a number
|
||||||
|
badFormat := false
|
||||||
|
if len(kParts) != 3 {
|
||||||
|
badFormat = true
|
||||||
|
} else if _, err := strconv.Atoi(kParts[1]); err != nil {
|
||||||
|
badFormat = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if badFormat {
|
||||||
|
return is, fmt.Errorf(
|
||||||
|
"migration error: found metadata key in unexpected format: %s", k)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rejoin as "metadata.<key>"
|
||||||
|
newK := strings.Join([]string{kParts[0], kParts[2]}, ".")
|
||||||
|
newMetadata[newK] = v
|
||||||
|
delete(is.Attributes, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range newMetadata {
|
||||||
|
is.Attributes[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
|
||||||
|
return is, nil
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestComputeInstanceMigrateState(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
StateVersion int
|
||||||
|
Attributes map[string]string
|
||||||
|
Expected map[string]string
|
||||||
|
Meta interface{}
|
||||||
|
}{
|
||||||
|
"v0.4.2 and earlier": {
|
||||||
|
StateVersion: 0,
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"metadata.#": "2",
|
||||||
|
"metadata.0.foo": "bar",
|
||||||
|
"metadata.1.baz": "qux",
|
||||||
|
"metadata.2.with.dots": "should.work",
|
||||||
|
},
|
||||||
|
Expected: map[string]string{
|
||||||
|
"metadata.foo": "bar",
|
||||||
|
"metadata.baz": "qux",
|
||||||
|
"metadata.with.dots": "should.work",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range cases {
|
||||||
|
is := &terraform.InstanceState{
|
||||||
|
ID: "i-abc123",
|
||||||
|
Attributes: tc.Attributes,
|
||||||
|
}
|
||||||
|
is, err := resourceComputeInstanceMigrateState(
|
||||||
|
tc.StateVersion, is, tc.Meta)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("bad: %s, err: %#v", tn, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range tc.Expected {
|
||||||
|
if is.Attributes[k] != v {
|
||||||
|
t.Fatalf(
|
||||||
|
"bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v",
|
||||||
|
tn, k, v, k, is.Attributes[k], is.Attributes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestComputeInstanceMigrateState_empty(t *testing.T) {
|
||||||
|
var is *terraform.InstanceState
|
||||||
|
var meta interface{}
|
||||||
|
|
||||||
|
// should handle nil
|
||||||
|
is, err := resourceComputeInstanceMigrateState(0, is, meta)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %#v", err)
|
||||||
|
}
|
||||||
|
if is != nil {
|
||||||
|
t.Fatalf("expected nil instancestate, got: %#v", is)
|
||||||
|
}
|
||||||
|
|
||||||
|
// should handle non-nil but empty
|
||||||
|
is = &terraform.InstanceState{}
|
||||||
|
is, err = resourceComputeInstanceMigrateState(0, is, meta)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %#v", err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,6 +47,7 @@ func TestAccComputeInstance_basic(t *testing.T) {
|
||||||
"google_compute_instance.foobar", &instance),
|
"google_compute_instance.foobar", &instance),
|
||||||
testAccCheckComputeInstanceTag(&instance, "foo"),
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
||||||
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
||||||
|
testAccCheckComputeInstanceMetadata(&instance, "baz", "qux"),
|
||||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -168,6 +169,34 @@ func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
|
||||||
|
var instance compute.Instance
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeInstance_basic,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeInstanceExists(
|
||||||
|
"google_compute_instance.foobar", &instance),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeInstance_forceNewAndChangeMetadata,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeInstanceExists(
|
||||||
|
"google_compute_instance.foobar", &instance),
|
||||||
|
testAccCheckComputeInstanceMetadata(
|
||||||
|
&instance, "qux", "true"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccComputeInstance_update(t *testing.T) {
|
func TestAccComputeInstance_update(t *testing.T) {
|
||||||
var instance compute.Instance
|
var instance compute.Instance
|
||||||
|
|
||||||
|
@ -387,6 +416,9 @@ resource "google_compute_instance" "foobar" {
|
||||||
metadata {
|
metadata {
|
||||||
foo = "bar"
|
foo = "bar"
|
||||||
}
|
}
|
||||||
|
metadata {
|
||||||
|
baz = "qux"
|
||||||
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const testAccComputeInstance_basic2 = `
|
const testAccComputeInstance_basic2 = `
|
||||||
|
@ -432,6 +464,30 @@ resource "google_compute_instance" "foobar" {
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
// Update zone to ForceNew, and change metadata k/v entirely
|
||||||
|
// Generates diff mismatch
|
||||||
|
const testAccComputeInstance_forceNewAndChangeMetadata = `
|
||||||
|
resource "google_compute_instance" "foobar" {
|
||||||
|
name = "terraform-test"
|
||||||
|
machine_type = "n1-standard-1"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
zone = "us-central1-b"
|
||||||
|
tags = ["baz"]
|
||||||
|
|
||||||
|
disk {
|
||||||
|
image = "debian-7-wheezy-v20140814"
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = "default"
|
||||||
|
access_config { }
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata {
|
||||||
|
qux = "true"
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
// Update metadata, tags, and network_interface
|
// Update metadata, tags, and network_interface
|
||||||
const testAccComputeInstance_update = `
|
const testAccComputeInstance_update = `
|
||||||
resource "google_compute_instance" "foobar" {
|
resource "google_compute_instance" "foobar" {
|
||||||
|
|
|
@ -8,6 +8,7 @@ func canonicalizeServiceScope(scope string) string {
|
||||||
"compute-ro": "https://www.googleapis.com/auth/compute.readonly",
|
"compute-ro": "https://www.googleapis.com/auth/compute.readonly",
|
||||||
"compute-rw": "https://www.googleapis.com/auth/compute",
|
"compute-rw": "https://www.googleapis.com/auth/compute",
|
||||||
"datastore": "https://www.googleapis.com/auth/datastore",
|
"datastore": "https://www.googleapis.com/auth/datastore",
|
||||||
|
"logging-write": "https://www.googleapis.com/auth/logging.write",
|
||||||
"sql": "https://www.googleapis.com/auth/sqlservice",
|
"sql": "https://www.googleapis.com/auth/sqlservice",
|
||||||
"sql-admin": "https://www.googleapis.com/auth/sqlservice.admin",
|
"sql-admin": "https://www.googleapis.com/auth/sqlservice.admin",
|
||||||
"storage-full": "https://www.googleapis.com/auth/devstorage.full_control",
|
"storage-full": "https://www.googleapis.com/auth/devstorage.full_control",
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package openstack
|
package openstack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/rackspace/gophercloud"
|
"github.com/rackspace/gophercloud"
|
||||||
"github.com/rackspace/gophercloud/openstack"
|
"github.com/rackspace/gophercloud/openstack"
|
||||||
)
|
)
|
||||||
|
@ -15,6 +18,7 @@ type Config struct {
|
||||||
TenantName string
|
TenantName string
|
||||||
DomainID string
|
DomainID string
|
||||||
DomainName string
|
DomainName string
|
||||||
|
Insecure bool
|
||||||
|
|
||||||
osClient *gophercloud.ProviderClient
|
osClient *gophercloud.ProviderClient
|
||||||
}
|
}
|
||||||
|
@ -32,7 +36,19 @@ func (c *Config) loadAndValidate() error {
|
||||||
DomainName: c.DomainName,
|
DomainName: c.DomainName,
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := openstack.AuthenticatedClient(ao)
|
client, err := openstack.NewClient(ao.IdentityEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Insecure {
|
||||||
|
// Configure custom TLS settings.
|
||||||
|
config := &tls.Config{InsecureSkipVerify: true}
|
||||||
|
transport := &http.Transport{TLSClientConfig: config}
|
||||||
|
client.HTTPClient.Transport = transport
|
||||||
|
}
|
||||||
|
|
||||||
|
err = openstack.Authenticate(client, ao)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,11 @@ func Provider() terraform.ResourceProvider {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "",
|
Default: "",
|
||||||
},
|
},
|
||||||
|
"insecure": &schema.Schema{
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
|
@ -93,6 +98,7 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
|
||||||
TenantName: d.Get("tenant_name").(string),
|
TenantName: d.Get("tenant_name").(string),
|
||||||
DomainID: d.Get("domain_id").(string),
|
DomainID: d.Get("domain_id").(string),
|
||||||
DomainName: d.Get("domain_name").(string),
|
DomainName: d.Get("domain_name").(string),
|
||||||
|
Insecure: d.Get("insecure").(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.loadAndValidate(); err != nil {
|
if err := config.loadAndValidate(); err != nil {
|
||||||
|
@ -111,3 +117,10 @@ func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func envDefaultFuncAllowMissing(k string) schema.SchemaDefaultFunc {
|
||||||
|
return func() (interface{}, error) {
|
||||||
|
v := os.Getenv(k)
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,10 +40,9 @@ func testAccPreCheck(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
v = os.Getenv("OS_REGION_NAME")
|
v = os.Getenv("OS_REGION_NAME")
|
||||||
if v == "" {
|
if v != "" {
|
||||||
t.Fatal("OS_REGION_NAME must be set for acceptance tests")
|
OS_REGION_NAME = v
|
||||||
}
|
}
|
||||||
OS_REGION_NAME = v
|
|
||||||
|
|
||||||
v1 := os.Getenv("OS_IMAGE_ID")
|
v1 := os.Getenv("OS_IMAGE_ID")
|
||||||
v2 := os.Getenv("OS_IMAGE_NAME")
|
v2 := os.Getenv("OS_IMAGE_NAME")
|
||||||
|
|
|
@ -26,7 +26,7 @@ func resourceBlockStorageVolumeV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"size": &schema.Schema{
|
"size": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
|
|
@ -20,7 +20,7 @@ func resourceComputeFloatingIPV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
|
|
||||||
"pool": &schema.Schema{
|
"pool": &schema.Schema{
|
||||||
|
|
|
@ -36,7 +36,7 @@ func resourceComputeInstanceV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -19,7 +19,7 @@ func resourceComputeKeypairV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -23,7 +23,7 @@ func resourceComputeSecGroupV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -23,7 +23,7 @@ func resourceFWFirewallV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -23,7 +23,7 @@ func resourceFWPolicyV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -21,7 +21,7 @@ func resourceFWRuleV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -21,7 +21,7 @@ func resourceLBMonitorV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"tenant_id": &schema.Schema{
|
"tenant_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -24,7 +24,7 @@ func resourceLBPoolV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -61,7 +61,7 @@ func resourceLBPoolV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"tenant_id": &schema.Schema{
|
"tenant_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -22,7 +22,7 @@ func resourceLBVipV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -21,7 +21,7 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"address": &schema.Schema{
|
"address": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -21,7 +21,7 @@ func resourceNetworkingNetworkV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -21,7 +21,7 @@ func resourceNetworkingRouterInterfaceV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"router_id": &schema.Schema{
|
"router_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -22,7 +22,7 @@ func resourceNetworkingRouterV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -22,7 +22,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"network_id": &schema.Schema{
|
"network_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -20,7 +20,7 @@ func resourceObjectStorageContainerV1() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"),
|
||||||
},
|
},
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/config"
|
"github.com/hashicorp/terraform/helper/config"
|
||||||
helper "github.com/hashicorp/terraform/helper/ssh"
|
helper "github.com/hashicorp/terraform/helper/ssh"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"github.com/mitchellh/go-homedir"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResourceProvisioner struct{}
|
type ResourceProvisioner struct{}
|
||||||
|
@ -35,6 +36,11 @@ func (p *ResourceProvisioner) Apply(
|
||||||
return fmt.Errorf("Unsupported 'source' type! Must be string.")
|
return fmt.Errorf("Unsupported 'source' type! Must be string.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
src, err = homedir.Expand(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
dRaw := c.Config["destination"]
|
dRaw := c.Config["destination"]
|
||||||
dst, ok := dRaw.(string)
|
dst, ok := dRaw.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/errwrap"
|
"github.com/hashicorp/errwrap"
|
||||||
"github.com/hashicorp/terraform/state"
|
"github.com/hashicorp/terraform/state"
|
||||||
|
@ -208,7 +209,7 @@ func remoteState(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the remote client based on the local state
|
// Initialize the remote client based on the local state
|
||||||
client, err := remote.NewClient(local.Remote.Type, local.Remote.Config)
|
client, err := remote.NewClient(strings.ToLower(local.Remote.Type), local.Remote.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errwrap.Wrapf(fmt.Sprintf(
|
return nil, errwrap.Wrapf(fmt.Sprintf(
|
||||||
"Error initializing remote driver '%s': {{err}}",
|
"Error initializing remote driver '%s': {{err}}",
|
||||||
|
|
|
@ -290,6 +290,14 @@ func (c *Config) Validate() error {
|
||||||
raw[k] = strVal
|
raw[k] = strVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for invalid count variables
|
||||||
|
for _, v := range m.RawConfig.Variables {
|
||||||
|
if _, ok := v.(*CountVariable); ok {
|
||||||
|
errs = append(errs, fmt.Errorf(
|
||||||
|
"%s: count variables are only valid within resources", m.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update the raw configuration to only contain the string values
|
// Update the raw configuration to only contain the string values
|
||||||
m.RawConfig, err = NewRawConfig(raw)
|
m.RawConfig, err = NewRawConfig(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -472,6 +480,13 @@ func (c *Config) Validate() error {
|
||||||
errs = append(errs, fmt.Errorf(
|
errs = append(errs, fmt.Errorf(
|
||||||
"%s: output should only have 'value' field", o.Name))
|
"%s: output should only have 'value' field", o.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, v := range o.RawConfig.Variables {
|
||||||
|
if _, ok := v.(*CountVariable); ok {
|
||||||
|
errs = append(errs, fmt.Errorf(
|
||||||
|
"%s: count variables are only valid within resources", o.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all variables are in the proper context
|
// Check that all variables are in the proper context
|
||||||
|
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,6 +61,22 @@ func TestConfigValidate_countInt(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigValidate_countBadContext(t *testing.T) {
|
||||||
|
c := testConfig(t, "validate-count-bad-context")
|
||||||
|
|
||||||
|
err := c.Validate()
|
||||||
|
|
||||||
|
expected := []string{
|
||||||
|
"no_count_in_output: count variables are only valid within resources",
|
||||||
|
"no_count_in_module: count variables are only valid within resources",
|
||||||
|
}
|
||||||
|
for _, exp := range expected {
|
||||||
|
if !strings.Contains(err.Error(), exp) {
|
||||||
|
t.Fatalf("expected: %q,\nto contain: %q", err, exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigValidate_countCountVar(t *testing.T) {
|
func TestConfigValidate_countCountVar(t *testing.T) {
|
||||||
c := testConfig(t, "validate-count-count-var")
|
c := testConfig(t, "validate-count-count-var")
|
||||||
if err := c.Validate(); err == nil {
|
if err := c.Validate(); err == nil {
|
||||||
|
|
|
@ -23,6 +23,7 @@ func init() {
|
||||||
"element": interpolationFuncElement(),
|
"element": interpolationFuncElement(),
|
||||||
"replace": interpolationFuncReplace(),
|
"replace": interpolationFuncReplace(),
|
||||||
"split": interpolationFuncSplit(),
|
"split": interpolationFuncSplit(),
|
||||||
|
"length": interpolationFuncLength(),
|
||||||
|
|
||||||
// Concat is a little useless now since we supported embeddded
|
// Concat is a little useless now since we supported embeddded
|
||||||
// interpolations but we keep it around for backwards compat reasons.
|
// interpolations but we keep it around for backwards compat reasons.
|
||||||
|
@ -132,6 +133,28 @@ func interpolationFuncReplace() ast.Function {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func interpolationFuncLength() ast.Function {
|
||||||
|
return ast.Function{
|
||||||
|
ArgTypes: []ast.Type{ast.TypeString},
|
||||||
|
ReturnType: ast.TypeInt,
|
||||||
|
Variadic: false,
|
||||||
|
Callback: func(args []interface{}) (interface{}, error) {
|
||||||
|
if !strings.Contains(args[0].(string), InterpSplitDelim) {
|
||||||
|
return len(args[0].(string)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []string
|
||||||
|
for _, arg := range args {
|
||||||
|
parts := strings.Split(arg.(string), InterpSplitDelim)
|
||||||
|
for _, part := range parts {
|
||||||
|
list = append(list, part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(list), nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// interpolationFuncSplit implements the "split" function that allows
|
// interpolationFuncSplit implements the "split" function that allows
|
||||||
// strings to split into multi-variable values
|
// strings to split into multi-variable values
|
||||||
func interpolationFuncSplit() ast.Function {
|
func interpolationFuncSplit() ast.Function {
|
||||||
|
|
|
@ -183,6 +183,66 @@ func TestInterpolateFuncReplace(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInterpolateFuncLength(t *testing.T) {
|
||||||
|
testFunction(t, testFunctionConfig{
|
||||||
|
Cases: []testFunctionCase{
|
||||||
|
// Raw strings
|
||||||
|
{
|
||||||
|
`${length("")}`,
|
||||||
|
"0",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length("a")}`,
|
||||||
|
"1",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length(" ")}`,
|
||||||
|
"1",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length(" a ,")}`,
|
||||||
|
"4",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length("aaa")}`,
|
||||||
|
"3",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// Lists
|
||||||
|
{
|
||||||
|
`${length(split(",", "a"))}`,
|
||||||
|
"1",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length(split(",", "foo,"))}`,
|
||||||
|
"2",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length(split(",", ",foo,"))}`,
|
||||||
|
"3",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length(split(",", "foo,bar"))}`,
|
||||||
|
"2",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`${length(split(".", "one.two.three.four.five"))}`,
|
||||||
|
"5",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestInterpolateFuncSplit(t *testing.T) {
|
func TestInterpolateFuncSplit(t *testing.T) {
|
||||||
testFunction(t, testFunctionConfig{
|
testFunction(t, testFunctionConfig{
|
||||||
Cases: []testFunctionCase{
|
Cases: []testFunctionCase{
|
||||||
|
@ -198,6 +258,35 @@ func TestInterpolateFuncSplit(t *testing.T) {
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`${split(",", ",,,")}`,
|
||||||
|
fmt.Sprintf(
|
||||||
|
"%s%s%s",
|
||||||
|
InterpSplitDelim,
|
||||||
|
InterpSplitDelim,
|
||||||
|
InterpSplitDelim),
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`${split(",", "foo,")}`,
|
||||||
|
fmt.Sprintf(
|
||||||
|
"%s%s",
|
||||||
|
"foo",
|
||||||
|
InterpSplitDelim),
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`${split(",", ",foo,")}`,
|
||||||
|
fmt.Sprintf(
|
||||||
|
"%s%s%s",
|
||||||
|
InterpSplitDelim,
|
||||||
|
"foo",
|
||||||
|
InterpSplitDelim),
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`${split(".", "foo.bar.baz")}`,
|
`${split(".", "foo.bar.baz")}`,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
|
|
|
@ -100,20 +100,29 @@ func (tc *typeCheckArithmetic) TypeCheck(v *TypeCheck) (ast.Node, error) {
|
||||||
exprs[len(tc.n.Exprs)-1-i] = v.StackPop()
|
exprs[len(tc.n.Exprs)-1-i] = v.StackPop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the resulting type we want
|
// Determine the resulting type we want. We do this by going over
|
||||||
|
// every expression until we find one with a type we recognize.
|
||||||
|
// We do this because the first expr might be a string ("var.foo")
|
||||||
|
// and we need to know what to implicit to.
|
||||||
mathFunc := "__builtin_IntMath"
|
mathFunc := "__builtin_IntMath"
|
||||||
mathType := ast.TypeInt
|
mathType := ast.TypeInt
|
||||||
switch v := exprs[0]; v {
|
for _, v := range exprs {
|
||||||
case ast.TypeInt:
|
exit := true
|
||||||
mathFunc = "__builtin_IntMath"
|
switch v {
|
||||||
mathType = v
|
case ast.TypeInt:
|
||||||
case ast.TypeFloat:
|
mathFunc = "__builtin_IntMath"
|
||||||
mathFunc = "__builtin_FloatMath"
|
mathType = v
|
||||||
mathType = v
|
case ast.TypeFloat:
|
||||||
default:
|
mathFunc = "__builtin_FloatMath"
|
||||||
return nil, fmt.Errorf(
|
mathType = v
|
||||||
"Math operations can only be done with ints and floats, got %s",
|
default:
|
||||||
v)
|
exit = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// We found the type, so leave
|
||||||
|
if exit {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the args
|
// Verify the args
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue