providers/aws: depend on security groups, failing test for #87
This commit is contained in:
parent
6522f568bb
commit
dbe6b74884
|
@ -153,13 +153,37 @@ func resource_aws_security_group_update_state(
|
||||||
|
|
||||||
// Flatten our ingress values
|
// Flatten our ingress values
|
||||||
toFlatten := make(map[string]interface{})
|
toFlatten := make(map[string]interface{})
|
||||||
toFlatten["ingress"] = flattenIPPerms(sg.IPPerms)
|
|
||||||
|
ingressRules := make([]map[string]interface{}, 0, len(sg.IPPerms))
|
||||||
|
for _, perm := range sg.IPPerms {
|
||||||
|
n := make(map[string]interface{})
|
||||||
|
n["from_port"] = perm.FromPort
|
||||||
|
n["protocol"] = perm.Protocol
|
||||||
|
n["to_port"] = perm.ToPort
|
||||||
|
|
||||||
|
if len(perm.SourceIPs) > 0 {
|
||||||
|
n["cidr_blocks"] = perm.SourceIPs
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(perm.SourceGroups) > 0 {
|
||||||
|
// We depend on other security groups
|
||||||
|
for _, v := range perm.SourceGroups {
|
||||||
|
s.Dependencies = append(s.Dependencies,
|
||||||
|
terraform.ResourceDependency{ID: v.Id},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
n["security_groups"] = flattenSecurityGroups(perm.SourceGroups)
|
||||||
|
}
|
||||||
|
|
||||||
|
ingressRules = append(ingressRules, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
toFlatten["ingress"] = ingressRules
|
||||||
|
|
||||||
for k, v := range flatmap.Flatten(toFlatten) {
|
for k, v := range flatmap.Flatten(toFlatten) {
|
||||||
s.Attributes[k] = v
|
s.Attributes[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Dependencies = nil
|
|
||||||
if s.Attributes["vpc_id"] != "" {
|
if s.Attributes["vpc_id"] != "" {
|
||||||
s.Dependencies = append(s.Dependencies,
|
s.Dependencies = append(s.Dependencies,
|
||||||
terraform.ResourceDependency{ID: s.Attributes["vpc_id"]},
|
terraform.ResourceDependency{ID: s.Attributes["vpc_id"]},
|
||||||
|
|
|
@ -85,6 +85,30 @@ func TestAccAWSSecurityGroup_vpc(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSSecurityGroup_MultiIngress(t *testing.T) {
|
||||||
|
var group ec2.SecurityGroupInfo
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSSecurityGroupConfigMultiIngress,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSSecurityGroupConfigMultiIngress,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.ec2conn
|
conn := testAccProvider.ec2conn
|
||||||
|
|
||||||
|
@ -218,3 +242,36 @@ resource "aws_security_group" "web" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccAWSSecurityGroupConfigMultiIngress = `
|
||||||
|
resource "aws_security_group" "worker" {
|
||||||
|
name = "terraform_acceptance_test_example_1"
|
||||||
|
description = "Used in the terraform acceptance tests"
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
protocol = "tcp"
|
||||||
|
from_port = 80
|
||||||
|
to_port = 8000
|
||||||
|
cidr_blocks = ["10.0.0.0/8"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_security_group" "web" {
|
||||||
|
name = "terraform_acceptance_test_example_2"
|
||||||
|
description = "Used in the terraform acceptance tests"
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
protocol = "tcp"
|
||||||
|
from_port = 80
|
||||||
|
to_port = 8000
|
||||||
|
cidr_blocks = ["10.0.0.0/8"]
|
||||||
|
}
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
protocol = "tcp"
|
||||||
|
from_port = 80
|
||||||
|
to_port = 8000
|
||||||
|
security_groups = ["${aws_security_group.worker.id}"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue