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

Add API Gateway resources #2636

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
36 changes: 36 additions & 0 deletions .changelog/4066.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
```release-note:new-resource
`google_api_gateway_api`
```
```release-note:new-resource
`google_api_gateway_api_config`
```
```release-note:new-resource
`google_api_gateway_gateway`
```
```release-note:new-resource
`google_api_gateway_api_iam_binding`
```
```release-note:new-resource
`google_api_gateway_api_iam_member`
```
```release-note:new-resource
`google_api_gateway_api_iam_policy`
```
```release-note:new-resource
`google_api_gateway_api_config_iam_binding`
```
```release-note:new-resource
`google_api_gateway_api_config_iam_member`
```
```release-note:new-resource
`google_api_gateway_api_config_iam_policy`
```
```release-note:new-resource
`google_api_gateway_gateway_iam_binding`
```
```release-note:new-resource
`google_api_gateway_gateway_iam_member`
```
```release-note:new-resource
`google_api_gateway_gateway_iam_policy`
```
75 changes: 75 additions & 0 deletions google-beta/api_gateway_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 ApiGatewayOperationWaiter struct {
Config *Config
UserAgent string
Project string
CommonOperationWaiter
}

func (w *ApiGatewayOperationWaiter) 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("https://apigateway.googleapis.com/v1beta/%s", w.CommonOperationWaiter.Op.Name)

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

func createApiGatewayWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*ApiGatewayOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil, nil
}
w := &ApiGatewayOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

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

func apiGatewayOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createApiGatewayWaiter(config, op, project, activity, userAgent)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeout, config.PollInterval)
}
3 changes: 3 additions & 0 deletions google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Config struct {
AccessApprovalBasePath string
AccessContextManagerBasePath string
ActiveDirectoryBasePath string
ApiGatewayBasePath string
AppEngineBasePath string
ArtifactRegistryBasePath string
BigQueryBasePath string
Expand Down Expand Up @@ -171,6 +172,7 @@ type Config struct {
var AccessApprovalDefaultBasePath = "https://accessapproval.googleapis.com/v1/"
var AccessContextManagerDefaultBasePath = "https://accesscontextmanager.googleapis.com/v1/"
var ActiveDirectoryDefaultBasePath = "https://managedidentities.googleapis.com/v1/"
var ApiGatewayDefaultBasePath = "https://apigateway.googleapis.com/v1beta/"
var AppEngineDefaultBasePath = "https://appengine.googleapis.com/v1/"
var ArtifactRegistryDefaultBasePath = "https://artifactregistry.googleapis.com/v1beta1/"
var BigQueryDefaultBasePath = "https://bigquery.googleapis.com/bigquery/v2/"
Expand Down Expand Up @@ -966,6 +968,7 @@ func ConfigureBasePaths(c *Config) {
c.AccessApprovalBasePath = AccessApprovalDefaultBasePath
c.AccessContextManagerBasePath = AccessContextManagerDefaultBasePath
c.ActiveDirectoryBasePath = ActiveDirectoryDefaultBasePath
c.ApiGatewayBasePath = ApiGatewayDefaultBasePath
c.AppEngineBasePath = AppEngineDefaultBasePath
c.ArtifactRegistryBasePath = ArtifactRegistryDefaultBasePath
c.BigQueryBasePath = BigQueryDefaultBasePath
Expand Down
198 changes: 198 additions & 0 deletions google-beta/iam_api_gateway_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 ApiGatewayApiIamSchema = map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"api": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
}

type ApiGatewayApiIamUpdater struct {
project string
api string
d *schema.ResourceData
Config *Config
}

func ApiGatewayApiIamUpdaterProducer(d *schema.ResourceData, 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
if v, ok := d.GetOk("api"); ok {
values["api"] = 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/global/apis/(?P<api>[^/]+)", "(?P<project>[^/]+)/(?P<api>[^/]+)", "(?P<api>[^/]+)"}, d, config, d.Get("api").(string))
if err != nil {
return nil, err
}

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

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

return u, nil
}

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

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

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

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

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

func (u *ApiGatewayApiIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url, err := u.qualifyApiUrl("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 *ApiGatewayApiIamUpdater) 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.qualifyApiUrl("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 *ApiGatewayApiIamUpdater) qualifyApiUrl(methodIdentifier string) (string, error) {
urlTemplate := fmt.Sprintf("{{ApiGatewayBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/global/apis/%s", u.project, u.api), methodIdentifier)
url, err := replaceVars(u.d, u.Config, urlTemplate)
if err != nil {
return "", err
}
return url, nil
}

func (u *ApiGatewayApiIamUpdater) GetResourceId() string {
return fmt.Sprintf("projects/%s/locations/global/apis/%s", u.project, u.api)
}

func (u *ApiGatewayApiIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-apigateway-api-%s", u.GetResourceId())
}

func (u *ApiGatewayApiIamUpdater) DescribeResource() string {
return fmt.Sprintf("apigateway api %q", u.GetResourceId())
}
Loading