Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promote cfn2 to ga #12322

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
3 changes: 3 additions & 0 deletions .changelog/6388.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudfunction2: promote to `google_cloudfunctions2_function` ga
```
75 changes: 75 additions & 0 deletions google/cloudfunctions2_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------
//
// *** 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 (
"encoding/json"
"fmt"
"time"
)

type Cloudfunctions2OperationWaiter struct {
Config *Config
UserAgent string
Project string
CommonOperationWaiter
}

func (w *Cloudfunctions2OperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("%s%s", w.Config.Cloudfunctions2BasePath, w.CommonOperationWaiter.Op.Name)

return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
}

func createCloudfunctions2Waiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*Cloudfunctions2OperationWaiter, error) {
w := &Cloudfunctions2OperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func cloudfunctions2OperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createCloudfunctions2Waiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func cloudfunctions2OperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := createCloudfunctions2Waiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeout, config.PollInterval)
}
4 changes: 4 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ type Config struct {
CloudAssetBasePath string
CloudBuildBasePath string
CloudFunctionsBasePath string
Cloudfunctions2BasePath string
CloudIdentityBasePath string
CloudIotBasePath string
CloudRunBasePath string
Expand Down Expand Up @@ -271,6 +272,7 @@ const CertificateManagerBasePathKey = "CertificateManager"
const CloudAssetBasePathKey = "CloudAsset"
const CloudBuildBasePathKey = "CloudBuild"
const CloudFunctionsBasePathKey = "CloudFunctions"
const Cloudfunctions2BasePathKey = "Cloudfunctions2"
const CloudIdentityBasePathKey = "CloudIdentity"
const CloudIotBasePathKey = "CloudIot"
const CloudRunBasePathKey = "CloudRun"
Expand Down Expand Up @@ -358,6 +360,7 @@ var DefaultBasePaths = map[string]string{
CloudAssetBasePathKey: "https://cloudasset.googleapis.com/v1/",
CloudBuildBasePathKey: "https://cloudbuild.googleapis.com/v1/",
CloudFunctionsBasePathKey: "https://cloudfunctions.googleapis.com/v1/",
Cloudfunctions2BasePathKey: "https://cloudfunctions.googleapis.com/v2/",
CloudIdentityBasePathKey: "https://cloudidentity.googleapis.com/v1/",
CloudIotBasePathKey: "https://cloudiot.googleapis.com/v1/",
CloudRunBasePathKey: "https://{{location}}-run.googleapis.com/",
Expand Down Expand Up @@ -1207,6 +1210,7 @@ func ConfigureBasePaths(c *Config) {
c.CloudAssetBasePath = DefaultBasePaths[CloudAssetBasePathKey]
c.CloudBuildBasePath = DefaultBasePaths[CloudBuildBasePathKey]
c.CloudFunctionsBasePath = DefaultBasePaths[CloudFunctionsBasePathKey]
c.Cloudfunctions2BasePath = DefaultBasePaths[Cloudfunctions2BasePathKey]
c.CloudIdentityBasePath = DefaultBasePaths[CloudIdentityBasePathKey]
c.CloudIotBasePath = DefaultBasePaths[CloudIotBasePathKey]
c.CloudRunBasePath = DefaultBasePaths[CloudRunBasePathKey]
Expand Down
223 changes: 223 additions & 0 deletions google/iam_cloudfunctions2_function.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// ----------------------------------------------------------------------------
//
// *** 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 Cloudfunctions2functionIamSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"location": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"cloud_function": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type Cloudfunctions2functionIamUpdater struct {
project string
location string
cloudFunction string
d TerraformResourceData
Config *Config
}

func Cloudfunctions2functionIamUpdaterProducer(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("cloud_function"); ok {
values["cloud_function"] = 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>[^/]+)/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))
if err != nil {
return nil, err
}

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

u := &Cloudfunctions2functionIamUpdater{
project: values["project"],
location: values["location"],
cloudFunction: values["cloud_function"],
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("cloud_function", u.GetResourceId()); err != nil {
return nil, fmt.Errorf("Error setting cloud_function: %s", err)
}

return u, nil
}

func Cloudfunctions2functionIdParseFunc(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>[^/]+)/functions/(?P<cloud_function>[^/]+)", "(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<cloud_function>[^/]+)", "(?P<location>[^/]+)/(?P<cloud_function>[^/]+)", "(?P<cloud_function>[^/]+)"}, d, config, d.Id())
if err != nil {
return err
}

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

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

func (u *Cloudfunctions2functionIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url, err := u.qualifyfunctionUrl("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, "GET", 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 *Cloudfunctions2functionIamUpdater) 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.qualifyfunctionUrl("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 *Cloudfunctions2functionIamUpdater) qualifyfunctionUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{Cloudfunctions2BasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/functions/%s", u.project, u.location, u.cloudFunction), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *Cloudfunctions2functionIamUpdater) GetResourceId() string {
return fmt.Sprintf("projects/%s/locations/%s/functions/%s", u.project, u.location, u.cloudFunction)
}

func (u *Cloudfunctions2functionIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-cloudfunctions2-function-%s", u.GetResourceId())
}

func (u *Cloudfunctions2functionIamUpdater) DescribeResource() string {
return fmt.Sprintf("cloudfunctions2 function %q", u.GetResourceId())
}
Loading