Skip to content

Commit dd8578f

Browse files
Beyondcorp application (#12919) (#21199)
[upstream:c0cff93bde60f8fc5d5b42a0282ef907ab3e50e3] Signed-off-by: Modular Magician <[email protected]>
1 parent 9070376 commit dd8578f

11 files changed

+2131
-3
lines changed

.changelog/12919.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:note
2+
Reapplied `google_beyondcorp_application`
3+
```

google/provider/provider_mmv1_resources.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ var generatedIAMDatasources = map[string]*schema.Resource{
361361
"google_access_context_manager_access_policy_iam_policy": tpgiamresource.DataSourceIamPolicy(accesscontextmanager.AccessContextManagerAccessPolicyIamSchema, accesscontextmanager.AccessContextManagerAccessPolicyIamUpdaterProducer),
362362
"google_apigee_environment_iam_policy": tpgiamresource.DataSourceIamPolicy(apigee.ApigeeEnvironmentIamSchema, apigee.ApigeeEnvironmentIamUpdaterProducer),
363363
"google_artifact_registry_repository_iam_policy": tpgiamresource.DataSourceIamPolicy(artifactregistry.ArtifactRegistryRepositoryIamSchema, artifactregistry.ArtifactRegistryRepositoryIamUpdaterProducer),
364+
"google_beyondcorp_application_iam_policy": tpgiamresource.DataSourceIamPolicy(beyondcorp.BeyondcorpApplicationIamSchema, beyondcorp.BeyondcorpApplicationIamUpdaterProducer),
364365
"google_beyondcorp_security_gateway_iam_policy": tpgiamresource.DataSourceIamPolicy(beyondcorp.BeyondcorpSecurityGatewayIamSchema, beyondcorp.BeyondcorpSecurityGatewayIamUpdaterProducer),
365366
"google_bigquery_table_iam_policy": tpgiamresource.DataSourceIamPolicy(bigquery.BigQueryTableIamSchema, bigquery.BigQueryTableIamUpdaterProducer),
366367
"google_bigquery_analytics_hub_data_exchange_iam_policy": tpgiamresource.DataSourceIamPolicy(bigqueryanalyticshub.BigqueryAnalyticsHubDataExchangeIamSchema, bigqueryanalyticshub.BigqueryAnalyticsHubDataExchangeIamUpdaterProducer),
@@ -472,9 +473,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
472473
}
473474

474475
// Resources
475-
// Generated resources: 515
476-
// Generated IAM resources: 273
477-
// Total generated resources: 788
476+
// Generated resources: 516
477+
// Generated IAM resources: 276
478+
// Total generated resources: 792
478479
var generatedResources = map[string]*schema.Resource{
479480
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
480481
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -546,6 +547,10 @@ var generatedResources = map[string]*schema.Resource{
546547
"google_beyondcorp_app_connection": beyondcorp.ResourceBeyondcorpAppConnection(),
547548
"google_beyondcorp_app_connector": beyondcorp.ResourceBeyondcorpAppConnector(),
548549
"google_beyondcorp_app_gateway": beyondcorp.ResourceBeyondcorpAppGateway(),
550+
"google_beyondcorp_application": beyondcorp.ResourceBeyondcorpApplication(),
551+
"google_beyondcorp_application_iam_binding": tpgiamresource.ResourceIamBinding(beyondcorp.BeyondcorpApplicationIamSchema, beyondcorp.BeyondcorpApplicationIamUpdaterProducer, beyondcorp.BeyondcorpApplicationIdParseFunc),
552+
"google_beyondcorp_application_iam_member": tpgiamresource.ResourceIamMember(beyondcorp.BeyondcorpApplicationIamSchema, beyondcorp.BeyondcorpApplicationIamUpdaterProducer, beyondcorp.BeyondcorpApplicationIdParseFunc),
553+
"google_beyondcorp_application_iam_policy": tpgiamresource.ResourceIamPolicy(beyondcorp.BeyondcorpApplicationIamSchema, beyondcorp.BeyondcorpApplicationIamUpdaterProducer, beyondcorp.BeyondcorpApplicationIdParseFunc),
549554
"google_beyondcorp_security_gateway": beyondcorp.ResourceBeyondcorpSecurityGateway(),
550555
"google_beyondcorp_security_gateway_iam_binding": tpgiamresource.ResourceIamBinding(beyondcorp.BeyondcorpSecurityGatewayIamSchema, beyondcorp.BeyondcorpSecurityGatewayIamUpdaterProducer, beyondcorp.BeyondcorpSecurityGatewayIdParseFunc),
551556
"google_beyondcorp_security_gateway_iam_member": tpgiamresource.ResourceIamMember(beyondcorp.BeyondcorpSecurityGatewayIamSchema, beyondcorp.BeyondcorpSecurityGatewayIamUpdaterProducer, beyondcorp.BeyondcorpSecurityGatewayIdParseFunc),
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package beyondcorp
19+
20+
import (
21+
"fmt"
22+
23+
"github.com/hashicorp/errwrap"
24+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
25+
"google.golang.org/api/cloudresourcemanager/v1"
26+
27+
"github.com/hashicorp/terraform-provider-google/google/tpgiamresource"
28+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
29+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
30+
)
31+
32+
var BeyondcorpApplicationIamSchema = map[string]*schema.Schema{
33+
"project": {
34+
Type: schema.TypeString,
35+
Computed: true,
36+
Optional: true,
37+
ForceNew: true,
38+
},
39+
"security_gateways_id": {
40+
Type: schema.TypeString,
41+
Required: true,
42+
ForceNew: true,
43+
},
44+
"application_id": {
45+
Type: schema.TypeString,
46+
Required: true,
47+
ForceNew: true,
48+
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
49+
},
50+
}
51+
52+
type BeyondcorpApplicationIamUpdater struct {
53+
project string
54+
securityGatewaysId string
55+
applicationId string
56+
d tpgresource.TerraformResourceData
57+
Config *transport_tpg.Config
58+
}
59+
60+
func BeyondcorpApplicationIamUpdaterProducer(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) {
61+
values := make(map[string]string)
62+
63+
project, _ := tpgresource.GetProject(d, config)
64+
if project != "" {
65+
if err := d.Set("project", project); err != nil {
66+
return nil, fmt.Errorf("Error setting project: %s", err)
67+
}
68+
}
69+
values["project"] = project
70+
if v, ok := d.GetOk("security_gateways_id"); ok {
71+
values["security_gateways_id"] = v.(string)
72+
}
73+
74+
if v, ok := d.GetOk("application_id"); ok {
75+
values["application_id"] = v.(string)
76+
}
77+
78+
// We may have gotten either a long or short name, so attempt to parse long name if possible
79+
m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/global/securityGateways/(?P<security_gateways_id>[^/]+)/applications/(?P<application_id>[^/]+)", "(?P<project>[^/]+)/(?P<security_gateways_id>[^/]+)/(?P<application_id>[^/]+)", "(?P<security_gateways_id>[^/]+)/(?P<application_id>[^/]+)", "(?P<application_id>[^/]+)"}, d, config, d.Get("application_id").(string))
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
for k, v := range m {
85+
values[k] = v
86+
}
87+
88+
u := &BeyondcorpApplicationIamUpdater{
89+
project: values["project"],
90+
securityGatewaysId: values["security_gateways_id"],
91+
applicationId: values["application_id"],
92+
d: d,
93+
Config: config,
94+
}
95+
96+
if err := d.Set("project", u.project); err != nil {
97+
return nil, fmt.Errorf("Error setting project: %s", err)
98+
}
99+
if err := d.Set("security_gateways_id", u.securityGatewaysId); err != nil {
100+
return nil, fmt.Errorf("Error setting security_gateways_id: %s", err)
101+
}
102+
if err := d.Set("application_id", u.GetResourceId()); err != nil {
103+
return nil, fmt.Errorf("Error setting application_id: %s", err)
104+
}
105+
106+
return u, nil
107+
}
108+
109+
func BeyondcorpApplicationIdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error {
110+
values := make(map[string]string)
111+
112+
project, _ := tpgresource.GetProject(d, config)
113+
if project != "" {
114+
values["project"] = project
115+
}
116+
117+
m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/locations/global/securityGateways/(?P<security_gateways_id>[^/]+)/applications/(?P<application_id>[^/]+)", "(?P<project>[^/]+)/(?P<security_gateways_id>[^/]+)/(?P<application_id>[^/]+)", "(?P<security_gateways_id>[^/]+)/(?P<application_id>[^/]+)", "(?P<application_id>[^/]+)"}, d, config, d.Id())
118+
if err != nil {
119+
return err
120+
}
121+
122+
for k, v := range m {
123+
values[k] = v
124+
}
125+
126+
u := &BeyondcorpApplicationIamUpdater{
127+
project: values["project"],
128+
securityGatewaysId: values["security_gateways_id"],
129+
applicationId: values["application_id"],
130+
d: d,
131+
Config: config,
132+
}
133+
if err := d.Set("application_id", u.GetResourceId()); err != nil {
134+
return fmt.Errorf("Error setting application_id: %s", err)
135+
}
136+
d.SetId(u.GetResourceId())
137+
return nil
138+
}
139+
140+
func (u *BeyondcorpApplicationIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
141+
url, err := u.qualifyApplicationUrl("getIamPolicy")
142+
if err != nil {
143+
return nil, err
144+
}
145+
146+
project, err := tpgresource.GetProject(u.d, u.Config)
147+
if err != nil {
148+
return nil, err
149+
}
150+
var obj map[string]interface{}
151+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"options.requestedPolicyVersion": fmt.Sprintf("%d", tpgiamresource.IamPolicyVersion)})
152+
if err != nil {
153+
return nil, err
154+
}
155+
156+
userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent)
157+
if err != nil {
158+
return nil, err
159+
}
160+
161+
policy, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
162+
Config: u.Config,
163+
Method: "GET",
164+
Project: project,
165+
RawURL: url,
166+
UserAgent: userAgent,
167+
Body: obj,
168+
})
169+
if err != nil {
170+
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
171+
}
172+
173+
out := &cloudresourcemanager.Policy{}
174+
err = tpgresource.Convert(policy, out)
175+
if err != nil {
176+
return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err)
177+
}
178+
179+
return out, nil
180+
}
181+
182+
func (u *BeyondcorpApplicationIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error {
183+
json, err := tpgresource.ConvertToMap(policy)
184+
if err != nil {
185+
return err
186+
}
187+
188+
obj := make(map[string]interface{})
189+
obj["policy"] = json
190+
191+
url, err := u.qualifyApplicationUrl("setIamPolicy")
192+
if err != nil {
193+
return err
194+
}
195+
project, err := tpgresource.GetProject(u.d, u.Config)
196+
if err != nil {
197+
return err
198+
}
199+
200+
userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent)
201+
if err != nil {
202+
return err
203+
}
204+
205+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
206+
Config: u.Config,
207+
Method: "POST",
208+
Project: project,
209+
RawURL: url,
210+
UserAgent: userAgent,
211+
Body: obj,
212+
Timeout: u.d.Timeout(schema.TimeoutCreate),
213+
})
214+
if err != nil {
215+
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
216+
}
217+
218+
return nil
219+
}
220+
221+
func (u *BeyondcorpApplicationIamUpdater) qualifyApplicationUrl(methodIdentifier string) (string, error) {
222+
urlTemplate := fmt.Sprintf("{{BeyondcorpBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", u.project, u.securityGatewaysId, u.applicationId), methodIdentifier)
223+
url, err := tpgresource.ReplaceVars(u.d, u.Config, urlTemplate)
224+
if err != nil {
225+
return "", err
226+
}
227+
return url, nil
228+
}
229+
230+
func (u *BeyondcorpApplicationIamUpdater) GetResourceId() string {
231+
return fmt.Sprintf("projects/%s/locations/global/securityGateways/%s/applications/%s", u.project, u.securityGatewaysId, u.applicationId)
232+
}
233+
234+
func (u *BeyondcorpApplicationIamUpdater) GetMutexKey() string {
235+
return fmt.Sprintf("iam-beyondcorp-application-%s", u.GetResourceId())
236+
}
237+
238+
func (u *BeyondcorpApplicationIamUpdater) DescribeResource() string {
239+
return fmt.Sprintf("beyondcorp application %q", u.GetResourceId())
240+
}

0 commit comments

Comments
 (0)