Skip to content

Commit 2b52b40

Browse files
zli82016abd-goog
authored andcommitted
Go rewrite handwritten provider files (GoogleCloudPlatform#11638)
1 parent 2cf8ddf commit 2b52b40

29 files changed

+3623
-48
lines changed

mmv1/products/kms/go_AutokeyConfig.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ timeouts:
4444
update_minutes: 20
4545
delete_minutes: 20
4646
custom_code:
47+
constants: 'templates/terraform/constants/go/autokey_config_folder_diff.go.tmpl'
48+
pre_create: 'templates/terraform/pre_create/go/kms_autokey_config_folder.go.tmpl'
49+
pre_read: 'templates/terraform/pre_read/go/kms_autokey_config_folder.go.tmpl'
50+
pre_update: 'templates/terraform/pre_update/go/kms_autokey_config_folder.go.tmpl'
51+
pre_delete: 'templates/terraform/pre_delete/go/kms_autokey_config_folder.go.tmpl'
4752
test_check_destroy: 'templates/terraform/custom_check_destroy/go/kms_autokey_config.go.tmpl'
53+
skip_sweeper: true
4854
examples:
4955
- name: 'kms_autokey_config_all'
5056
primary_resource_id: 'example-autokeyconfig'
@@ -66,6 +72,7 @@ parameters:
6672
url_param_only: true
6773
required: true
6874
immutable: true
75+
diff_suppress_func: 'folderPrefixSuppress'
6976
properties:
7077
- name: 'keyProject'
7178
type: String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
---
14+
name: 'SiteVerification'
15+
display_name: 'Site Verification'
16+
versions:
17+
- name: 'ga'
18+
base_url: 'https://www.googleapis.com/siteVerification/v1/'
19+
scopes:
20+
- 'https://www.googleapis.com/auth/siteverification'

mmv1/provider/terraform.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ func (t *Terraform) generateResourcesForVersion(products []*api.Product) {
898898
t.IAMResourceCount += 3
899899

900900
if !(iamPolicy.MinVersion != "" && iamPolicy.MinVersion < t.TargetVersionName) {
901-
iamClassName = fmt.Sprintf("%s.Resource%s", service, object.ResourceName())
901+
iamClassName = fmt.Sprintf("%s.%s", service, object.ResourceName())
902902
}
903903
}
904904

mmv1/template-converter.go

-9
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,6 @@ func checkExceptionList(filePath string) bool {
701701
"iam/example_config_body/privateca",
702702
"iam/example_config_body/vertex_ai",
703703
"iam/example_config_body/app_engine_",
704-
705-
// TODO: remove the following files from the exception list after all of the services are migrated to Go
706-
// It will generate diffs when partial services are migrated.
707-
"provider/provider_mmv1_resources.go.erb",
708-
"provider/provider.go.erb",
709-
"fwmodels/provider_model.go.erb",
710-
"fwprovider/framework_provider.go.erb",
711-
"fwtransport/framework_config.go.erb",
712-
"sweeper/gcp_sweeper_test.go.erb",
713704
"transport/config.go.erb",
714705
}
715706

mmv1/templates/terraform/custom_check_destroy/go/kms_autokey_config.go.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
config := acctest.GoogleProviderConfig(t)
22

33
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{"{{"}}KMSBasePath{{"}}"}}folders/{{"{{"}}folder{{"}}"}}/autokeyConfig")
4+
url = strings.Replace(url, "folders/folders/", "folders/", 1)
45
if err != nil {
56
return err
67
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
name = "{{index $.Vars "cloud_run_service_name"}}"
4+
depends_on = [time_sleep.wait_for_mesh]
5+
deletion_protection = false
6+
7+
location = "us-central1"
8+
launch_stage = "BETA"
9+
10+
template {
11+
containers {
12+
image = "us-docker.pkg.dev/cloudrun/container/hello"
13+
}
14+
service_mesh {
15+
mesh = google_network_services_mesh.mesh.id
16+
}
17+
}
18+
}
19+
20+
resource "time_sleep" "wait_for_mesh" {
21+
depends_on = [google_network_services_mesh.mesh]
22+
23+
create_duration = "1m"
24+
}
25+
26+
resource "google_network_services_mesh" "mesh" {
27+
provider = google-beta
28+
name = "{{index $.Vars "mesh_name"}}"
29+
}

mmv1/templates/terraform/examples/go/cloudrunv2_service_mount_gcs.tf.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {
33

44
location = "us-central1"
55
deletion_protection = false
6-
launch_stage = "BETA"
6+
77

88
template {
99
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"

mmv1/templates/terraform/examples/go/cloudrunv2_service_mount_nfs.tf.tmpl

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {
44
location = "us-central1"
55
deletion_protection = false
66
ingress = "INGRESS_TRAFFIC_ALL"
7-
launch_stage = "BETA"
87

98
template {
109
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"

mmv1/templates/terraform/examples/go/kms_autokey_config_all.tf.tmpl

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ resource "time_sleep" "wait_srv_acc_permissions" {
6464

6565
resource "google_kms_autokey_config" "{{$.PrimaryResourceId}}" {
6666
provider = google-beta
67-
folder = google_folder.autokms_folder.folder_id
67+
folder = google_folder.autokms_folder.id
6868
key_project = "projects/${google_project.key_project.project_id}"
6969
depends_on = [time_sleep.wait_srv_acc_permissions]
7070
}
71+
72+
# Wait delay after setting AutokeyConfig, to prevent diffs on reapply,
73+
# because setting the config takes a little to fully propagate.
74+
resource "time_sleep" "wait_autokey_propagation" {
75+
create_duration = "30s"
76+
depends_on = [google_kms_autokey_config.{{$.PrimaryResourceId}}]
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id = strings.Replace(id, "folders/folders/", "folders/", 1)
2+
d.SetId(id)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
url = strings.Replace(url, "folders/folders/", "folders/", 1)
2+
folderValue := d.Get("folder").(string)
3+
folderValue = strings.Replace(folderValue, "folders/", "", 1)
4+
d.Set("folder", folderValue)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
url = strings.Replace(url, "folders/folders/", "folders/", 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
url = strings.Replace(url, "folders/folders/", "folders/", 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
url = strings.Replace(url, "folders/folders/", "folders/", 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package fwmodels
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/attr"
5+
"github.com/hashicorp/terraform-plugin-framework/types"
6+
)
7+
8+
// ProviderModel describes the provider config data model.
9+
type ProviderModel struct {
10+
Credentials types.String `tfsdk:"credentials"`
11+
AccessToken types.String `tfsdk:"access_token"`
12+
ImpersonateServiceAccount types.String `tfsdk:"impersonate_service_account"`
13+
ImpersonateServiceAccountDelegates types.List `tfsdk:"impersonate_service_account_delegates"`
14+
Project types.String `tfsdk:"project"`
15+
BillingProject types.String `tfsdk:"billing_project"`
16+
Region types.String `tfsdk:"region"`
17+
Zone types.String `tfsdk:"zone"`
18+
Scopes types.List `tfsdk:"scopes"`
19+
Batching types.List `tfsdk:"batching"`
20+
UserProjectOverride types.Bool `tfsdk:"user_project_override"`
21+
RequestTimeout types.String `tfsdk:"request_timeout"`
22+
RequestReason types.String `tfsdk:"request_reason"`
23+
UniverseDomain types.String `tfsdk:"universe_domain"`
24+
DefaultLabels types.Map `tfsdk:"default_labels"`
25+
AddTerraformAttributionLabel types.Bool `tfsdk:"add_terraform_attribution_label"`
26+
TerraformAttributionLabelAdditionStrategy types.String `tfsdk:"terraform_attribution_label_addition_strategy"`
27+
28+
// Generated Products
29+
{{- range $product := $.Products }}
30+
{{ $product.Name }}CustomEndpoint types.String `tfsdk:"{{ underscore $product.Name }}_custom_endpoint"`
31+
{{- end }}
32+
33+
// Handwritten Products / Versioned / Atypical Entries
34+
CloudBillingCustomEndpoint types.String `tfsdk:"cloud_billing_custom_endpoint"`
35+
ContainerCustomEndpoint types.String `tfsdk:"container_custom_endpoint"`
36+
DataflowCustomEndpoint types.String `tfsdk:"dataflow_custom_endpoint"`
37+
IamCredentialsCustomEndpoint types.String `tfsdk:"iam_credentials_custom_endpoint"`
38+
ResourceManagerV3CustomEndpoint types.String `tfsdk:"resource_manager_v3_custom_endpoint"`
39+
{{- if ne $.TargetVersionName "ga" }}
40+
RuntimeconfigCustomEndpoint types.String `tfsdk:"runtimeconfig_custom_endpoint"`
41+
{{- end }}
42+
IAMCustomEndpoint types.String `tfsdk:"iam_custom_endpoint"`
43+
TagsLocationCustomEndpoint types.String `tfsdk:"tags_location_custom_endpoint"`
44+
45+
// dcl
46+
ContainerAwsCustomEndpoint types.String `tfsdk:"container_aws_custom_endpoint"`
47+
ContainerAzureCustomEndpoint types.String `tfsdk:"container_azure_custom_endpoint"`
48+
49+
// dcl generated
50+
ApikeysCustomEndpoint types.String `tfsdk:"apikeys_custom_endpoint"`
51+
AssuredWorkloadsCustomEndpoint types.String `tfsdk:"assured_workloads_custom_endpoint"`
52+
CloudBuildWorkerPoolCustomEndpoint types.String `tfsdk:"cloud_build_worker_pool_custom_endpoint"`
53+
CloudResourceManagerCustomEndpoint types.String `tfsdk:"cloud_resource_manager_custom_endpoint"`
54+
EventarcCustomEndpoint types.String `tfsdk:"eventarc_custom_endpoint"`
55+
FirebaserulesCustomEndpoint types.String `tfsdk:"firebaserules_custom_endpoint"`
56+
RecaptchaEnterpriseCustomEndpoint types.String `tfsdk:"recaptcha_enterprise_custom_endpoint"`
57+
58+
GkehubFeatureCustomEndpoint types.String `tfsdk:"gkehub_feature_custom_endpoint"`
59+
}
60+
61+
type ProviderBatching struct {
62+
SendAfter types.String `tfsdk:"send_after"`
63+
EnableBatching types.Bool `tfsdk:"enable_batching"`
64+
}
65+
66+
var ProviderBatchingAttributes = map[string]attr.Type{
67+
"send_after": types.StringType,
68+
"enable_batching": types.BoolType,
69+
}
70+
71+
// ProviderMetaModel describes the provider meta model
72+
type ProviderMetaModel struct {
73+
ModuleName types.String `tfsdk:"module_name"`
74+
}

0 commit comments

Comments
 (0)