Skip to content

Commit

Permalink
Merge pull request #3 from terraform-providers/f-aws-snapshot-tags
Browse files Browse the repository at this point in the history
resource/ebs_snapshot: Add support for tags
  • Loading branch information
catsby authored Jun 9, 2017
2 parents 064c229 + 02e780a commit b0d4180
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
8 changes: 8 additions & 0 deletions aws/resource_aws_ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ resource "aws_ebs_volume" "foo" {
resource "aws_ebs_snapshot" "foo" {
volume_id = "${aws_ebs_volume.foo.id}"
tags {
Name = "testAccAmiConfig_basic"
}
}
resource "aws_ami" "foo" {
Expand All @@ -219,6 +223,10 @@ resource "aws_ebs_volume" "foo" {
resource "aws_ebs_snapshot" "foo" {
volume_id = "${aws_ebs_volume.foo.id}"
tags {
Name = "TestAccAWSAMI_snapshotSize"
}
}
resource "aws_ami" "foo" {
Expand Down
14 changes: 14 additions & 0 deletions aws/resource_aws_ebs_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func resourceAwsEbsSnapshot() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"tags": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
},
},
}
}
Expand All @@ -79,6 +85,10 @@ func resourceAwsEbsSnapshotCreate(d *schema.ResourceData, meta interface{}) erro
return err
}

if err := setTags(conn, d); err != nil {
log.Printf("[WARN] error setting tags: %s", err)
}

return resourceAwsEbsSnapshotRead(d, meta)
}

Expand Down Expand Up @@ -106,6 +116,10 @@ func resourceAwsEbsSnapshotRead(d *schema.ResourceData, meta interface{}) error
d.Set("kms_keey_id", snapshot.KmsKeyId)
d.Set("volume_size", snapshot.VolumeSize)

if err := d.Set("tags", tagsToMap(snapshot.Tags)); err != nil {
log.Printf("[WARN] error saving tags to state: %s", err)
}

return nil
}

Expand Down
11 changes: 8 additions & 3 deletions aws/resource_aws_ebs_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestAccAWSEBSSnapshot_basic(t *testing.T) {
Config: testAccAwsEbsSnapshotConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckSnapshotExists("aws_ebs_snapshot.test", &v),
testAccCheckTags(&v.Tags, "Name", "testAccAwsEbsSnapshotConfig"),
),
},
},
Expand Down Expand Up @@ -73,12 +74,16 @@ func testAccCheckSnapshotExists(n string, v *ec2.Snapshot) resource.TestCheckFun

const testAccAwsEbsSnapshotConfig = `
resource "aws_ebs_volume" "test" {
availability_zone = "us-west-2a"
size = 1
availability_zone = "us-west-2a"
size = 1
}
resource "aws_ebs_snapshot" "test" {
volume_id = "${aws_ebs_volume.test.id}"
volume_id = "${aws_ebs_volume.test.id}"
tags {
Name = "testAccAwsEbsSnapshotConfig"
}
}
`

Expand Down
9 changes: 7 additions & 2 deletions website/docs/r/ebs_snapshot.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ resource "aws_ebs_volume" "example" {
}
resource "aws_ebs_snapshot" "example_snapshot" {
volume_id = "${aws_ebs_volume.example.id}"
volume_id = "${aws_ebs_volume.example.id}"
tags {
Name = "HelloWorld_snap"
}
}
```

Expand All @@ -32,6 +36,7 @@ The following arguments are supported:

* `volume_id` - (Required) The Volume ID of which to make a snapshot.
* `description` - (Optional) A description of what the snapshot is.
* `tags` - (Optional) A mapping of tags to assign to the snapshot


## Attributes Reference
Expand All @@ -45,4 +50,4 @@ The following attributes are exported:
* `volume_size` - The size of the drive in GiBs.
* `kms_key_id` - The ARN for the KMS encryption key.
* `data_encryption_key_id` - The data encryption key identifier for the snapshot.
* `tags` - A mapping of tags for the resource.
* `tags` - A mapping of tags for the snapshot.

0 comments on commit b0d4180

Please sign in to comment.