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

Add taxonomy and policy_tag resources to data_catalog product #2626

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
10 changes: 10 additions & 0 deletions .changelog/4076.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```release-note:new-resource
`google_data_catalog_taxonomy`
`google_data_catalog_policy_tag`
`google_data_catalog_taxonomy_iam_binding`
`google_data_catalog_taxonomy_iam_member`
`google_data_catalog_taxonomy_iam_policy`
`google_data_catalog_policy_tag_iam_binding`
`google_data_catalog_policy_tag_iam_member`
`google_data_catalog_policy_tag_iam_policy`
```
2 changes: 1 addition & 1 deletion google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var CloudSchedulerDefaultBasePath = "https://cloudscheduler.googleapis.com/v1/"
var CloudTasksDefaultBasePath = "https://cloudtasks.googleapis.com/v2/"
var ComputeDefaultBasePath = "https://compute.googleapis.com/compute/beta/"
var ContainerAnalysisDefaultBasePath = "https://containeranalysis.googleapis.com/v1beta1/"
var DataCatalogDefaultBasePath = "https://datacatalog.googleapis.com/v1/"
var DataCatalogDefaultBasePath = "https://datacatalog.googleapis.com/v1beta1/"
var DataFusionDefaultBasePath = "https://datafusion.googleapis.com/v1beta1/"
var DataLossPreventionDefaultBasePath = "https://dlp.googleapis.com/v2/"
var DataprocDefaultBasePath = "https://dataproc.googleapis.com/v1beta2/"
Expand Down
166 changes: 166 additions & 0 deletions google-beta/iam_data_catalog_policy_tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package google

import (
"fmt"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"google.golang.org/api/cloudresourcemanager/v1"
)

var DataCatalogPolicyTagIamSchema = map[string]*schema.Schema{
"policy_tag": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type DataCatalogPolicyTagIamUpdater struct {
policyTag string
d *schema.ResourceData
Config *Config
}

func DataCatalogPolicyTagIamUpdaterProducer(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) {
values := make(map[string]string)

if v, ok := d.GetOk("policy_tag"); ok {
values["policy_tag"] = v.(string)
}

// We may have gotten either a long or short name, so attempt to parse long name if possible
m, err := getImportIdQualifiers([]string{"(?P<policy_tag>.+)"}, d, config, d.Get("policy_tag").(string))
if err != nil {
return nil, err
}

for k, v := range m {
values[k] = v
}

u := &DataCatalogPolicyTagIamUpdater{
policyTag: values["policy_tag"],
d: d,
Config: config,
}

if err := d.Set("policy_tag", u.GetResourceId()); err != nil {
return nil, fmt.Errorf("Error setting policy_tag: %s", err)
}

return u, nil
}

func DataCatalogPolicyTagIdParseFunc(d *schema.ResourceData, config *Config) error {
values := make(map[string]string)

m, err := getImportIdQualifiers([]string{"(?P<policy_tag>.+)"}, d, config, d.Id())
if err != nil {
return err
}

for k, v := range m {
values[k] = v
}

u := &DataCatalogPolicyTagIamUpdater{
policyTag: values["policy_tag"],
d: d,
Config: config,
}
if err := d.Set("policy_tag", u.GetResourceId()); err != nil {
return fmt.Errorf("Error setting policy_tag: %s", err)
}
d.SetId(u.GetResourceId())
return nil
}

func (u *DataCatalogPolicyTagIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url, err := u.qualifyPolicyTagUrl("getIamPolicy")
if err != nil {
return nil, err
}

var obj map[string]interface{}

userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
if err != nil {
return nil, err
}

policy, err := sendRequest(u.Config, "POST", "", url, userAgent, obj)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}

out := &cloudresourcemanager.Policy{}
err = Convert(policy, out)
if err != nil {
return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err)
}

return out, nil
}

func (u *DataCatalogPolicyTagIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
json, err := ConvertToMap(policy)
if err != nil {
return err
}

obj := make(map[string]interface{})
obj["policy"] = json

url, err := u.qualifyPolicyTagUrl("setIamPolicy")
if err != nil {
return err
}

userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", "", url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate))
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}

return nil
}

func (u *DataCatalogPolicyTagIamUpdater) qualifyPolicyTagUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{DataCatalogBasePath}}%s:%s", fmt.Sprintf("%s", u.policyTag), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *DataCatalogPolicyTagIamUpdater) GetResourceId() string {
return fmt.Sprintf("%s", u.policyTag)
}

func (u *DataCatalogPolicyTagIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-datacatalog-policytag-%s", u.GetResourceId())
}

func (u *DataCatalogPolicyTagIamUpdater) DescribeResource() string {
return fmt.Sprintf("datacatalog policytag %q", u.GetResourceId())
}
Loading