Added security group tagging
This commit is contained in:
parent
c2a27fe507
commit
eef3197ba0
|
@ -84,6 +84,8 @@ func resourceAwsSecurityGroup() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"tags": tagsSchema(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,6 +228,12 @@ func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := setTags(ec2conn, d); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
d.SetPartial("tags")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +303,7 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
d.Set("vpc_id", sg.VpcId)
|
d.Set("vpc_id", sg.VpcId)
|
||||||
d.Set("owner_id", sg.OwnerId)
|
d.Set("owner_id", sg.OwnerId)
|
||||||
d.Set("ingress", ingressRules)
|
d.Set("ingress", ingressRules)
|
||||||
|
d.Set("tags", tagsToMap(sg.Tags))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,6 +276,34 @@ func testAccCheckAWSSecurityGroupAttributes(group *ec2.SecurityGroupInfo) resour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSSecurityGroup_tags(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: testAccAWSSecurityGroupConfigTags,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
||||||
|
testAccCheckTags(&group.Tags, "foo", "bar"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSSecurityGroupConfigTagsUpdate,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
||||||
|
testAccCheckTags(&group.Tags, "foo", ""),
|
||||||
|
testAccCheckTags(&group.Tags, "bar", "baz"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSSecurityGroupAttributesChanged(group *ec2.SecurityGroupInfo) resource.TestCheckFunc {
|
func testAccCheckAWSSecurityGroupAttributesChanged(group *ec2.SecurityGroupInfo) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
p := []ec2.IPPerm{
|
p := []ec2.IPPerm{
|
||||||
|
@ -432,3 +460,19 @@ resource "aws_security_group" "web" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccAWSSecurityGroupConfigTags = `
|
||||||
|
resource "aws_security_group" "foo" {
|
||||||
|
tags {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const testAccAWSSecurityGroupConfigTagsUpdate = `
|
||||||
|
resource "aws_security_group" "foo" {
|
||||||
|
tags {
|
||||||
|
bar = "baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -10,17 +10,39 @@ Provides an security group resource.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
Basic usage
|
||||||
|
|
||||||
```
|
```
|
||||||
resource "aws_security_group" "allow_all" {
|
resource "aws_security_group" "allow_all" {
|
||||||
name = "allow_all"
|
name = "allow_all"
|
||||||
description = "Allow all inbound traffic"
|
description = "Allow all inbound traffic"
|
||||||
|
|
||||||
ingress {
|
ingress {
|
||||||
from_port = 0
|
from_port = 0
|
||||||
to_port = 65535
|
to_port = 65535
|
||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
cidr_blocks = ["0.0.0.0/0"]
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Basic usage with tags:
|
||||||
|
|
||||||
|
```
|
||||||
|
resource "aws_security_group" "allow_all" {
|
||||||
|
name = "allow_all"
|
||||||
|
description = "Allow all inbound traffic"
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
from_port = 0
|
||||||
|
to_port = 65535
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "allow_all"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -44,6 +66,7 @@ The `ingress` block supports:
|
||||||
* `self` - (Optional) If true, the security group itself will be added as
|
* `self` - (Optional) If true, the security group itself will be added as
|
||||||
a source to this ingress rule.
|
a source to this ingress rule.
|
||||||
* `to_port` - (Required) The end range port.
|
* `to_port` - (Required) The end range port.
|
||||||
|
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
|
@ -55,4 +78,3 @@ The following attributes are exported:
|
||||||
* `name` - The name of the security group
|
* `name` - The name of the security group
|
||||||
* `description` - The description of the security group
|
* `description` - The description of the security group
|
||||||
* `ingress` - The ingress rules. See above for more.
|
* `ingress` - The ingress rules. See above for more.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue