This repository has been archived by the owner on May 15, 2023. It is now read-only.
/
cloudfunctions2_function_iam.go
123 lines (104 loc) · 4.36 KB
/
cloudfunctions2_function_iam.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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 Cloudfunctions2functionIAMAssetType string = "cloudfunctions.googleapis.com/function"
func resourceConverterCloudfunctions2functionIamPolicy() ResourceConverter {
return ResourceConverter{
AssetType: Cloudfunctions2functionIAMAssetType,
Convert: GetCloudfunctions2functionIamPolicyCaiObject,
MergeCreateUpdate: MergeCloudfunctions2functionIamPolicy,
}
}
func resourceConverterCloudfunctions2functionIamBinding() ResourceConverter {
return ResourceConverter{
AssetType: Cloudfunctions2functionIAMAssetType,
Convert: GetCloudfunctions2functionIamBindingCaiObject,
FetchFullResource: FetchCloudfunctions2functionIamPolicy,
MergeCreateUpdate: MergeCloudfunctions2functionIamBinding,
MergeDelete: MergeCloudfunctions2functionIamBindingDelete,
}
}
func resourceConverterCloudfunctions2functionIamMember() ResourceConverter {
return ResourceConverter{
AssetType: Cloudfunctions2functionIAMAssetType,
Convert: GetCloudfunctions2functionIamMemberCaiObject,
FetchFullResource: FetchCloudfunctions2functionIamPolicy,
MergeCreateUpdate: MergeCloudfunctions2functionIamMember,
MergeDelete: MergeCloudfunctions2functionIamMemberDelete,
}
}
func GetCloudfunctions2functionIamPolicyCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
return newCloudfunctions2functionIamAsset(d, config, expandIamPolicyBindings)
}
func GetCloudfunctions2functionIamBindingCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
return newCloudfunctions2functionIamAsset(d, config, expandIamRoleBindings)
}
func GetCloudfunctions2functionIamMemberCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
return newCloudfunctions2functionIamAsset(d, config, expandIamMemberBindings)
}
func MergeCloudfunctions2functionIamPolicy(existing, incoming Asset) Asset {
existing.IAMPolicy = incoming.IAMPolicy
return existing
}
func MergeCloudfunctions2functionIamBinding(existing, incoming Asset) Asset {
return mergeIamAssets(existing, incoming, mergeAuthoritativeBindings)
}
func MergeCloudfunctions2functionIamBindingDelete(existing, incoming Asset) Asset {
return mergeDeleteIamAssets(existing, incoming, mergeDeleteAuthoritativeBindings)
}
func MergeCloudfunctions2functionIamMember(existing, incoming Asset) Asset {
return mergeIamAssets(existing, incoming, mergeAdditiveBindings)
}
func MergeCloudfunctions2functionIamMemberDelete(existing, incoming Asset) Asset {
return mergeDeleteIamAssets(existing, incoming, mergeDeleteAdditiveBindings)
}
func newCloudfunctions2functionIamAsset(
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, "//cloudfunctions.googleapis.com/projects/{{project}}/locations/{{location}}/functions/{{cloud_function}}")
if err != nil {
return []Asset{}, err
}
return []Asset{{
Name: name,
Type: Cloudfunctions2functionIAMAssetType,
IAMPolicy: &IAMPolicy{
Bindings: bindings,
},
}}, nil
}
func FetchCloudfunctions2functionIamPolicy(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("cloud_function"); !ok {
return Asset{}, ErrEmptyIdentityField
}
return fetchIamPolicy(
Cloudfunctions2functionIamUpdaterProducer,
d,
config,
"//cloudfunctions.googleapis.com/projects/{{project}}/locations/{{location}}/functions/{{cloud_function}}",
Cloudfunctions2functionIAMAssetType,
)
}