Skip to content

Commit b569cc0

Browse files
Add Cloud Deploy Automation (#9562) (#6794)
* Add Cloud Deploy Automation * Attempt to solve the test errors based on https://yaqs.corp.google.com/eng/q/7753655943518224384 * Add update test for the new automation resource * fix lint errors * fix lint errors * fix errors in GA provider test * add the missing test * add a full test * Attempt to fix the acceptance test errors * fix a lint error * mark labels as default_from_api:true * fix advance rollout rule definition * Mark service_account as 'ignore_read: true' * Fix test errors * Resolve review comments * Format test file [upstream:0c92938cbea41ce693a4082501c52ff2403bfa3c] Signed-off-by: Modular Magician <[email protected]>
1 parent 2146b77 commit b569cc0

15 files changed

+2031
-32
lines changed

.changelog/9562.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_clouddeploy_automation` (beta)
3+
```

google-beta/fwmodels/provider_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type ProviderModel struct {
5050
CloudAssetCustomEndpoint types.String `tfsdk:"cloud_asset_custom_endpoint"`
5151
CloudBuildCustomEndpoint types.String `tfsdk:"cloud_build_custom_endpoint"`
5252
Cloudbuildv2CustomEndpoint types.String `tfsdk:"cloudbuildv2_custom_endpoint"`
53+
ClouddeployCustomEndpoint types.String `tfsdk:"clouddeploy_custom_endpoint"`
5354
CloudFunctionsCustomEndpoint types.String `tfsdk:"cloud_functions_custom_endpoint"`
5455
Cloudfunctions2CustomEndpoint types.String `tfsdk:"cloudfunctions2_custom_endpoint"`
5556
CloudIdentityCustomEndpoint types.String `tfsdk:"cloud_identity_custom_endpoint"`
@@ -166,7 +167,6 @@ type ProviderModel struct {
166167
ApikeysCustomEndpoint types.String `tfsdk:"apikeys_custom_endpoint"`
167168
AssuredWorkloadsCustomEndpoint types.String `tfsdk:"assured_workloads_custom_endpoint"`
168169
CloudBuildWorkerPoolCustomEndpoint types.String `tfsdk:"cloud_build_worker_pool_custom_endpoint"`
169-
CloudDeployCustomEndpoint types.String `tfsdk:"clouddeploy_custom_endpoint"`
170170
CloudResourceManagerCustomEndpoint types.String `tfsdk:"cloud_resource_manager_custom_endpoint"`
171171
EventarcCustomEndpoint types.String `tfsdk:"eventarc_custom_endpoint"`
172172
FirebaserulesCustomEndpoint types.String `tfsdk:"firebaserules_custom_endpoint"`

google-beta/fwprovider/framework_provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
281281
transport_tpg.CustomEndpointValidator(),
282282
},
283283
},
284+
"clouddeploy_custom_endpoint": &schema.StringAttribute{
285+
Optional: true,
286+
Validators: []validator.String{
287+
transport_tpg.CustomEndpointValidator(),
288+
},
289+
},
284290
"cloud_functions_custom_endpoint": &schema.StringAttribute{
285291
Optional: true,
286292
Validators: []validator.String{

google-beta/fwtransport/framework_config.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type FrameworkProviderConfig struct {
7575
CloudAssetBasePath string
7676
CloudBuildBasePath string
7777
Cloudbuildv2BasePath string
78+
ClouddeployBasePath string
7879
CloudFunctionsBasePath string
7980
Cloudfunctions2BasePath string
8081
CloudIdentityBasePath string
@@ -233,6 +234,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
233234
p.CloudAssetBasePath = data.CloudAssetCustomEndpoint.ValueString()
234235
p.CloudBuildBasePath = data.CloudBuildCustomEndpoint.ValueString()
235236
p.Cloudbuildv2BasePath = data.Cloudbuildv2CustomEndpoint.ValueString()
237+
p.ClouddeployBasePath = data.ClouddeployCustomEndpoint.ValueString()
236238
p.CloudFunctionsBasePath = data.CloudFunctionsCustomEndpoint.ValueString()
237239
p.Cloudfunctions2BasePath = data.Cloudfunctions2CustomEndpoint.ValueString()
238240
p.CloudIdentityBasePath = data.CloudIdentityCustomEndpoint.ValueString()
@@ -647,6 +649,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
647649
data.Cloudbuildv2CustomEndpoint = types.StringValue(customEndpoint.(string))
648650
}
649651
}
652+
if data.ClouddeployCustomEndpoint.IsNull() {
653+
customEndpoint := transport_tpg.MultiEnvDefault([]string{
654+
"GOOGLE_CLOUDDEPLOY_CUSTOM_ENDPOINT",
655+
}, transport_tpg.DefaultBasePaths[transport_tpg.ClouddeployBasePathKey])
656+
if customEndpoint != nil {
657+
data.ClouddeployCustomEndpoint = types.StringValue(customEndpoint.(string))
658+
}
659+
}
650660
if data.CloudFunctionsCustomEndpoint.IsNull() {
651661
customEndpoint := transport_tpg.MultiEnvDefault([]string{
652662
"GOOGLE_CLOUD_FUNCTIONS_CUSTOM_ENDPOINT",
@@ -1546,15 +1556,6 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
15461556
}
15471557
}
15481558

1549-
if data.CloudDeployCustomEndpoint.IsNull() {
1550-
customEndpoint := transport_tpg.MultiEnvDefault([]string{
1551-
"GOOGLE_CLOUDDEPLOY_CUSTOM_ENDPOINT",
1552-
}, "")
1553-
if customEndpoint != nil {
1554-
data.CloudDeployCustomEndpoint = types.StringValue(customEndpoint.(string))
1555-
}
1556-
}
1557-
15581559
if data.CloudResourceManagerCustomEndpoint.IsNull() {
15591560
customEndpoint := transport_tpg.MultiEnvDefault([]string{
15601561
"GOOGLE_CLOUD_RESOURCE_MANAGER_CUSTOM_ENDPOINT",

google-beta/provider/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ func Provider() *schema.Provider {
255255
Optional: true,
256256
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
257257
},
258+
"clouddeploy_custom_endpoint": {
259+
Type: schema.TypeString,
260+
Optional: true,
261+
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
262+
},
258263
"cloud_functions_custom_endpoint": {
259264
Type: schema.TypeString,
260265
Optional: true,
@@ -955,6 +960,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
955960
config.CloudAssetBasePath = d.Get("cloud_asset_custom_endpoint").(string)
956961
config.CloudBuildBasePath = d.Get("cloud_build_custom_endpoint").(string)
957962
config.Cloudbuildv2BasePath = d.Get("cloudbuildv2_custom_endpoint").(string)
963+
config.ClouddeployBasePath = d.Get("clouddeploy_custom_endpoint").(string)
958964
config.CloudFunctionsBasePath = d.Get("cloud_functions_custom_endpoint").(string)
959965
config.Cloudfunctions2BasePath = d.Get("cloudfunctions2_custom_endpoint").(string)
960966
config.CloudIdentityBasePath = d.Get("cloud_identity_custom_endpoint").(string)

google-beta/provider/provider_mmv1_resources.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudasset"
3030
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudbuild"
3131
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudbuildv2"
32+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/clouddeploy"
3233
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudfunctions"
3334
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudfunctions2"
3435
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/cloudidentity"
@@ -418,9 +419,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
418419
}
419420

420421
// Resources
421-
// Generated resources: 413
422+
// Generated resources: 414
422423
// Generated IAM resources: 252
423-
// Total generated resources: 665
424+
// Total generated resources: 666
424425
var generatedResources = map[string]*schema.Resource{
425426
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
426427
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -544,6 +545,7 @@ var generatedResources = map[string]*schema.Resource{
544545
"google_cloudbuildv2_connection_iam_binding": tpgiamresource.ResourceIamBinding(cloudbuildv2.Cloudbuildv2ConnectionIamSchema, cloudbuildv2.Cloudbuildv2ConnectionIamUpdaterProducer, cloudbuildv2.Cloudbuildv2ConnectionIdParseFunc),
545546
"google_cloudbuildv2_connection_iam_member": tpgiamresource.ResourceIamMember(cloudbuildv2.Cloudbuildv2ConnectionIamSchema, cloudbuildv2.Cloudbuildv2ConnectionIamUpdaterProducer, cloudbuildv2.Cloudbuildv2ConnectionIdParseFunc),
546547
"google_cloudbuildv2_connection_iam_policy": tpgiamresource.ResourceIamPolicy(cloudbuildv2.Cloudbuildv2ConnectionIamSchema, cloudbuildv2.Cloudbuildv2ConnectionIamUpdaterProducer, cloudbuildv2.Cloudbuildv2ConnectionIdParseFunc),
548+
"google_clouddeploy_automation": clouddeploy.ResourceClouddeployAutomation(),
547549
"google_cloudfunctions_function_iam_binding": tpgiamresource.ResourceIamBinding(cloudfunctions.CloudFunctionsCloudFunctionIamSchema, cloudfunctions.CloudFunctionsCloudFunctionIamUpdaterProducer, cloudfunctions.CloudFunctionsCloudFunctionIdParseFunc),
548550
"google_cloudfunctions_function_iam_member": tpgiamresource.ResourceIamMember(cloudfunctions.CloudFunctionsCloudFunctionIamSchema, cloudfunctions.CloudFunctionsCloudFunctionIamUpdaterProducer, cloudfunctions.CloudFunctionsCloudFunctionIdParseFunc),
549551
"google_cloudfunctions_function_iam_policy": tpgiamresource.ResourceIamPolicy(cloudfunctions.CloudFunctionsCloudFunctionIamSchema, cloudfunctions.CloudFunctionsCloudFunctionIamUpdaterProducer, cloudfunctions.CloudFunctionsCloudFunctionIdParseFunc),
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 clouddeploy
19+
20+
import (
21+
"encoding/json"
22+
"errors"
23+
"fmt"
24+
"time"
25+
26+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
27+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
28+
)
29+
30+
type ClouddeployOperationWaiter struct {
31+
Config *transport_tpg.Config
32+
UserAgent string
33+
Project string
34+
tpgresource.CommonOperationWaiter
35+
}
36+
37+
func (w *ClouddeployOperationWaiter) QueryOp() (interface{}, error) {
38+
if w == nil {
39+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
40+
}
41+
// Returns the proper get.
42+
url := fmt.Sprintf("%s%s", w.Config.ClouddeployBasePath, w.CommonOperationWaiter.Op.Name)
43+
44+
return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
45+
Config: w.Config,
46+
Method: "GET",
47+
Project: w.Project,
48+
RawURL: url,
49+
UserAgent: w.UserAgent,
50+
})
51+
}
52+
53+
func createClouddeployWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*ClouddeployOperationWaiter, error) {
54+
w := &ClouddeployOperationWaiter{
55+
Config: config,
56+
UserAgent: userAgent,
57+
Project: project,
58+
}
59+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
60+
return nil, err
61+
}
62+
return w, nil
63+
}
64+
65+
// nolint: deadcode,unused
66+
func ClouddeployOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
67+
w, err := createClouddeployWaiter(config, op, project, activity, userAgent)
68+
if err != nil {
69+
return err
70+
}
71+
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
72+
return err
73+
}
74+
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
75+
if len(rawResponse) == 0 {
76+
return errors.New("`resource` not set in operation response")
77+
}
78+
return json.Unmarshal(rawResponse, response)
79+
}
80+
81+
func ClouddeployOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
82+
if val, ok := op["name"]; !ok || val == "" {
83+
// This was a synchronous call - there is no operation to wait for.
84+
return nil
85+
}
86+
w, err := createClouddeployWaiter(config, op, project, activity, userAgent)
87+
if err != nil {
88+
// If w is nil, the op was synchronous.
89+
return err
90+
}
91+
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
92+
}

0 commit comments

Comments
 (0)