Skip to content

Commit ed4ffec

Browse files
promote cfn2 to ga (#6388) (#12322)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 180c6ab commit ed4ffec

11 files changed

+3098
-56
lines changed

.changelog/6388.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudfunction2: promote to `google_cloudfunctions2_function` ga
3+
```

google/cloudfunctions2_operation.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import (
18+
"encoding/json"
19+
"fmt"
20+
"time"
21+
)
22+
23+
type Cloudfunctions2OperationWaiter struct {
24+
Config *Config
25+
UserAgent string
26+
Project string
27+
CommonOperationWaiter
28+
}
29+
30+
func (w *Cloudfunctions2OperationWaiter) QueryOp() (interface{}, error) {
31+
if w == nil {
32+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
33+
}
34+
// Returns the proper get.
35+
url := fmt.Sprintf("%s%s", w.Config.Cloudfunctions2BasePath, w.CommonOperationWaiter.Op.Name)
36+
37+
return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
38+
}
39+
40+
func createCloudfunctions2Waiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*Cloudfunctions2OperationWaiter, error) {
41+
w := &Cloudfunctions2OperationWaiter{
42+
Config: config,
43+
UserAgent: userAgent,
44+
Project: project,
45+
}
46+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
47+
return nil, err
48+
}
49+
return w, nil
50+
}
51+
52+
// nolint: deadcode,unused
53+
func cloudfunctions2OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
54+
w, err := createCloudfunctions2Waiter(config, op, project, activity, userAgent)
55+
if err != nil {
56+
return err
57+
}
58+
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
59+
return err
60+
}
61+
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
62+
}
63+
64+
func cloudfunctions2OperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
65+
if val, ok := op["name"]; !ok || val == "" {
66+
// This was a synchronous call - there is no operation to wait for.
67+
return nil
68+
}
69+
w, err := createCloudfunctions2Waiter(config, op, project, activity, userAgent)
70+
if err != nil {
71+
// If w is nil, the op was synchronous.
72+
return err
73+
}
74+
return OperationWait(w, activity, timeout, config.PollInterval)
75+
}

google/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ type Config struct {
178178
CloudAssetBasePath string
179179
CloudBuildBasePath string
180180
CloudFunctionsBasePath string
181+
Cloudfunctions2BasePath string
181182
CloudIdentityBasePath string
182183
CloudIotBasePath string
183184
CloudRunBasePath string
@@ -271,6 +272,7 @@ const CertificateManagerBasePathKey = "CertificateManager"
271272
const CloudAssetBasePathKey = "CloudAsset"
272273
const CloudBuildBasePathKey = "CloudBuild"
273274
const CloudFunctionsBasePathKey = "CloudFunctions"
275+
const Cloudfunctions2BasePathKey = "Cloudfunctions2"
274276
const CloudIdentityBasePathKey = "CloudIdentity"
275277
const CloudIotBasePathKey = "CloudIot"
276278
const CloudRunBasePathKey = "CloudRun"
@@ -358,6 +360,7 @@ var DefaultBasePaths = map[string]string{
358360
CloudAssetBasePathKey: "https://cloudasset.googleapis.com/v1/",
359361
CloudBuildBasePathKey: "https://cloudbuild.googleapis.com/v1/",
360362
CloudFunctionsBasePathKey: "https://cloudfunctions.googleapis.com/v1/",
363+
Cloudfunctions2BasePathKey: "https://cloudfunctions.googleapis.com/v2/",
361364
CloudIdentityBasePathKey: "https://cloudidentity.googleapis.com/v1/",
362365
CloudIotBasePathKey: "https://cloudiot.googleapis.com/v1/",
363366
CloudRunBasePathKey: "https://{{location}}-run.googleapis.com/",
@@ -1207,6 +1210,7 @@ func ConfigureBasePaths(c *Config) {
12071210
c.CloudAssetBasePath = DefaultBasePaths[CloudAssetBasePathKey]
12081211
c.CloudBuildBasePath = DefaultBasePaths[CloudBuildBasePathKey]
12091212
c.CloudFunctionsBasePath = DefaultBasePaths[CloudFunctionsBasePathKey]
1213+
c.Cloudfunctions2BasePath = DefaultBasePaths[Cloudfunctions2BasePathKey]
12101214
c.CloudIdentityBasePath = DefaultBasePaths[CloudIdentityBasePathKey]
12111215
c.CloudIotBasePath = DefaultBasePaths[CloudIotBasePathKey]
12121216
c.CloudRunBasePath = DefaultBasePaths[CloudRunBasePathKey]
+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/hashicorp/errwrap"
21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
22+
"google.golang.org/api/cloudresourcemanager/v1"
23+
)
24+
25+
var Cloudfunctions2functionIamSchema = map[string]*schema.Schema{
26+
"project": {
27+
Type: schema.TypeString,
28+
Computed: true,
29+
Optional: true,
30+
ForceNew: true,
31+
},
32+
"location": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
Optional: true,
36+
ForceNew: true,
37+
},
38+
"cloud_function": {
39+
Type: schema.TypeString,
40+
Required: true,
41+
ForceNew: true,
42+
DiffSuppressFunc: compareSelfLinkOrResourceName,
43+
},
44+
}
45+
46+
type Cloudfunctions2functionIamUpdater struct {
47+
project string
48+
location string
49+
cloudFunction string
50+
d TerraformResourceData
51+
Config *Config
52+
}
53+
54+
func Cloudfunctions2functionIamUpdaterProducer(d TerraformResourceData, config *Config) (ResourceIamUpdater, error) {
55+
values := make(map[string]string)
56+
57+
project, _ := getProject(d, config)
58+
if project != "" {
59+
if err := d.Set("project", project); err != nil {
60+
return nil, fmt.Errorf("Error setting project: %s", err)
61+
}
62+
}
63+
values["project"] = project
64+
location, _ := getLocation(d, config)
65+
if location != "" {
66+
if err := d.Set("location", location); err != nil {
67+
return nil, fmt.Errorf("Error setting location: %s", err)
68+
}
69+
}
70+
values["location"] = location
71+
if v, ok := d.GetOk("cloud_function"); ok {
72+
values["cloud_function"] = v.(string)
73+
}
74+
75+
// We may have gotten either a long or short name, so attempt to parse long name if possible
76+
m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/functions/(?P<cloud_function>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<cloud_function>[^/]+)", "(?P<location>[^/]+)/(?P<cloud_function>[^/]+)", "(?P<cloud_function>[^/]+)"}, d, config, d.Get("cloud_function").(string))
77+
if err != nil {
78+
return nil, err
79+
}
80+
81+
for k, v := range m {
82+
values[k] = v
83+
}
84+
85+
u := &Cloudfunctions2functionIamUpdater{
86+
project: values["project"],
87+
location: values["location"],
88+
cloudFunction: values["cloud_function"],
89+
d: d,
90+
Config: config,
91+
}
92+
93+
if err := d.Set("project", u.project); err != nil {
94+
return nil, fmt.Errorf("Error setting project: %s", err)
95+
}
96+
if err := d.Set("location", u.location); err != nil {
97+
return nil, fmt.Errorf("Error setting location: %s", err)
98+
}
99+
if err := d.Set("cloud_function", u.GetResourceId()); err != nil {
100+
return nil, fmt.Errorf("Error setting cloud_function: %s", err)
101+
}
102+
103+
return u, nil
104+
}
105+
106+
func Cloudfunctions2functionIdParseFunc(d *schema.ResourceData, config *Config) error {
107+
values := make(map[string]string)
108+
109+
project, _ := getProject(d, config)
110+
if project != "" {
111+
values["project"] = project
112+
}
113+
114+
location, _ := getLocation(d, config)
115+
if location != "" {
116+
values["location"] = location
117+
}
118+
119+
m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/functions/(?P<cloud_function>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<cloud_function>[^/]+)", "(?P<location>[^/]+)/(?P<cloud_function>[^/]+)", "(?P<cloud_function>[^/]+)"}, d, config, d.Id())
120+
if err != nil {
121+
return err
122+
}
123+
124+
for k, v := range m {
125+
values[k] = v
126+
}
127+
128+
u := &Cloudfunctions2functionIamUpdater{
129+
project: values["project"],
130+
location: values["location"],
131+
cloudFunction: values["cloud_function"],
132+
d: d,
133+
Config: config,
134+
}
135+
if err := d.Set("cloud_function", u.GetResourceId()); err != nil {
136+
return fmt.Errorf("Error setting cloud_function: %s", err)
137+
}
138+
d.SetId(u.GetResourceId())
139+
return nil
140+
}
141+
142+
func (u *Cloudfunctions2functionIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
143+
url, err := u.qualifyfunctionUrl("getIamPolicy")
144+
if err != nil {
145+
return nil, err
146+
}
147+
148+
project, err := getProject(u.d, u.Config)
149+
if err != nil {
150+
return nil, err
151+
}
152+
var obj map[string]interface{}
153+
154+
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
155+
if err != nil {
156+
return nil, err
157+
}
158+
159+
policy, err := sendRequest(u.Config, "GET", project, url, userAgent, obj)
160+
if err != nil {
161+
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
162+
}
163+
164+
out := &cloudresourcemanager.Policy{}
165+
err = Convert(policy, out)
166+
if err != nil {
167+
return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err)
168+
}
169+
170+
return out, nil
171+
}
172+
173+
func (u *Cloudfunctions2functionIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
174+
json, err := ConvertToMap(policy)
175+
if err != nil {
176+
return err
177+
}
178+
179+
obj := make(map[string]interface{})
180+
obj["policy"] = json
181+
182+
url, err := u.qualifyfunctionUrl("setIamPolicy")
183+
if err != nil {
184+
return err
185+
}
186+
project, err := getProject(u.d, u.Config)
187+
if err != nil {
188+
return err
189+
}
190+
191+
userAgent, err := generateUserAgentString(u.d, u.Config.userAgent)
192+
if err != nil {
193+
return err
194+
}
195+
196+
_, err = sendRequestWithTimeout(u.Config, "POST", project, url, userAgent, obj, u.d.Timeout(schema.TimeoutCreate))
197+
if err != nil {
198+
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
199+
}
200+
201+
return nil
202+
}
203+
204+
func (u *Cloudfunctions2functionIamUpdater) qualifyfunctionUrl(methodIdentifier string) (string, error) {
205+
urlTemplate := fmt.Sprintf("{{Cloudfunctions2BasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/functions/%s", u.project, u.location, u.cloudFunction), methodIdentifier)
206+
url, err := replaceVars(u.d, u.Config, urlTemplate)
207+
if err != nil {
208+
return "", err
209+
}
210+
return url, nil
211+
}
212+
213+
func (u *Cloudfunctions2functionIamUpdater) GetResourceId() string {
214+
return fmt.Sprintf("projects/%s/locations/%s/functions/%s", u.project, u.location, u.cloudFunction)
215+
}
216+
217+
func (u *Cloudfunctions2functionIamUpdater) GetMutexKey() string {
218+
return fmt.Sprintf("iam-cloudfunctions2-function-%s", u.GetResourceId())
219+
}
220+
221+
func (u *Cloudfunctions2functionIamUpdater) DescribeResource() string {
222+
return fmt.Sprintf("cloudfunctions2 function %q", u.GetResourceId())
223+
}

0 commit comments

Comments
 (0)