2014-07-10 22:39:43 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-16 17:14:23 +02:00
|
|
|
"reflect"
|
2015-04-22 19:56:06 +02:00
|
|
|
"strings"
|
2014-07-16 18:01:56 +02:00
|
|
|
"testing"
|
2014-07-10 22:39:43 +02:00
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2014-07-10 22:39:43 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2016-01-20 17:52:46 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-07-10 22:39:43 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2016-01-20 17:52:46 +01:00
|
|
|
func TestResourceAwsSecurityGroupIPPermGather(t *testing.T) {
|
|
|
|
raw := []*ec2.IpPermission{
|
|
|
|
&ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("tcp"),
|
|
|
|
FromPort: aws.Int64(int64(1)),
|
|
|
|
ToPort: aws.Int64(int64(-1)),
|
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: aws.String("0.0.0.0/0")}},
|
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
GroupId: aws.String("sg-22222"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("tcp"),
|
|
|
|
FromPort: aws.Int64(int64(80)),
|
|
|
|
ToPort: aws.Int64(int64(80)),
|
|
|
|
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
|
|
|
&ec2.UserIdGroupPair{
|
|
|
|
GroupId: aws.String("foo"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local := []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "tcp",
|
|
|
|
"from_port": int64(1),
|
|
|
|
"to_port": int64(-1),
|
|
|
|
"cidr_blocks": []string{"0.0.0.0/0"},
|
|
|
|
"self": true,
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "tcp",
|
|
|
|
"from_port": int64(80),
|
|
|
|
"to_port": int64(80),
|
|
|
|
"security_groups": schema.NewSet(schema.HashString, []interface{}{
|
|
|
|
"foo",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
out := resourceAwsSecurityGroupIPPermGather("sg-22222", raw)
|
|
|
|
for _, i := range out {
|
|
|
|
// loop and match rules, because the ordering is not guarneteed
|
|
|
|
for _, l := range local {
|
|
|
|
if i["from_port"] == l["from_port"] {
|
|
|
|
|
|
|
|
if i["to_port"] != l["to_port"] {
|
|
|
|
t.Fatalf("to_port does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := i["cidr_blocks"]; ok {
|
|
|
|
if !reflect.DeepEqual(i["cidr_blocks"], l["cidr_blocks"]) {
|
|
|
|
t.Fatalf("error matching cidr_blocks")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := i["security_groups"]; ok {
|
|
|
|
outSet := i["security_groups"].(*schema.Set)
|
|
|
|
localSet := l["security_groups"].(*schema.Set)
|
|
|
|
|
|
|
|
if !outSet.Equal(localSet) {
|
|
|
|
t.Fatalf("Security Group sets are not equal")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-08 01:04:38 +02:00
|
|
|
func TestAccAWSSecurityGroup_basic(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(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.protocol", "tcp"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.from_port", "80"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.to_port", "8000"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.cidr_blocks.#", "1"),
|
2014-07-16 17:14:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.cidr_blocks.0", "10.0.0.0/8"),
|
2014-07-16 17:14:23 +02:00
|
|
|
),
|
2014-07-10 22:39:43 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-12-17 18:24:24 +01:00
|
|
|
func TestAccAWSSecurityGroup_namePrefix(t *testing.T) {
|
2015-12-04 15:21:08 +01:00
|
|
|
var group ec2.SecurityGroup
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupPrefixNameConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.baz", &group),
|
|
|
|
testAccCheckAWSSecurityGroupGeneratedNamePrefix(
|
|
|
|
"aws_security_group.baz", "baz-"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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-08-17 20:27:16 +02: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(
|
2015-04-02 16:00:47 +02:00
|
|
|
"aws_security_group.web", "ingress.3971148406.protocol", "tcp"),
|
2014-09-30 23:19:16 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-04-02 16:00:47 +02:00
|
|
|
"aws_security_group.web", "ingress.3971148406.from_port", "80"),
|
2014-09-30 23:19:16 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-04-02 16:00:47 +02:00
|
|
|
"aws_security_group.web", "ingress.3971148406.to_port", "8000"),
|
2014-09-30 23:19:16 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-04-02 16:00:47 +02:00
|
|
|
"aws_security_group.web", "ingress.3971148406.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-08-17 20:27:16 +02: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(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.protocol", "tcp"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.from_port", "80"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.to_port", "8000"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.cidr_blocks.#", "1"),
|
2014-07-17 19:03:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "ingress.3629188364.cidr_blocks.0", "10.0.0.0/8"),
|
2015-01-23 15:46:20 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "egress.3629188364.protocol", "tcp"),
|
2015-01-23 15:46:20 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "egress.3629188364.from_port", "80"),
|
2015-01-23 15:46:20 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "egress.3629188364.to_port", "8000"),
|
2015-01-23 15:46:20 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "egress.3629188364.cidr_blocks.#", "1"),
|
2015-01-23 15:46:20 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-03-30 21:54:03 +02:00
|
|
|
"aws_security_group.web", "egress.3629188364.cidr_blocks.0", "10.0.0.0/8"),
|
2014-07-17 19:03:15 +02:00
|
|
|
testCheck,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-05 05:55:32 +02:00
|
|
|
func TestAccAWSSecurityGroup_vpcNegOneIngress(t *testing.T) {
|
|
|
|
var group ec2.SecurityGroup
|
|
|
|
|
|
|
|
testCheck := func(*terraform.State) error {
|
2015-08-17 20:27:16 +02:00
|
|
|
if *group.VpcId == "" {
|
2015-05-05 05:55:32 +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: testAccAWSSecurityGroupConfigVpcNegOneIngress,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
|
|
|
testAccCheckAWSSecurityGroupAttributesNegOneProtocol(&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.956249133.protocol", "-1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "ingress.956249133.from_port", "0"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "ingress.956249133.to_port", "0"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "ingress.956249133.cidr_blocks.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "ingress.956249133.cidr_blocks.0", "10.0.0.0/8"),
|
|
|
|
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
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:56:06 +02:00
|
|
|
func TestAccAWSSecurityGroup_generatedName(t *testing.T) {
|
|
|
|
var group ec2.SecurityGroup
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfig_generatedName,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
2015-04-22 20:27:20 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_security_group.web", "description", "Managed by Terraform"),
|
2015-04-22 19:56:06 +02:00
|
|
|
func(s *terraform.State) error {
|
|
|
|
if group.GroupName == nil {
|
|
|
|
return fmt.Errorf("bad: No SG name")
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(*group.GroupName, "terraform-") {
|
|
|
|
return fmt.Errorf("No terraform- prefix: %s", *group.GroupName)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:33:23 +02:00
|
|
|
func TestAccAWSSecurityGroup_DefaultEgress(t *testing.T) {
|
|
|
|
|
2015-04-20 20:38:21 +02:00
|
|
|
// VPC
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfigDefaultEgress,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExistsWithoutDefault("aws_security_group.worker"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Classic
|
|
|
|
var group ec2.SecurityGroup
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSecurityGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSSecurityGroupConfigClassic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.web", &group),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2015-05-01 21:33:23 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 22:39:43 +02:00
|
|
|
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
|
2015-04-16 22:05:55 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
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-04-09 16:10:04 +02:00
|
|
|
req := &ec2.DescribeSecurityGroupsInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
GroupIds: []*string{aws.String(rs.Primary.ID)},
|
2015-03-09 16:02:27 +01:00
|
|
|
}
|
|
|
|
resp, err := conn.DescribeSecurityGroups(req)
|
2014-07-10 22:39:43 +02:00
|
|
|
if err == nil {
|
2015-08-17 20:27:16 +02: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-05-20 13:21:23 +02:00
|
|
|
ec2err, ok := err.(awserr.Error)
|
2014-07-10 22:39:43 +02:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Confirm error code is what we want
|
2015-05-20 13:21:23 +02:00
|
|
|
if ec2err.Code() != "InvalidGroup.NotFound" {
|
2014-07-10 22:39:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-04 15:21:08 +01:00
|
|
|
func testAccCheckAWSSecurityGroupGeneratedNamePrefix(
|
2015-12-17 18:24:24 +01:00
|
|
|
resource, prefix string) resource.TestCheckFunc {
|
2015-12-04 15:21:08 +01:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
r, ok := s.RootModule().Resources[resource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Resource not found")
|
|
|
|
}
|
|
|
|
name, ok := r.Primary.Attributes["name"]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Name attr not found: %#v", r.Primary.Attributes)
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(name, prefix) {
|
|
|
|
return fmt.Errorf("Name: %q, does not have prefix: %q", name, prefix)
|
|
|
|
}
|
|
|
|
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-04-16 22:05:55 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
2015-04-09 16:10:04 +02:00
|
|
|
req := &ec2.DescribeSecurityGroupsInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
GroupIds: []*string{aws.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-08-17 20:27:16 +02:00
|
|
|
if len(resp.SecurityGroups) > 0 && *resp.SecurityGroups[0].GroupId == rs.Primary.ID {
|
2015-04-09 16:10:04 +02:00
|
|
|
*group = *resp.SecurityGroups[0]
|
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-08-17 20:27:16 +02:00
|
|
|
p := &ec2.IpPermission{
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(80),
|
|
|
|
ToPort: aws.Int64(8000),
|
2015-08-17 20:27:16 +02:00
|
|
|
IpProtocol: aws.String("tcp"),
|
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: 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-08-17 20:27:16 +02: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-08-17 20:27:16 +02: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-08-17 20:27:16 +02:00
|
|
|
group.IpPermissions[0],
|
2014-07-16 17:14:23 +02:00
|
|
|
p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 05:55:32 +02:00
|
|
|
func testAccCheckAWSSecurityGroupAttributesNegOneProtocol(group *ec2.SecurityGroup) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
2015-08-17 20:27:16 +02:00
|
|
|
p := &ec2.IpPermission{
|
|
|
|
IpProtocol: aws.String("-1"),
|
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: aws.String("10.0.0.0/8")}},
|
2015-05-05 05:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if *group.GroupName != "terraform_acceptance_test_example" {
|
|
|
|
return fmt.Errorf("Bad name: %s", *group.GroupName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *group.Description != "Used in the terraform acceptance tests" {
|
|
|
|
return fmt.Errorf("Bad description: %s", *group.Description)
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if len(group.IpPermissions) == 0 {
|
2015-05-05 05:55:32 +02:00
|
|
|
return fmt.Errorf("No IPPerms")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare our ingress
|
2015-08-17 20:27:16 +02:00
|
|
|
if !reflect.DeepEqual(group.IpPermissions[0], p) {
|
2015-05-05 05:55:32 +02:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2015-08-17 20:27:16 +02:00
|
|
|
group.IpPermissions[0],
|
2015-05-05 05:55:32 +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-05-12 21:58:10 +02:00
|
|
|
testAccCheckTags(&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-05-12 21:58:10 +02:00
|
|
|
testAccCheckTags(&group.Tags, "foo", ""),
|
|
|
|
testAccCheckTags(&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-08-17 20:27:16 +02:00
|
|
|
p := []*ec2.IpPermission{
|
|
|
|
&ec2.IpPermission{
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(80),
|
|
|
|
ToPort: aws.Int64(9000),
|
2015-08-17 20:27:16 +02:00
|
|
|
IpProtocol: aws.String("tcp"),
|
|
|
|
IpRanges: []*ec2.IpRange{&ec2.IpRange{CidrIp: aws.String("10.0.0.0/8")}},
|
2014-08-20 20:18:00 +02:00
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
&ec2.IpPermission{
|
2015-07-28 22:29:46 +02:00
|
|
|
FromPort: aws.Int64(80),
|
|
|
|
ToPort: aws.Int64(8000),
|
2015-08-17 20:27:16 +02:00
|
|
|
IpProtocol: aws.String("tcp"),
|
|
|
|
IpRanges: []*ec2.IpRange{
|
|
|
|
&ec2.IpRange{
|
|
|
|
CidrIp: aws.String("0.0.0.0/0"),
|
2015-04-09 16:10:04 +02:00
|
|
|
},
|
2015-08-17 20:27:16 +02:00
|
|
|
&ec2.IpRange{
|
|
|
|
CidrIp: aws.String("10.0.0.0/8"),
|
2015-04-09 16:10:04 +02:00
|
|
|
},
|
|
|
|
},
|
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-08-17 20:27:16 +02: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-08-17 20:27:16 +02:00
|
|
|
group.IpPermissions,
|
2014-08-20 20:18:00 +02:00
|
|
|
p)
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02: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-08-17 20:27:16 +02: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-08-17 20:27:16 +02:00
|
|
|
group.IpPermissions,
|
2014-08-20 20:18:00 +02:00
|
|
|
p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:33:23 +02:00
|
|
|
func testAccCheckAWSSecurityGroupExistsWithoutDefault(n string) resource.TestCheckFunc {
|
2015-04-20 20:38:21 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No Security Group is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
req := &ec2.DescribeSecurityGroupsInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
GroupIds: []*string{aws.String(rs.Primary.ID)},
|
2015-04-20 20:38:21 +02:00
|
|
|
}
|
|
|
|
resp, err := conn.DescribeSecurityGroups(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if len(resp.SecurityGroups) > 0 && *resp.SecurityGroups[0].GroupId == rs.Primary.ID {
|
2015-04-20 20:38:21 +02:00
|
|
|
group := *resp.SecurityGroups[0]
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
if len(group.IpPermissionsEgress) != 1 {
|
|
|
|
return fmt.Errorf("Security Group should have only 1 egress rule, got %d", len(group.IpPermissionsEgress))
|
2015-04-20 20:38:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2015-05-01 21:33:23 +02:00
|
|
|
}
|
|
|
|
|
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"]
|
|
|
|
}
|
2015-04-09 16:10:04 +02:00
|
|
|
|
2015-05-01 21:56:16 +02:00
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
2015-04-09 16:10:04 +02:00
|
|
|
tags {
|
|
|
|
Name = "tf-acc-test"
|
|
|
|
}
|
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"]
|
|
|
|
}
|
2015-05-01 21:56:16 +02:00
|
|
|
|
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["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
|
|
|
|
}
|
2015-05-01 21:56:16 +02:00
|
|
|
|
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
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
|
|
|
|
2015-05-05 05:55:32 +02:00
|
|
|
const testAccAWSSecurityGroupConfigVpcNegOneIngress = `
|
|
|
|
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 = "-1"
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
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"]
|
|
|
|
}
|
2015-05-01 21:56:16 +02:00
|
|
|
|
|
|
|
egress {
|
|
|
|
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}"]
|
|
|
|
}
|
2015-05-01 21:56:16 +02:00
|
|
|
|
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
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"]
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:56:16 +02:00
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
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"]
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:56:16 +02:00
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
tags {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
2014-10-14 23:07:01 +02:00
|
|
|
}
|
|
|
|
`
|
2015-04-22 19:56:06 +02:00
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfig_generatedName = `
|
|
|
|
resource "aws_security_group" "web" {
|
|
|
|
ingress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:56:16 +02:00
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:56:06 +02:00
|
|
|
tags {
|
|
|
|
Name = "tf-acc-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2015-05-01 21:33:23 +02:00
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigDefaultEgress = `
|
2015-05-01 21:56:16 +02:00
|
|
|
resource "aws_vpc" "tf_sg_egress_test" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
tags {
|
|
|
|
Name = "tf_sg_egress_test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 21:33:23 +02:00
|
|
|
resource "aws_security_group" "worker" {
|
|
|
|
name = "terraform_acceptance_test_example_1"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
2015-05-01 21:56:16 +02:00
|
|
|
vpc_id = "${aws_vpc.tf_sg_egress_test.id}"
|
2015-05-01 21:33:23 +02:00
|
|
|
|
|
|
|
egress {
|
|
|
|
protocol = "tcp"
|
|
|
|
from_port = 80
|
|
|
|
to_port = 8000
|
|
|
|
cidr_blocks = ["10.0.0.0/8"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2015-05-01 21:56:16 +02:00
|
|
|
|
|
|
|
const testAccAWSSecurityGroupConfigClassic = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "web" {
|
|
|
|
name = "terraform_acceptance_test_example_1"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
}
|
|
|
|
`
|
2015-12-04 15:21:08 +01:00
|
|
|
|
|
|
|
const testAccAWSSecurityGroupPrefixNameConfig = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "baz" {
|
|
|
|
name_prefix = "baz-"
|
|
|
|
description = "Used in the terraform acceptance tests"
|
|
|
|
}
|
|
|
|
`
|