providers/aws: VPC assignment fix, and dependencies for destroy

This commit is contained in:
Mitchell Hashimoto 2014-07-17 10:03:15 -07:00
parent c3229aaef1
commit 388bcfa7b4
2 changed files with 70 additions and 1 deletions

View File

@ -125,6 +125,7 @@ func resource_aws_security_group_diff(
"name": diff.AttrTypeCreate, "name": diff.AttrTypeCreate,
"description": diff.AttrTypeUpdate, "description": diff.AttrTypeUpdate,
"ingress": diff.AttrTypeUpdate, "ingress": diff.AttrTypeUpdate,
"vpc_id": diff.AttrTypeCreate,
}, },
ComputedAttrs: []string{ ComputedAttrs: []string{
@ -153,6 +154,13 @@ func resource_aws_security_group_update_state(
s.Attributes[k] = v s.Attributes[k] = v
} }
s.Dependencies = nil
if s.Attributes["vpc_id"] != "" {
s.Dependencies = append(s.Dependencies,
terraform.ResourceDependency{ID: s.Attributes["vpc_id"]},
)
}
return s, nil return s, nil
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
) )
func TestAccAWSSecurityGroup(t *testing.T) { func TestAccAWSSecurityGroup_normal(t *testing.T) {
var group ec2.SecurityGroupInfo var group ec2.SecurityGroupInfo
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
@ -43,6 +43,48 @@ func TestAccAWSSecurityGroup(t *testing.T) {
}) })
} }
func TestAccAWSSecurityGroup_vpc(t *testing.T) {
var group ec2.SecurityGroupInfo
testCheck := func(*terraform.State) error {
if group.VpcId == "" {
return fmt.Errorf("should have vpc ID")
}
return nil
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSSecurityGroupConfigVpc,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
testAccCheckAWSSecurityGroupAttributes(&group),
resource.TestCheckResourceAttr(
"aws_security_group.web", "name", "terraform_acceptance_test_example"),
resource.TestCheckResourceAttr(
"aws_security_group.web", "description", "Used in the terraform acceptance tests"),
resource.TestCheckResourceAttr(
"aws_security_group.web", "ingress.0.protocol", "tcp"),
resource.TestCheckResourceAttr(
"aws_security_group.web", "ingress.0.from_port", "80"),
resource.TestCheckResourceAttr(
"aws_security_group.web", "ingress.0.to_port", "8000"),
resource.TestCheckResourceAttr(
"aws_security_group.web", "ingress.0.cidr_blocks.#", "1"),
resource.TestCheckResourceAttr(
"aws_security_group.web", "ingress.0.cidr_blocks.0", "10.0.0.0/0"),
testCheck,
),
},
},
})
}
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error { func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
@ -157,3 +199,22 @@ resource "aws_security_group" "web" {
} }
} }
` `
const testAccAWSSecurityGroupConfigVpc = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_security_group" "web" {
name = "terraform_acceptance_test_example"
description = "Used in the terraform acceptance tests"
vpc_id = "${aws_vpc.foo.id}"
ingress {
protocol = "tcp"
from_port = 80
to_port = 8000
cidr_blocks = ["10.0.0.0/0"]
}
}
`