Skip to content

Commit

Permalink
Go rewrite handwritten provider files (GoogleCloudPlatform#11638)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Sep 5, 2024
1 parent c4eadf3 commit 51a9f53
Show file tree
Hide file tree
Showing 29 changed files with 3,623 additions and 48 deletions.
7 changes: 7 additions & 0 deletions mmv1/products/kms/go_AutokeyConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ timeouts:
update_minutes: 20
delete_minutes: 20
custom_code:
constants: 'templates/terraform/constants/go/autokey_config_folder_diff.go.tmpl'
pre_create: 'templates/terraform/pre_create/go/kms_autokey_config_folder.go.tmpl'
pre_read: 'templates/terraform/pre_read/go/kms_autokey_config_folder.go.tmpl'
pre_update: 'templates/terraform/pre_update/go/kms_autokey_config_folder.go.tmpl'
pre_delete: 'templates/terraform/pre_delete/go/kms_autokey_config_folder.go.tmpl'
test_check_destroy: 'templates/terraform/custom_check_destroy/go/kms_autokey_config.go.tmpl'
skip_sweeper: true
examples:
- name: 'kms_autokey_config_all'
primary_resource_id: 'example-autokeyconfig'
Expand All @@ -66,6 +72,7 @@ parameters:
url_param_only: true
required: true
immutable: true
diff_suppress_func: 'folderPrefixSuppress'
properties:
- name: 'keyProject'
type: String
Expand Down
20 changes: 20 additions & 0 deletions mmv1/products/siteverification/go_product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: 'SiteVerification'
display_name: 'Site Verification'
versions:
- name: 'ga'
base_url: 'https://www.googleapis.com/siteVerification/v1/'
scopes:
- 'https://www.googleapis.com/auth/siteverification'
2 changes: 1 addition & 1 deletion mmv1/provider/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ func (t *Terraform) generateResourcesForVersion(products []*api.Product) {
t.IAMResourceCount += 3

if !(iamPolicy.MinVersion != "" && iamPolicy.MinVersion < t.TargetVersionName) {
iamClassName = fmt.Sprintf("%s.Resource%s", service, object.ResourceName())
iamClassName = fmt.Sprintf("%s.%s", service, object.ResourceName())
}
}

Expand Down
9 changes: 0 additions & 9 deletions mmv1/template-converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,6 @@ func checkExceptionList(filePath string) bool {
"iam/example_config_body/privateca",
"iam/example_config_body/vertex_ai",
"iam/example_config_body/app_engine_",

// TODO: remove the following files from the exception list after all of the services are migrated to Go
// It will generate diffs when partial services are migrated.
"provider/provider_mmv1_resources.go.erb",
"provider/provider.go.erb",
"fwmodels/provider_model.go.erb",
"fwprovider/framework_provider.go.erb",
"fwtransport/framework_config.go.erb",
"sweeper/gcp_sweeper_test.go.erb",
"transport/config.go.erb",
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
config := acctest.GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{"{{"}}KMSBasePath{{"}}"}}folders/{{"{{"}}folder{{"}}"}}/autokeyConfig")
url = strings.Replace(url, "folders/folders/", "folders/", 1)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "cloud_run_service_name"}}"
depends_on = [time_sleep.wait_for_mesh]
deletion_protection = false

location = "us-central1"
launch_stage = "BETA"

template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
service_mesh {
mesh = google_network_services_mesh.mesh.id
}
}
}

resource "time_sleep" "wait_for_mesh" {
depends_on = [google_network_services_mesh.mesh]

create_duration = "1m"
}

resource "google_network_services_mesh" "mesh" {
provider = google-beta
name = "{{index $.Vars "mesh_name"}}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {

location = "us-central1"
deletion_protection = false
launch_stage = "BETA"


template {
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {
location = "us-central1"
deletion_protection = false
ingress = "INGRESS_TRAFFIC_ALL"
launch_stage = "BETA"

template {
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ resource "time_sleep" "wait_srv_acc_permissions" {

resource "google_kms_autokey_config" "{{$.PrimaryResourceId}}" {
provider = google-beta
folder = google_folder.autokms_folder.folder_id
folder = google_folder.autokms_folder.id
key_project = "projects/${google_project.key_project.project_id}"
depends_on = [time_sleep.wait_srv_acc_permissions]
}

# Wait delay after setting AutokeyConfig, to prevent diffs on reapply,
# because setting the config takes a little to fully propagate.
resource "time_sleep" "wait_autokey_propagation" {
create_duration = "30s"
depends_on = [google_kms_autokey_config.{{$.PrimaryResourceId}}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id = strings.Replace(id, "folders/folders/", "folders/", 1)
d.SetId(id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url = strings.Replace(url, "folders/folders/", "folders/", 1)
folderValue := d.Get("folder").(string)
folderValue = strings.Replace(folderValue, "folders/", "", 1)
d.Set("folder", folderValue)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
url = strings.Replace(url, "folders/folders/", "folders/", 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
url = strings.Replace(url, "folders/folders/", "folders/", 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
url = strings.Replace(url, "folders/folders/", "folders/", 1)
74 changes: 74 additions & 0 deletions mmv1/third_party/terraform/fwmodels/go/provider_model.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package fwmodels

import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// ProviderModel describes the provider config data model.
type ProviderModel struct {
Credentials types.String `tfsdk:"credentials"`
AccessToken types.String `tfsdk:"access_token"`
ImpersonateServiceAccount types.String `tfsdk:"impersonate_service_account"`
ImpersonateServiceAccountDelegates types.List `tfsdk:"impersonate_service_account_delegates"`
Project types.String `tfsdk:"project"`
BillingProject types.String `tfsdk:"billing_project"`
Region types.String `tfsdk:"region"`
Zone types.String `tfsdk:"zone"`
Scopes types.List `tfsdk:"scopes"`
Batching types.List `tfsdk:"batching"`
UserProjectOverride types.Bool `tfsdk:"user_project_override"`
RequestTimeout types.String `tfsdk:"request_timeout"`
RequestReason types.String `tfsdk:"request_reason"`
UniverseDomain types.String `tfsdk:"universe_domain"`
DefaultLabels types.Map `tfsdk:"default_labels"`
AddTerraformAttributionLabel types.Bool `tfsdk:"add_terraform_attribution_label"`
TerraformAttributionLabelAdditionStrategy types.String `tfsdk:"terraform_attribution_label_addition_strategy"`

// Generated Products
{{- range $product := $.Products }}
{{ $product.Name }}CustomEndpoint types.String `tfsdk:"{{ underscore $product.Name }}_custom_endpoint"`
{{- end }}

// Handwritten Products / Versioned / Atypical Entries
CloudBillingCustomEndpoint types.String `tfsdk:"cloud_billing_custom_endpoint"`
ContainerCustomEndpoint types.String `tfsdk:"container_custom_endpoint"`
DataflowCustomEndpoint types.String `tfsdk:"dataflow_custom_endpoint"`
IamCredentialsCustomEndpoint types.String `tfsdk:"iam_credentials_custom_endpoint"`
ResourceManagerV3CustomEndpoint types.String `tfsdk:"resource_manager_v3_custom_endpoint"`
{{- if ne $.TargetVersionName "ga" }}
RuntimeconfigCustomEndpoint types.String `tfsdk:"runtimeconfig_custom_endpoint"`
{{- end }}
IAMCustomEndpoint types.String `tfsdk:"iam_custom_endpoint"`
TagsLocationCustomEndpoint types.String `tfsdk:"tags_location_custom_endpoint"`

// dcl
ContainerAwsCustomEndpoint types.String `tfsdk:"container_aws_custom_endpoint"`
ContainerAzureCustomEndpoint types.String `tfsdk:"container_azure_custom_endpoint"`

// dcl generated
ApikeysCustomEndpoint types.String `tfsdk:"apikeys_custom_endpoint"`
AssuredWorkloadsCustomEndpoint types.String `tfsdk:"assured_workloads_custom_endpoint"`
CloudBuildWorkerPoolCustomEndpoint types.String `tfsdk:"cloud_build_worker_pool_custom_endpoint"`
CloudResourceManagerCustomEndpoint types.String `tfsdk:"cloud_resource_manager_custom_endpoint"`
EventarcCustomEndpoint types.String `tfsdk:"eventarc_custom_endpoint"`
FirebaserulesCustomEndpoint types.String `tfsdk:"firebaserules_custom_endpoint"`
RecaptchaEnterpriseCustomEndpoint types.String `tfsdk:"recaptcha_enterprise_custom_endpoint"`

GkehubFeatureCustomEndpoint types.String `tfsdk:"gkehub_feature_custom_endpoint"`
}

type ProviderBatching struct {
SendAfter types.String `tfsdk:"send_after"`
EnableBatching types.Bool `tfsdk:"enable_batching"`
}

var ProviderBatchingAttributes = map[string]attr.Type{
"send_after": types.StringType,
"enable_batching": types.BoolType,
}

// ProviderMetaModel describes the provider meta model
type ProviderMetaModel struct {
ModuleName types.String `tfsdk:"module_name"`
}
Loading

0 comments on commit 51a9f53

Please sign in to comment.