|
|
|
|
@ -43,6 +43,51 @@ func TestAccAWSSecurityGroup_normal(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAccAWSSecurityGroup_self(t *testing.T) {
|
|
|
|
|
var group ec2.SecurityGroupInfo
|
|
|
|
|
|
|
|
|
|
checkSelf := func(s *terraform.State) (err error) {
|
|
|
|
|
defer func() {
|
|
|
|
|
if e := recover(); e != nil {
|
|
|
|
|
err = fmt.Errorf("bad: %#v", group)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if group.IPPerms[0].SourceGroups[0].Id != group.Id {
|
|
|
|
|
return fmt.Errorf("bad: %#v", group)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
|
resource.TestStep{
|
|
|
|
|
Config: testAccAWSSecurityGroupConfigSelf,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &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.self", "true"),
|
|
|
|
|
checkSelf,
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAccAWSSecurityGroup_vpc(t *testing.T) {
|
|
|
|
|
var group ec2.SecurityGroupInfo
|
|
|
|
|
|
|
|
|
|
@ -215,6 +260,10 @@ func testAccCheckAWSSecurityGroupAttributes(group *ec2.SecurityGroupInfo) resour
|
|
|
|
|
return fmt.Errorf("Bad description: %s", group.Description)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(group.IPPerms) == 0 {
|
|
|
|
|
return fmt.Errorf("No IPPerms")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compare our ingress
|
|
|
|
|
if !reflect.DeepEqual(group.IPPerms[0], p) {
|
|
|
|
|
return fmt.Errorf(
|
|
|
|
|
@ -311,6 +360,20 @@ resource "aws_security_group" "web" {
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigSelf = `
|
|
|
|
|
resource "aws_security_group" "web" {
|
|
|
|
|
name = "terraform_acceptance_test_example"
|
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
from_port = 80
|
|
|
|
|
to_port = 8000
|
|
|
|
|
self = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigVpc = `
|
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
|
cidr_block = "10.1.0.0/16"
|
|
|
|
|
|