Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/ebs_snapshot: Add support for tags #3

Merged
merged 3 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.