Skip to content

Instantly share code, notes, and snippets.

@catsby
Created June 9, 2017 18:00
Show Gist options
  • Save catsby/dadec1a7c70811910743f560548ca80c to your computer and use it in GitHub Desktop.
Save catsby/dadec1a7c70811910743f560548ca80c to your computer and use it in GitHub Desktop.
Test migration thing
From adc36385f91aeba390f3e095f2b584e792ba4399 Mon Sep 17 00:00:00 2001
From: clint shryock <clint@ctshryock.com>
Date: Thu, 8 Jun 2017 17:17:43 -0500
Subject: [PATCH 1/2] provider/aws: Add tag support for ebs_volume_snapshot
---
builtin/providers/aws/resource_aws_ami_test.go | 7 +++++++
builtin/providers/aws/resource_aws_ebs_snapshot.go | 14 ++++++++++++++
website/source/docs/providers/aws/r/ebs_snapshot.html.md | 7 ++++++-
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/builtin/providers/aws/resource_aws_ami_test.go b/builtin/providers/aws/resource_aws_ami_test.go
index 2f2e481a408..e860ccea437 100644
--- a/builtin/providers/aws/resource_aws_ami_test.go
+++ b/builtin/providers/aws/resource_aws_ami_test.go
@@ -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" {
@@ -219,6 +223,9 @@ 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" {
diff --git a/builtin/providers/aws/resource_aws_ebs_snapshot.go b/builtin/providers/aws/resource_aws_ebs_snapshot.go
index e06a7290dec..f444df4ef13 100644
--- a/builtin/providers/aws/resource_aws_ebs_snapshot.go
+++ b/builtin/providers/aws/resource_aws_ebs_snapshot.go
@@ -53,6 +53,12 @@ func resourceAwsEbsSnapshot() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
+
+ "tags": {
+ Type: schema.TypeMap,
+ Optional: true,
+ ForceNew: true,
+ },
},
}
}
@@ -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)
}
@@ -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
}
diff --git a/website/source/docs/providers/aws/r/ebs_snapshot.html.md b/website/source/docs/providers/aws/r/ebs_snapshot.html.md
index fffa6c9781e..45aec6fe5bf 100644
--- a/website/source/docs/providers/aws/r/ebs_snapshot.html.md
+++ b/website/source/docs/providers/aws/r/ebs_snapshot.html.md
@@ -23,6 +23,10 @@ resource "aws_ebs_volume" "example" {
resource "aws_ebs_snapshot" "example_snapshot" {
volume_id = "${aws_ebs_volume.example.id}"
+
+ tags {
+ Name = "HelloWorld_snap"
+ }
}
```
@@ -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
@@ -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.
\ No newline at end of file
+* `tags` - A mapping of tags for the snapshot.
From 2113681e5ca85c8f9ab8d331226ff37b86a26add Mon Sep 17 00:00:00 2001
From: clint shryock <clint@ctshryock.com>
Date: Fri, 9 Jun 2017 11:00:10 -0500
Subject: [PATCH 2/2] add test for tags
---
builtin/providers/aws/resource_aws_ebs_snapshot_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/builtin/providers/aws/resource_aws_ebs_snapshot_test.go b/builtin/providers/aws/resource_aws_ebs_snapshot_test.go
index 8e2c7a2ba17..71860c67f22 100644
--- a/builtin/providers/aws/resource_aws_ebs_snapshot_test.go
+++ b/builtin/providers/aws/resource_aws_ebs_snapshot_test.go
@@ -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"),
),
},
},
@@ -79,6 +80,10 @@ resource "aws_ebs_volume" "test" {
resource "aws_ebs_snapshot" "test" {
volume_id = "${aws_ebs_volume.test.id}"
+
+ tags {
+ Name = "testAccAwsEbsSnapshotConfig"
+ }
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment