Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
cloud run v2 iam support (#7091) (#1286)
Browse files Browse the repository at this point in the history
Closes hashicorp/terraform-provider-google#13394

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 13, 2023
1 parent e6efca7 commit 9de4e3d
Show file tree
Hide file tree
Showing 5 changed files with 698 additions and 0 deletions.
123 changes: 123 additions & 0 deletions converters/google/resources/cloud_run_v2_job_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 CloudRunV2JobIAMAssetType string = "run.googleapis.com/Job"

func resourceConverterCloudRunV2JobIamPolicy() ResourceConverter {
return ResourceConverter{
AssetType: CloudRunV2JobIAMAssetType,
Convert: GetCloudRunV2JobIamPolicyCaiObject,
MergeCreateUpdate: MergeCloudRunV2JobIamPolicy,
}
}

func resourceConverterCloudRunV2JobIamBinding() ResourceConverter {
return ResourceConverter{
AssetType: CloudRunV2JobIAMAssetType,
Convert: GetCloudRunV2JobIamBindingCaiObject,
FetchFullResource: FetchCloudRunV2JobIamPolicy,
MergeCreateUpdate: MergeCloudRunV2JobIamBinding,
MergeDelete: MergeCloudRunV2JobIamBindingDelete,
}
}

func resourceConverterCloudRunV2JobIamMember() ResourceConverter {
return ResourceConverter{
AssetType: CloudRunV2JobIAMAssetType,
Convert: GetCloudRunV2JobIamMemberCaiObject,
FetchFullResource: FetchCloudRunV2JobIamPolicy,
MergeCreateUpdate: MergeCloudRunV2JobIamMember,
MergeDelete: MergeCloudRunV2JobIamMemberDelete,
}
}

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

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

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

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

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

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

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

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

func newCloudRunV2JobIamAsset(
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, "//run.googleapis.com/projects/{{project}}/locations/{{location}}/jobs/{{name}}")
if err != nil {
return []Asset{}, err
}

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

func FetchCloudRunV2JobIamPolicy(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("name"); !ok {
return Asset{}, ErrEmptyIdentityField
}

return fetchIamPolicy(
CloudRunV2JobIamUpdaterProducer,
d,
config,
"//run.googleapis.com/projects/{{project}}/locations/{{location}}/jobs/{{name}}",
CloudRunV2JobIAMAssetType,
)
}
123 changes: 123 additions & 0 deletions converters/google/resources/cloud_run_v2_service_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 CloudRunV2ServiceIAMAssetType string = "run.googleapis.com/Service"

func resourceConverterCloudRunV2ServiceIamPolicy() ResourceConverter {
return ResourceConverter{
AssetType: CloudRunV2ServiceIAMAssetType,
Convert: GetCloudRunV2ServiceIamPolicyCaiObject,
MergeCreateUpdate: MergeCloudRunV2ServiceIamPolicy,
}
}

func resourceConverterCloudRunV2ServiceIamBinding() ResourceConverter {
return ResourceConverter{
AssetType: CloudRunV2ServiceIAMAssetType,
Convert: GetCloudRunV2ServiceIamBindingCaiObject,
FetchFullResource: FetchCloudRunV2ServiceIamPolicy,
MergeCreateUpdate: MergeCloudRunV2ServiceIamBinding,
MergeDelete: MergeCloudRunV2ServiceIamBindingDelete,
}
}

func resourceConverterCloudRunV2ServiceIamMember() ResourceConverter {
return ResourceConverter{
AssetType: CloudRunV2ServiceIAMAssetType,
Convert: GetCloudRunV2ServiceIamMemberCaiObject,
FetchFullResource: FetchCloudRunV2ServiceIamPolicy,
MergeCreateUpdate: MergeCloudRunV2ServiceIamMember,
MergeDelete: MergeCloudRunV2ServiceIamMemberDelete,
}
}

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

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

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

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

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

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

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

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

func newCloudRunV2ServiceIamAsset(
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, "//run.googleapis.com/projects/{{project}}/locations/{{location}}/services/{{name}}")
if err != nil {
return []Asset{}, err
}

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

func FetchCloudRunV2ServiceIamPolicy(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("name"); !ok {
return Asset{}, ErrEmptyIdentityField
}

return fetchIamPolicy(
CloudRunV2ServiceIamUpdaterProducer,
d,
config,
"//run.googleapis.com/projects/{{project}}/locations/{{location}}/services/{{name}}",
CloudRunV2ServiceIAMAssetType,
)
}
Loading

0 comments on commit 9de4e3d

Please sign in to comment.