2014-07-10 22:39:43 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-03-09 16:02:27 +01:00
|
|
|
"log"
|
2014-07-16 17:14:23 +02:00
|
|
|
"reflect"
|
2014-07-16 18:01:56 +02:00
|
|
|
"testing"
|
2014-07-10 22:39:43 +02:00
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
"github.com/hashicorp/aws-sdk-go/aws"
|
|
|
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
2014-07-10 22:39:43 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2014-07-17 19:03:15 +02:00
|
|
|
func TestAccAWSSecurityGroup_normal(t *testing.T) {
|
2015-03-09 16:02:27 +01:00
|
|
|
var group ec2.SecurityGroup
|
2014-07-16 17:14:23 +02:00
|
|
|
|
2014-07-10 22:39:43 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
2014-07-10 22:43:03 +02:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
2014-07-10 22:39:43 +02:00
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfig,
|
2014-07-16 17:14:23 +02:00
|
|
|
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(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.protocol", "tcp"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.from_port", "80"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.to_port", "8000"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.cidr_blocks.#", "1"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.cidr_blocks.0", "10.0.0.0/8"),
|
2014-07-16 17:14:23 +02:00
|
|
|
),
|
2014-07-10 22:39:43 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-09-30 23:19:16 +02:00
|
|
|
func TestAccAWSSecurityGroup_self(t *testing.T) {
|
2015-03-09 16:02:27 +01:00
|
|
|
var group ec2.SecurityGroup
|
2014-09-30 23:19:16 +02:00
|
|
|
|
|
|
|
checkSelf := func(s *terraform.State) (err error) {
|
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
|
|
|
err = fmt.Errorf("bad: %#v", group)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.IPPermissions[0].UserIDGroupPairs[0].GroupID != *group.GroupID {
|
2014-09-30 23:19:16 +02:00
|
|
|
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(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.3128515109.protocol", "tcp"),
|
2014-09-30 23:19:16 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.3128515109.from_port", "80"),
|
2014-09-30 23:19:16 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.3128515109.to_port", "8000"),
|
2014-09-30 23:19:16 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.3128515109.self", "true"),
|
2014-09-30 23:19:16 +02:00
|
|
|
checkSelf,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-17 19:03:15 +02:00
|
|
|
func TestAccAWSSecurityGroup_vpc(t *testing.T) {
|
2015-03-09 16:02:27 +01:00
|
|
|
var group ec2.SecurityGroup
|
2014-07-17 19:03:15 +02:00
|
|
|
|
|
|
|
testCheck := func(*terraform.State) error {
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.VPCID == "" {
|
2014-07-17 19:03:15 +02:00
|
|
|
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(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.protocol", "tcp"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.from_port", "80"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.to_port", "8000"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.cidr_blocks.#", "1"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-12-12 23:21:20 +01:00
|
|
|
"aws_security_group.web", "ingress.332851786.cidr_blocks.0", "10.0.0.0/8"),
|
2015-01-23 15:46:20 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "egress.332851786.protocol", "tcp"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "egress.332851786.from_port", "80"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "egress.332851786.to_port", "8000"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "egress.332851786.cidr_blocks.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "egress.332851786.cidr_blocks.0", "10.0.0.0/8"),
|
2014-07-17 19:03:15 +02:00
|
|
|
testCheck,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-29 18:06:28 +02:00
|
|
|
func TestAccAWSSecurityGroup_MultiIngress(t *testing.T) {
|
2015-03-09 16:02:27 +01:00
|
|
|
var group ec2.SecurityGroup
|
2014-07-29 18:06:28 +02:00
|
|
|
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
},
|
2014-08-20 20:18:00 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAWSSecurityGroup_Change(t *testing.T) {
|
2015-03-09 16:02:27 +01:00
|
|
|
var group ec2.SecurityGroup
|
2014-08-20 20:18:00 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2014-07-29 18:06:28 +02:00
|
|
|
resource.TestStep{
|
2014-08-20 20:18:00 +02:00
|
|
|
Config: testAccAWSSecurityGroupConfig,
|
2014-07-29 18:06:28 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
|
|
|
),
|
|
|
|
},
|
2014-08-20 20:18:00 +02:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfigChange,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
|
|
|
testAccCheckAWSSecurityGroupAttributesChanged(&group),
|
|
|
|
),
|
|
|
|
},
|
2014-07-29 18:06:28 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-10 22:39:43 +02:00
|
|
|
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
2015-03-09 16:02:27 +01:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
2014-07-10 22:39:43 +02:00
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-07-10 22:39:43 +02:00
|
|
|
if rs.Type != "aws_security_group" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve our group
|
2015-03-09 16:02:27 +01:00
|
|
|
req := &ec2.DescribeSecurityGroupsRequest{
|
|
|
|
GroupIDs: []string{rs.Primary.ID},
|
|
|
|
}
|
|
|
|
resp, err := conn.DescribeSecurityGroups(req)
|
2014-07-10 22:39:43 +02:00
|
|
|
if err == nil {
|
2015-03-09 16:02:27 +01:00
|
|
|
if len(resp.SecurityGroups) > 0 && *resp.SecurityGroups[0].GroupID == rs.Primary.ID {
|
2014-09-17 02:44:42 +02:00
|
|
|
return fmt.Errorf("Security Group (%s) still exists.", rs.Primary.ID)
|
2014-07-10 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
ec2err, ok := err.(aws.APIError)
|
2014-07-10 22:39:43 +02:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Confirm error code is what we want
|
|
|
|
if ec2err.Code != "InvalidGroup.NotFound" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
func testAccCheckAWSSecurityGroupExists(n string, group *ec2.SecurityGroup) resource.TestCheckFunc {
|
2014-07-10 22:39:43 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:44:42 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-07-10 22:39:43 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-07-10 22:39:43 +02:00
|
|
|
return fmt.Errorf("No Security Group is set")
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
|
|
|
req := &ec2.DescribeSecurityGroupsRequest{
|
|
|
|
GroupIDs: []string{rs.Primary.ID},
|
2014-07-10 22:39:43 +02:00
|
|
|
}
|
2015-03-09 16:02:27 +01:00
|
|
|
resp, err := conn.DescribeSecurityGroups(req)
|
2014-07-10 22:39:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if len(resp.SecurityGroups) > 0 && *resp.SecurityGroups[0].GroupID == rs.Primary.ID {
|
2014-07-16 17:14:23 +02:00
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
log.Printf("\n==\n===\nfound group\n===\n==\n")
|
|
|
|
*group = resp.SecurityGroups[0]
|
2014-07-16 17:14:23 +02:00
|
|
|
|
2014-07-10 22:39:43 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-08-25 06:50:35 +02:00
|
|
|
return fmt.Errorf("Security Group not found")
|
2014-07-10 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
func testAccCheckAWSSecurityGroupAttributes(group *ec2.SecurityGroup) resource.TestCheckFunc {
|
2014-07-16 17:14:23 +02:00
|
|
|
return func(s *terraform.State) error {
|
2015-03-09 16:02:27 +01:00
|
|
|
p := ec2.IPPermission{
|
|
|
|
FromPort: aws.Integer(80),
|
|
|
|
ToPort: aws.Integer(8000),
|
|
|
|
IPProtocol: aws.String("tcp"),
|
|
|
|
IPRanges: []ec2.IPRange{ec2.IPRange{aws.String("10.0.0.0/8")}},
|
2014-07-16 17:14:23 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.GroupName != "terraform_acceptance_test_example" {
|
|
|
|
return fmt.Errorf("Bad name: %s", *group.GroupName)
|
2014-07-16 17:14:23 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.Description != "Used in the terraform acceptance tests" {
|
|
|
|
return fmt.Errorf("Bad description: %s", *group.Description)
|
2014-07-16 17:14:23 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if len(group.IPPermissions) == 0 {
|
2014-09-30 23:19:16 +02:00
|
|
|
return fmt.Errorf("No IPPerms")
|
|
|
|
}
|
|
|
|
|
2014-07-16 17:14:23 +02:00
|
|
|
// Compare our ingress
|
2015-03-09 16:02:27 +01:00
|
|
|
if !reflect.DeepEqual(group.IPPermissions[0], p) {
|
2014-07-16 17:14:23 +02:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-03-09 16:02:27 +01:00
|
|
|
group.IPPermissions[0],
|
2014-07-16 17:14:23 +02:00
|
|
|
p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 23:07:01 +02:00
|
|
|
func TestAccAWSSecurityGroup_tags(t *testing.T) {
|
2015-03-09 16:02:27 +01:00
|
|
|
var group ec2.SecurityGroup
|
2014-10-14 23:07:01 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfigTags,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
2015-03-09 16:02:27 +01:00
|
|
|
testAccCheckTagsSDK(&group.Tags, "foo", "bar"),
|
2014-10-14 23:07:01 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfigTagsUpdate,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
2015-03-09 16:02:27 +01:00
|
|
|
testAccCheckTagsSDK(&group.Tags, "foo", ""),
|
|
|
|
testAccCheckTagsSDK(&group.Tags, "bar", "baz"),
|
2014-10-14 23:07:01 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
func testAccCheckAWSSecurityGroupAttributesChanged(group *ec2.SecurityGroup) resource.TestCheckFunc {
|
2014-08-20 20:18:00 +02:00
|
|
|
return func(s *terraform.State) error {
|
2015-03-09 16:02:27 +01:00
|
|
|
p := []ec2.IPPermission{
|
|
|
|
ec2.IPPermission{
|
|
|
|
FromPort: aws.Integer(80),
|
|
|
|
ToPort: aws.Integer(9000),
|
|
|
|
IPProtocol: aws.String("tcp"),
|
|
|
|
IPRanges: []ec2.IPRange{ec2.IPRange{aws.String("10.0.0.0/8")}},
|
2014-08-20 20:18:00 +02:00
|
|
|
},
|
2015-03-09 16:02:27 +01:00
|
|
|
ec2.IPPermission{
|
|
|
|
FromPort: aws.Integer(80),
|
|
|
|
ToPort: aws.Integer(8000),
|
|
|
|
IPProtocol: aws.String("tcp"),
|
|
|
|
IPRanges: []ec2.IPRange{ec2.IPRange{aws.String("0.0.0.0/0")}, ec2.IPRange{aws.String("10.0.0.0/8")}},
|
2014-08-20 20:18:00 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.GroupName != "terraform_acceptance_test_example" {
|
|
|
|
return fmt.Errorf("Bad name: %s", *group.GroupName)
|
2014-08-20 20:18:00 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.Description != "Used in the terraform acceptance tests" {
|
|
|
|
return fmt.Errorf("Bad description: %s", *group.Description)
|
2014-08-20 20:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compare our ingress
|
2015-03-09 16:02:27 +01:00
|
|
|
if len(group.IPPermissions) != 2 {
|
2014-08-20 20:18:00 +02:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-03-09 16:02:27 +01:00
|
|
|
group.IPPermissions,
|
2014-08-20 20:18:00 +02:00
|
|
|
p)
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if *group.IPPermissions[0].ToPort == 8000 {
|
|
|
|
group.IPPermissions[1], group.IPPermissions[0] =
|
|
|
|
group.IPPermissions[0], group.IPPermissions[1]
|
2014-08-20 20:18:00 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:02:27 +01:00
|
|
|
if !reflect.DeepEqual(group.IPPermissions, p) {
|
2014-08-20 20:18:00 +02:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-03-09 16:02:27 +01:00
|
|
|
group.IPPermissions,
|
2014-08-20 20:18:00 +02:00
|
|
|
p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 22:39:43 +02:00
|
|
|
const testAccAWSSecurityGroupConfig = `
|
|
|
|
resource "aws_security_group" "web" {
|
2014-12-12 23:21:20 +01:00
|
|
|
name = "terraform_acceptance_test_example"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
2014-07-10 22:39:43 +02:00
|
|
|
}
|
|
|
|
`
|
2014-07-17 19:03:15 +02:00
|
|
|
|
2014-08-20 20:18:00 +02:00
|
|
|
const testAccAWSSecurityGroupConfigChange = `
|
|
|
|
resource "aws_security_group" "web" {
|
2014-12-12 23:21:20 +01:00
|
|
|
name = "terraform_acceptance_test_example"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 9000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["0.0.0.0/0", "10.0.0.0/8"]
|
|
|
|
}
|
2014-08-20 20:18:00 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2014-09-30 23:19:16 +02:00
|
|
|
const testAccAWSSecurityGroupConfigSelf = `
|
|
|
|
resource "aws_security_group" "web" {
|
2014-12-12 23:21:20 +01:00
|
|
|
name = "terraform_acceptance_test_example"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
self = true
|
|
|
|
}
|
2014-09-30 23:19:16 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2014-07-17 19:03:15 +02:00
|
|
|
const testAccAWSSecurityGroupConfigVpc = `
|
|
|
|
resource "aws_vpc" "foo" {
|
2014-12-12 23:21:20 +01:00
|
|
|
cidr_block = "10.1.0.0/16"
|
2014-07-17 19:03:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "web" {
|
2014-12-12 23:21:20 +01:00
|
|
|
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/8"]
|
|
|
|
}
|
2015-01-23 15:46:20 +01:00
|
|
|
|
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
2014-07-17 19:03:15 +02:00
|
|
|
}
|
|
|
|
`
|
2014-07-29 18:06:28 +02:00
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigMultiIngress = `
|
|
|
|
resource "aws_security_group" "worker" {
|
2014-12-12 23:21:20 +01:00
|
|
|
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"]
|
|
|
|
}
|
2014-07-29 18:06:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "web" {
|
2014-12-12 23:21:20 +01:00
|
|
|
name = "terraform_acceptance_test_example_2"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 800
|
|
|
|
to_port = 800
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
security_groups = ["${aws_security_group.worker.id}"]
|
|
|
|
}
|
2014-07-29 18:06:28 +02:00
|
|
|
}
|
|
|
|
`
|
2014-10-14 23:07:01 +02:00
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigTags = `
|
|
|
|
resource "aws_security_group" "foo" {
|
2014-12-12 23:21:20 +01:00
|
|
|
name = "terraform_acceptance_test_example"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2014-10-14 23:07:01 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigTagsUpdate = `
|
|
|
|
resource "aws_security_group" "foo" {
|
2014-12-12 23:21:20 +01:00
|
|
|
name = "terraform_acceptance_test_example"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
2014-10-14 23:07:01 +02:00
|
|
|
}
|
|
|
|
`
|