Skip to content

Commit

Permalink
add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
abd-goog committed Aug 12, 2024
1 parent a33654d commit 3002e66
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func ResourceGoogleFolder() *schema.Resource {
Computed: true,
Description: `Timestamp when the Folder was created. Assigned by the server. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".`,
},
"tags": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `A map of resource manager tags. Resource manager tag keys and values have the same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456. The field is ignored when empty.`,
},
},
UseJSONNumber: true,
}
Expand All @@ -80,6 +87,14 @@ func resourceGoogleFolderCreate(d *schema.ResourceData, meta interface{}) error
displayName := d.Get("display_name").(string)
parent := d.Get("parent").(string)

folder := &cloudresourcemanager.Folder{
DisplayName: displayName,
Parent: parent,
}
if _, ok := d.GetOk("tags"); ok {
folder.Tags = tpgresource.ExpandStringMap(d, "tags")
}

var op *resourceManagerV3.Operation
err = transport_tpg.Retry(transport_tpg.RetryOptions{
RetryFunc: func() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resourcemanager_test

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -87,6 +88,41 @@ func TestAccFolder_moveParent(t *testing.T) {
})
}

// Test that a Project resource can be created with tags
func TestAccFolder_tags(t *testing.T) {
t.Parallel()

org := envvar.GetTestOrgFromEnv(t)
pid := fmt.Sprintf("%s-%d", TestPrefix, acctest.RandInt(t))
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccFolder_tags(pid, org, map[string]string{org + "/env": "test"}),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleFolderExists("google_folder.acceptance", pid),
),
},
// Make sure import supports tags
{
ResourceName: "google_folder.acceptance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"tags", "deletion_protection"}, // we don't read tags back
},
// Update tags tries to replace project but fails due to deletion protection
{
Config: testAccFolder_tags(pid, org, map[string]string{org + "/env": "staging"}),
ExpectError: regexp.MustCompile("deletion_protection"),
},
{
Config: testAccFolder_tagsAllowDestroy(pid, org, map[string]string{org + "/env": "test"}),
},
},
})
}

func testAccCheckGoogleFolderDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)
Expand Down

0 comments on commit 3002e66

Please sign in to comment.