Skip to content

Commit

Permalink
Added support for annotations field in google_secret_manager_secret r…
Browse files Browse the repository at this point in the history
…esource (GoogleCloudPlatform#8500)

* Added support for annotations field in google_secret_manager_secret resource

* Adjusted white spaces in Secret.yaml
  • Loading branch information
abheda-crest authored and ron-gal committed Aug 17, 2023
1 parent 5e7e0b8 commit d098c6d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mmv1/products/secretmanager/Secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ examples:
primary_resource_name: 'fmt.Sprintf("secret%s", context["random_suffix"])'
vars:
secret_id: 'secret'
- !ruby/object:Provider::Terraform::Examples
name: 'secret_with_annotations'
primary_resource_id: 'secret-with-annotations'
vars:
secret_id: 'secret'
import_format: ['projects/{{project}}/secrets/{{secret_id}}']
parameters:
- !ruby/object:Api::Type::String
Expand Down Expand Up @@ -67,6 +72,23 @@ properties:
No more than 64 labels can be assigned to a given resource.
An object containing a list of "key": value pairs. Example:
{ "name": "wrench", "mass": "1.3kg", "count": "3" }.
- !ruby/object:Api::Type::KeyValuePairs
name: annotations
description: |
Custom metadata about the secret.
Annotations are distinct from various forms of labels. Annotations exist to allow
client tools to store their own state information without requiring a database.
Annotation keys must be between 1 and 63 characters long, have a UTF-8 encoding of
maximum 128 bytes, begin and end with an alphanumeric character ([a-z0-9A-Z]), and
may have dashes (-), underscores (_), dots (.), and alphanumerics in between these
symbols.
The total size of annotation keys and values must be less than 16KiB.
An object containing a list of "key": value pairs. Example:
{ "name": "wrench", "mass": "1.3kg", "count": "3" }.
- !ruby/object:Api::Type::NestedObject
Expand Down
19 changes: 19 additions & 0 deletions mmv1/templates/terraform/examples/secret_with_annotations.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "google_secret_manager_secret" "<%= ctx[:primary_resource_id] %>" {
secret_id = "<%= ctx[:vars]['secret_id'] %>"

labels = {
label = "my-label"
}

annotations = {
key1 = "someval"
key2 = "someval2"
key3 = "someval3"
key4 = "someval4"
key5 = "someval5"
}

replication {
automatic = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,49 @@ func TestAccSecretManagerSecret_cmek(t *testing.T) {
})
}

func TestAccSecretManagerSecret_annotationsUpdate(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckSecretManagerSecretDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccSecretManagerSecret_annotationsBasic(context),
},
{
ResourceName: "google_secret_manager_secret.secret-with-annotations",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl"},
},
{
Config: testAccSecretManagerSecret_annotationsUpdate(context),
},
{
ResourceName: "google_secret_manager_secret.secret-with-annotations",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl"},
},
{
Config: testAccSecretManagerSecret_annotationsBasic(context),
},
{
ResourceName: "google_secret_manager_secret.secret-with-annotations",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ttl"},
},
},
})
}

func testAccSecretManagerSecret_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_secret_manager_secret" "secret-basic" {
Expand Down Expand Up @@ -127,3 +170,50 @@ resource "google_secret_manager_secret" "secret-basic" {
}
`, context)
}

func testAccSecretManagerSecret_annotationsBasic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_secret_manager_secret" "secret-with-annotations" {
secret_id = "tf-test-secret-%{random_suffix}"

labels = {
label = "my-label"
}

annotations = {
key1 = "someval"
key2 = "someval2"
key3 = "someval3"
key4 = "someval4"
key5 = "someval5"
}

replication {
automatic = true
}
}
`, context)
}

func testAccSecretManagerSecret_annotationsUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_secret_manager_secret" "secret-with-annotations" {
secret_id = "tf-test-secret-%{random_suffix}"

labels = {
label = "my-label"
}

annotations = {
key1 = "someval"
key2update = "someval2"
key3 = "someval3update"
key4update = "someval4update"
}

replication {
automatic = true
}
}
`, context)
}

0 comments on commit d098c6d

Please sign in to comment.