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

Added support for annotations field in google_secret_manager_secret resource #8500

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
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
slevenick marked this conversation as resolved.
Show resolved Hide resolved
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)
}