From f31b02cffbe863a6bfdb4ff0aa75da9f810cf5b6 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 12 Dec 2022 04:13:16 +0000 Subject: [PATCH] Adding Support to update DataCatalog TagTemplate fields (#6803) fixes https://github.com/hashicorp/terraform-provider-google/issues/6574 Signed-off-by: Modular Magician --- .../resources/datacatalog_tag_template.go | 46 +++++++++++++++++++ go.mod | 2 +- go.sum | 4 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/converters/google/resources/datacatalog_tag_template.go b/converters/google/resources/datacatalog_tag_template.go index b14681300..7efd1aff0 100644 --- a/converters/google/resources/datacatalog_tag_template.go +++ b/converters/google/resources/datacatalog_tag_template.go @@ -15,11 +15,57 @@ package google import ( + "fmt" + "log" "reflect" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +//Use it to delete TagTemplate Field +func deleteTagTemplateField(d *schema.ResourceData, config *Config, name, billingProject, userAgent string) error { + + url_delete, err := replaceVars(d, config, "{{DataCatalogBasePath}}{{name}}/fields/"+name+"?force={{force_delete}}") + if err != nil { + return err + } + var obj map[string]interface{} + res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url_delete, userAgent, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return fmt.Errorf("Error deleting TagTemplate Field %v: %s", name, err) + } + + log.Printf("[DEBUG] Finished deleting TagTemplate Field %q: %#v", name, res) + return nil +} + +//Use it to create TagTemplate Field +func createTagTemplateField(d *schema.ResourceData, config *Config, body map[string]interface{}, name, billingProject, userAgent string) error { + + url_create, err := replaceVars(d, config, "{{DataCatalogBasePath}}{{name}}/fields") + if err != nil { + return err + } + + url_create, err = addQueryParams(url_create, map[string]string{"tagTemplateFieldId": name}) + if err != nil { + return err + } + + res_create, err := sendRequestWithTimeout(config, "POST", billingProject, url_create, userAgent, body, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating TagTemplate Field: %s", err) + } + + if err != nil { + return fmt.Errorf("Error creating TagTemplate Field %v: %s", name, err) + } else { + log.Printf("[DEBUG] Finished creating TagTemplate Field %v: %#v", name, res_create) + } + + return nil +} + const DataCatalogTagTemplateAssetType string = "datacatalog.googleapis.com/TagTemplate" func resourceConverterDataCatalogTagTemplate() ResourceConverter { diff --git a/go.mod b/go.mod index 59ce4e037..d384a41fc 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/terraform-json v0.14.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 - github.com/hashicorp/terraform-provider-google v1.20.1-0.20221209230321-348619fa2dd2 + github.com/hashicorp/terraform-provider-google v1.20.1-0.20221212040814-3433c55b7ef9 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.0 diff --git a/go.sum b/go.sum index 5715fb688..b1558e511 100644 --- a/go.sum +++ b/go.sum @@ -514,8 +514,8 @@ github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 h1:FtCLTiTcykdsURXPt/ku7fYXm3y19nbzbZcUxHx9RbI= github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0/go.mod h1:80wf5oad1tW+oLnbXS4UTYmDCrl7BuN1Q+IA91X1a4Y= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20221209230321-348619fa2dd2 h1:RFZvI9QgBqODe5AM3zxS0i0SBc2kUFhkkrgs5/VExl4= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20221209230321-348619fa2dd2/go.mod h1:noO9KRFUJgJg9g+VaIqh0oUlr3GaDCtbFB+KD+iBgeI= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20221212040814-3433c55b7ef9 h1:pB3Nb1dcB40XaEqmihq5HMDHlV+ajB9nQsIO7Sbt57s= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20221212040814-3433c55b7ef9/go.mod h1:noO9KRFUJgJg9g+VaIqh0oUlr3GaDCtbFB+KD+iBgeI= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=