Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
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
123 changes: 123 additions & 0 deletions converters/google/resources/dataproc_autoscaling_policy_iam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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"

// Provide a separate asset type constant so we don't have to worry about name conflicts between IAM and non-IAM converter files
const DataprocAutoscalingPolicyIAMAssetType string = "dataproc.googleapis.com/AutoscalingPolicy"

func resourceConverterDataprocAutoscalingPolicyIamPolicy() ResourceConverter {
return ResourceConverter{
AssetType: DataprocAutoscalingPolicyIAMAssetType,
Convert: GetDataprocAutoscalingPolicyIamPolicyCaiObject,
MergeCreateUpdate: MergeDataprocAutoscalingPolicyIamPolicy,
}
}

func resourceConverterDataprocAutoscalingPolicyIamBinding() ResourceConverter {
return ResourceConverter{
AssetType: DataprocAutoscalingPolicyIAMAssetType,
Convert: GetDataprocAutoscalingPolicyIamBindingCaiObject,
FetchFullResource: FetchDataprocAutoscalingPolicyIamPolicy,
MergeCreateUpdate: MergeDataprocAutoscalingPolicyIamBinding,
MergeDelete: MergeDataprocAutoscalingPolicyIamBindingDelete,
}
}

func resourceConverterDataprocAutoscalingPolicyIamMember() ResourceConverter {
return ResourceConverter{
AssetType: DataprocAutoscalingPolicyIAMAssetType,
Convert: GetDataprocAutoscalingPolicyIamMemberCaiObject,
FetchFullResource: FetchDataprocAutoscalingPolicyIamPolicy,
MergeCreateUpdate: MergeDataprocAutoscalingPolicyIamMember,
MergeDelete: MergeDataprocAutoscalingPolicyIamMemberDelete,
}
}

func GetDataprocAutoscalingPolicyIamPolicyCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
return newDataprocAutoscalingPolicyIamAsset(d, config, expandIamPolicyBindings)
}

func GetDataprocAutoscalingPolicyIamBindingCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
return newDataprocAutoscalingPolicyIamAsset(d, config, expandIamRoleBindings)
}

func GetDataprocAutoscalingPolicyIamMemberCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
return newDataprocAutoscalingPolicyIamAsset(d, config, expandIamMemberBindings)
}

func MergeDataprocAutoscalingPolicyIamPolicy(existing, incoming Asset) Asset {
existing.IAMPolicy = incoming.IAMPolicy
return existing
}

func MergeDataprocAutoscalingPolicyIamBinding(existing, incoming Asset) Asset {
return mergeIamAssets(existing, incoming, mergeAuthoritativeBindings)
}

func MergeDataprocAutoscalingPolicyIamBindingDelete(existing, incoming Asset) Asset {
return mergeDeleteIamAssets(existing, incoming, mergeDeleteAuthoritativeBindings)
}

func MergeDataprocAutoscalingPolicyIamMember(existing, incoming Asset) Asset {
return mergeIamAssets(existing, incoming, mergeAdditiveBindings)
}

func MergeDataprocAutoscalingPolicyIamMemberDelete(existing, incoming Asset) Asset {
return mergeDeleteIamAssets(existing, incoming, mergeDeleteAdditiveBindings)
}

func newDataprocAutoscalingPolicyIamAsset(
d TerraformResourceData,
config *Config,
expandBindings func(d TerraformResourceData) ([]IAMBinding, error),
) ([]Asset, error) {
bindings, err := expandBindings(d)
if err != nil {
return []Asset{}, fmt.Errorf("expanding bindings: %v", err)
}

name, err := assetName(d, config, "//dataproc.googleapis.com/projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}")
if err != nil {
return []Asset{}, err
}

return []Asset{{
Name: name,
Type: DataprocAutoscalingPolicyIAMAssetType,
IAMPolicy: &IAMPolicy{
Bindings: bindings,
},
}}, nil
}

func FetchDataprocAutoscalingPolicyIamPolicy(d TerraformResourceData, config *Config) (Asset, error) {
// Check if the identity field returns a value
if _, ok := d.GetOk("location"); !ok {
return Asset{}, ErrEmptyIdentityField
}
if _, ok := d.GetOk("policy_id"); !ok {
return Asset{}, ErrEmptyIdentityField
}

return fetchIamPolicy(
DataprocAutoscalingPolicyIamUpdaterProducer,
d,
config,
"//dataproc.googleapis.com/projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}}",
DataprocAutoscalingPolicyIAMAssetType,
)
}
222 changes: 222 additions & 0 deletions converters/google/resources/iam_dataproc_autoscaling_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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 DataprocAutoscalingPolicyIamSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"location": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"policy_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type DataprocAutoscalingPolicyIamUpdater struct {
project string
location string
policyId string
d TerraformResourceData
Config *Config
}

func DataprocAutoscalingPolicyIamUpdaterProducer(d TerraformResourceData, config *Config) (ResourceIamUpdater, error) {
values := make(map[string]string)

project, _ := getProject(d, config)
if project != "" {
if err := d.Set("project", project); err != nil {
return nil, fmt.Errorf("Error setting project: %s", err)
}
}
values["project"] = project
location, _ := getLocation(d, config)
if location != "" {
if err := d.Set("location", location); err != nil {
return nil, fmt.Errorf("Error setting location: %s", err)
}
}
values["location"] = location
if v, ok := d.GetOk("policy_id"); ok {
values["policy_id"] = 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<location>[^/]+)/autoscalingPolicies/(?P<policy_id>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<policy_id>[^/]+)", "(?P<location>[^/]+)/(?P<policy_id>[^/]+)", "(?P<policy_id>[^/]+)"}, d, config, d.Get("policy_id").(string))
if err != nil {
return nil, err
}

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

u := &DataprocAutoscalingPolicyIamUpdater{
project: values["project"],
location: values["location"],
policyId: values["policy_id"],
d: d,
Config: config,
}

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

return u, nil
}

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

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

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

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

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

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

func (u *DataprocAutoscalingPolicyIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url, err := u.qualifyAutoscalingPolicyUrl("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{}

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

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

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

_, err = sendRequestWithTimeout(u.Config, "POST", project, 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 *DataprocAutoscalingPolicyIamUpdater) qualifyAutoscalingPolicyUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{DataprocBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", u.project, u.location, u.policyId), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *DataprocAutoscalingPolicyIamUpdater) GetResourceId() string {
return fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", u.project, u.location, u.policyId)
}

func (u *DataprocAutoscalingPolicyIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-dataproc-autoscalingpolicy-%s", u.GetResourceId())
}

func (u *DataprocAutoscalingPolicyIamUpdater) DescribeResource() string {
return fmt.Sprintf("dataproc autoscalingpolicy %q", u.GetResourceId())
}
3 changes: 3 additions & 0 deletions converters/google/resources/resource_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func ResourceConverters() map[string][]ResourceConverter {
"google_data_catalog_tag_template_iam_policy": {resourceConverterDataCatalogTagTemplateIamPolicy()},
"google_data_catalog_tag_template_iam_binding": {resourceConverterDataCatalogTagTemplateIamBinding()},
"google_data_catalog_tag_template_iam_member": {resourceConverterDataCatalogTagTemplateIamMember()},
"google_dataproc_autoscaling_policy_iam_policy": {resourceConverterDataprocAutoscalingPolicyIamPolicy()},
"google_dataproc_autoscaling_policy_iam_binding": {resourceConverterDataprocAutoscalingPolicyIamBinding()},
"google_dataproc_autoscaling_policy_iam_member": {resourceConverterDataprocAutoscalingPolicyIamMember()},
"google_healthcare_consent_store_iam_policy": {resourceConverterHealthcareConsentStoreIamPolicy()},
"google_healthcare_consent_store_iam_binding": {resourceConverterHealthcareConsentStoreIamBinding()},
"google_healthcare_consent_store_iam_member": {resourceConverterHealthcareConsentStoreIamMember()},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/terraform-json v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220630230611-ec67375b4853
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220701170018-4f0e4faec052
github.com/kr/pretty v0.3.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/gomega v1.17.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ github.com/hashicorp/terraform-plugin-log v0.4.0 h1:F3eVnm8r2EfQCe2k9blPIiF/r2TT
github.com/hashicorp/terraform-plugin-log v0.4.0/go.mod h1:9KclxdunFownr4pIm1jdmwKRmE4d6HVG2c9XDq47rpg=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0 h1:9fjPgCenJqnbjo95SDcbJ+YdLyEC1N35cwKWcRWhJTQ=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0/go.mod h1:hLa0sTiySU/AWEgV2GxJh0/pQIqcCmm30IPja9N9lTg=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220630230611-ec67375b4853 h1:TUjhHIsc7wBfeYzfxgwahEifWVzzqXiroO8C66A4750=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220630230611-ec67375b4853/go.mod h1:g7W3U8u64D5uAPK5wMiBiToVAYKk4XxRL3yVCU1HYAI=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220701170018-4f0e4faec052 h1:se+nq7nTxzbEovbDgS2g+2hs1pAhxsGn5ldtDtwP/Jo=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20220701170018-4f0e4faec052/go.mod h1:g7W3U8u64D5uAPK5wMiBiToVAYKk4XxRL3yVCU1HYAI=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 h1:1FGtlkJw87UsTMg5s8jrekrHmUPUJaMcu6ELiVhQrNw=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand Down