Skip to content

Commit

Permalink
Data Catalog EntryGroup (#3485) (#6438)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored May 20, 2020
1 parent ddb242e commit cc62c6b
Show file tree
Hide file tree
Showing 12 changed files with 1,294 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .changelog/3485.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```release-note:new-resource
`google_data_catalog_entry_group`
```
```release-note:new-resource
`google_data_catalog_entry_group_iam_member`
```
```release-note:new-resource
`google_data_catalog_entry_group_iam_binding`
```
```release-note:new-resource
`google_data_catalog_entry_group_iam_policy`
```
3 changes: 3 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type Config struct {
CloudTasksBasePath string
ComputeBasePath string
ContainerAnalysisBasePath string
DataCatalogBasePath string
DataprocBasePath string
DatastoreBasePath string
DeploymentManagerBasePath string
Expand Down Expand Up @@ -231,6 +232,7 @@ var CloudSchedulerDefaultBasePath = "https://cloudscheduler.googleapis.com/v1/"
var CloudTasksDefaultBasePath = "https://cloudtasks.googleapis.com/v2/"
var ComputeDefaultBasePath = "https://www.googleapis.com/compute/v1/"
var ContainerAnalysisDefaultBasePath = "https://containeranalysis.googleapis.com/v1/"
var DataCatalogDefaultBasePath = "https://datacatalog.googleapis.com/v1/"
var DataprocDefaultBasePath = "https://dataproc.googleapis.com/v1/"
var DatastoreDefaultBasePath = "https://datastore.googleapis.com/v1/"
var DeploymentManagerDefaultBasePath = "https://www.googleapis.com/deploymentmanager/v2/"
Expand Down Expand Up @@ -745,6 +747,7 @@ func ConfigureBasePaths(c *Config) {
c.CloudTasksBasePath = CloudTasksDefaultBasePath
c.ComputeBasePath = ComputeDefaultBasePath
c.ContainerAnalysisBasePath = ContainerAnalysisDefaultBasePath
c.DataCatalogBasePath = DataCatalogDefaultBasePath
c.DataprocBasePath = DataprocDefaultBasePath
c.DatastoreBasePath = DatastoreDefaultBasePath
c.DeploymentManagerBasePath = DeploymentManagerDefaultBasePath
Expand Down
200 changes: 200 additions & 0 deletions google/iam_data_catalog_entry_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// ----------------------------------------------------------------------------
//
// *** 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/helper/schema"
"google.golang.org/api/cloudresourcemanager/v1"
)

var DataCatalogEntryGroupIamSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"entry_group": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type DataCatalogEntryGroupIamUpdater struct {
project string
region string
entryGroup string
d *schema.ResourceData
Config *Config
}

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

project, _ := getProject(d, config)
if project != "" {
d.Set("project", project)
}
values["project"] = project
region, _ := getRegion(d, config)
if region != "" {
d.Set("region", region)
}
values["region"] = region
if v, ok := d.GetOk("entry_group"); ok {
values["entry_group"] = v.(string)
}

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

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

u := &DataCatalogEntryGroupIamUpdater{
project: values["project"],
region: values["region"],
entryGroup: values["entry_group"],
d: d,
Config: config,
}

d.Set("project", u.project)
d.Set("region", u.region)
d.Set("entry_group", u.GetResourceId())

return u, nil
}

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

project, _ := getProject(d, config)
if project != "" {
values["project"] = project
}

region, _ := getRegion(d, config)
if region != "" {
values["region"] = region
}

m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/entryGroups/(?P<entry_group>[^/]+)", "(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<entry_group>[^/]+)", "(?P<region>[^/]+)/(?P<entry_group>[^/]+)", "(?P<entry_group>[^/]+)"}, d, config, d.Id())
if err != nil {
return err
}

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

u := &DataCatalogEntryGroupIamUpdater{
project: values["project"],
region: values["region"],
entryGroup: values["entry_group"],
d: d,
Config: config,
}
d.Set("entry_group", u.GetResourceId())
d.SetId(u.GetResourceId())
return nil
}

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

project, err := getProject(u.d, u.Config)
if err != nil {
return nil, err
}
var obj map[string]interface{}

policy, err := sendRequest(u.Config, "POST", project, url, 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 *DataCatalogEntryGroupIamUpdater) 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.qualifyEntryGroupUrl("setIamPolicy")
if err != nil {
return err
}
project, err := getProject(u.d, u.Config)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", project, url, 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 *DataCatalogEntryGroupIamUpdater) qualifyEntryGroupUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{DataCatalogBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", u.project, u.region, u.entryGroup), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *DataCatalogEntryGroupIamUpdater) GetResourceId() string {
return fmt.Sprintf("projects/%s/locations/%s/entryGroups/%s", u.project, u.region, u.entryGroup)
}

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

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

0 comments on commit cc62c6b

Please sign in to comment.