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 tag value resource #4603

Merged
merged 5 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
56 changes: 56 additions & 0 deletions mmv1/products/tags/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,59 @@ objects:

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
output: true
- !ruby/object:Api::Resource
name: 'TagValue'
min_version: beta
base_url: tagValues
self_link: "tagValues/{{name}}"
update_verb: :PATCH
update_mask: true
description: A TagValue is a child of a particular TagKey. TagValues are used to group cloud resources for the purpose of controlling them using policies.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing'
api: 'https://cloud.google.com/resource-manager/reference/rest/v3/tagValues'
properties:
- !ruby/object:Api::Type::String
name: name
description: |
The generated numeric id for the TagValue.
output: true
- !ruby/object:Api::Type::String
name: parent
description: |
Input only. The resource name of the new TagValue's parent. Must be of the form tagKeys/{tag_key_id}.
input: true
required: true
- !ruby/object:Api::Type::String
name: shortName
description: |
Input only. User-assigned short name for TagValue. The short name should be unique for TagValues within the same parent TagKey.

The short name must be 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between.
input: true
required: true
- !ruby/object:Api::Type::String
name: namespacedName
description: |
Output only. Namespaced name of the TagValue. Will be in the format {organizationId}/{tag_key_short_name}/{shortName}.
output: true
- !ruby/object:Api::Type::String
name: description
description: |
User-assigned description of the TagValue. Must not exceed 256 characters.
melinath marked this conversation as resolved.
Show resolved Hide resolved
- !ruby/object:Api::Type::String
name: createTime
description: |
Output only. Creation time.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
output: true
- !ruby/object:Api::Type::String
name: updateTime
description: |
Output only. Update time.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
output: true
19 changes: 18 additions & 1 deletion mmv1/products/tags/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,27 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "tag_key_basic"
min_version: 'beta'
skip_vcr: true
skip_test: true
primary_resource_id: "key"
vars:
short_name: "foo"
test_env_vars:
org_id: :ORG_ID
TagValue: !ruby/object:Overrides::Terraform::ResourceOverride
autogen_async: true
mutex: tagValue/{{parent}}
id_format: "tagValues/{{name}}"
import_format: ["tagValues/{{name}}", "{{name}}"]
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
examples:
- !ruby/object:Provider::Terraform::Examples
name: "tag_value_basic"
min_version: 'beta'
skip_test: true
primary_resource_id: "value"
vars:
short_name: "foo"
test_env_vars:
org_id: :ORG_ID
15 changes: 15 additions & 0 deletions mmv1/templates/terraform/examples/tag_value_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
short_name = "keyname"
description = "For a certain set of resources."
}

resource "google_tags_tag_value" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "<%= ctx[:vars]['short_name'] %>"
description = "For <%= ctx[:vars]['short_name'] %> resources.""
}
156 changes: 153 additions & 3 deletions mmv1/third_party/terraform/tests/resource_tags_tag_key_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (

func TestAccTags(t *testing.T) {
testCases := map[string]func(t *testing.T){
"basic": testAccTagsTagKey_tagKeyBasic,
"update": testAccTagsTagKey_update,
"tagKeyBasic": testAccTagsTagKey_tagKeyBasic,
"tagKeyUpdate": testAccTagsTagKey_tagKeyUpdate,
"tagValueBasic": testAccTagsTagValue_tagValueBasic,
"tagValueUpdate": testAccTagsTagValue_tagValueUpdate,
}

for name, tc := range testCases {
Expand Down Expand Up @@ -65,7 +67,7 @@ resource "google_tags_tag_key" "key" {
`, context)
}

func testAccTagsTagKey_update(t *testing.T) {
func testAccTagsTagKey_tagKeyUpdate(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"random_suffix": randString(t, 10),
Expand Down Expand Up @@ -156,4 +158,152 @@ func testAccCheckTagsTagKeyDestroyProducer(t *testing.T) func(s *terraform.State
}
}

func testAccTagsTagValue_tagValueBasic(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
CheckDestroy: testAccCheckTagsTagValueDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccTagsTagValue_tagValueBasicExample(context),
},
},
})
}

func testAccTagsTagValue_tagValueBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/%{org_id}"
short_name = "foobarbaz%{random_suffix}"
description = "For foo/bar/baz resources."
}

resource "google_tags_tag_value" "value" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "foo%{random_suffix}"
description = "For foo resources."
}
`, context)
}

func testAccTagsTagValue_tagValueUpdate(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
CheckDestroy: testAccCheckTagsTagValueDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccTagsTagValue_basic(context),
},
{
ResourceName: "google_tags_tag_key.key",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccTagsTagValue_basicUpdated(context),
},
{
ResourceName: "google_tags_tag_key.key",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccTagsTagValue_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/%{org_id}"
short_name = "foobarbaz%{random_suffix}"
description = "For foo/bar/baz resources."
}

resource "google_tags_tag_value" "value" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "foo%{random_suffix}"
description = "For foo resources."
}
`, context)
}

func testAccTagsTagValue_basicUpdated(context map[string]interface{}) string {
return Nprintf(`
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/%{org_id}"
short_name = "foobarbaz%{random_suffix}"
description = "For foo/bar/baz resources."
}

resource "google_tags_tag_value" "value" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "foo%{random_suffix}"
description = "For any foo resources."
}
`, context)
}

func testAccCheckTagsTagValueDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_tags_tag_key" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{TagsBasePath}}tagValues/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
if err == nil {
return fmt.Errorf("TagsTagValue still exists at %s", url)
}
}

return nil
}
}

<% end %>