Skip to content

Commit a520431

Browse files
authored
migrate mmv1 to go (#11814)
2 parents 362f73c + 1cd5c8b commit a520431

File tree

6,705 files changed

+66038
-486951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,705 files changed

+66038
-486951
lines changed

GNUmakefile

+10-21
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ ifeq ($(ENGINE),tpgtools)
99
# exist so exclusively build base tpgtools implementation
1010
mmv1_compile=-p does-not-exist
1111
else ifneq ($(PRODUCT),)
12-
mmv1_compile=-p products/$(PRODUCT)
13-
else
14-
mmv1_compile=-a
12+
mmv1_compile=--product $(PRODUCT)
1513
endif
1614

1715
# tpgtools setup
@@ -26,12 +24,12 @@ else
2624
endif
2725

2826
ifneq ($(RESOURCE),)
29-
mmv1_compile += -t $(RESOURCE)
27+
mmv1_compile += --resource $(RESOURCE)
3028
tpgtools_compile += --resource $(RESOURCE)
3129
endif
3230

3331
ifneq ($(OVERRIDES),)
34-
mmv1_compile += -r $(OVERRIDES)
32+
mmv1_compile += --overrides $(OVERRIDES)
3533
tpgtools_compile += --overrides $(OVERRIDES)/tpgtools/overrides --path $(OVERRIDES)/tpgtools/api
3634
serialize_compile = --overrides $(OVERRIDES)/tpgtools/overrides --path $(OVERRIDES)/tpgtools/api
3735
else
@@ -62,12 +60,11 @@ terraform build provider:
6260

6361
mmv1:
6462
cd mmv1;\
65-
bundle; \
6663
if [ "$(VERSION)" = "ga" ]; then \
67-
bundle exec compiler.rb -e terraform -o $(OUTPUT_PATH) -v ga --no-docs $(mmv1_compile); \
68-
bundle exec compiler.rb -e terraform -o $(OUTPUT_PATH) -v beta --no-code $(mmv1_compile); \
64+
go run . --output $(OUTPUT_PATH) --version ga --no-docs $(mmv1_compile); \
65+
go run . --output $(OUTPUT_PATH) --version beta --no-code $(mmv1_compile); \
6966
else \
70-
bundle exec compiler.rb -e terraform -o $(OUTPUT_PATH) -v $(VERSION) $(mmv1_compile); \
67+
go run . --output $(OUTPUT_PATH) --version $(VERSION) $(mmv1_compile); \
7168
fi
7269

7370
tpgtools:
@@ -91,24 +88,16 @@ clean-tgc:
9188

9289
tgc:
9390
cd mmv1;\
94-
bundle;\
95-
bundle exec compiler -e terraform -f tgc -v beta -o $(OUTPUT_PATH)/tfplan2cai $(mmv1_compile);\
96-
bundle exec compiler -e terraform -f tgc_cai2hcl -v beta -o $(OUTPUT_PATH)/cai2hcl $(mmv1_compile);\
97-
98-
tgc-go:
99-
cd mmv1;\
100-
go run . --version beta --provider tgc --output $(OUTPUT_PATH)/tfplan2cai;\
101-
go run . --version beta --provider tgc_cai2hcl --output $(OUTPUT_PATH)/cai2hcl;\
91+
go run . --version beta --provider tgc --output $(OUTPUT_PATH)/tfplan2cai $(mmv1_compile);\
92+
go run . --version beta --provider tgc_cai2hcl --output $(OUTPUT_PATH)/cai2hcl $(mmv1_compile);\
10293

10394
tf-oics:
10495
cd mmv1;\
105-
bundle;\
106-
bundle exec compiler.rb -e terraform -f oics -o $(OUTPUT_PATH) $(mmv1_compile);\
96+
go run . --version ga --provider oics --output $(OUTPUT_PATH) $(mmv1_compile);\
10797

10898
test:
10999
cd mmv1; \
110-
bundle; \
111-
bundle exec rake test
100+
go test ./...
112101

113102
serialize:
114103
cd tpgtools;\

mmv1/api/resource.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ type Resource struct {
4242
//
4343
// references:
4444
// guides:
45-
// 'Guide name': 'official_documentation_url'
46-
// api: 'rest_api_reference_url/version'
45+
// 'Guide name': 'official_documentation_url'
46+
// api: 'rest_api_reference_url/version'
4747
//
4848
References resource.ReferenceLinks
4949

@@ -190,7 +190,7 @@ type Resource struct {
190190
//
191191
// import_format:
192192
// - example_import_one
193-
// - example_import_two
193+
// - example_import_two
194194
//
195195
ImportFormat []string `yaml:"import_format"`
196196

@@ -760,7 +760,7 @@ func getLabelsFieldNote(title string) string {
760760
}
761761

762762
func (r Resource) StateMigrationFile() string {
763-
return fmt.Sprintf("templates/terraform/state_migrations/go/%s_%s.go.tmpl", google.Underscore(r.ProductMetadata.Name), google.Underscore(r.Name))
763+
return fmt.Sprintf("templates/terraform/state_migrations/%s_%s.go.tmpl", google.Underscore(r.ProductMetadata.Name), google.Underscore(r.Name))
764764
}
765765

766766
// ====================

mmv1/api/resource/examples.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (e *Examples) UnmarshalYAML(unmarshal func(any) error) error {
170170
}
171171

172172
if e.ConfigPath == "" {
173-
e.ConfigPath = fmt.Sprintf("templates/terraform/examples/go/%s.tf.tmpl", e.Name)
173+
e.ConfigPath = fmt.Sprintf("templates/terraform/examples/%s.tf.tmpl", e.Name)
174174
}
175175
e.SetHCLText()
176176

@@ -286,7 +286,7 @@ func ExecuteTemplate(e any, templatePath string, appendNewline bool) string {
286286
templates := []string{
287287
templatePath,
288288
"templates/terraform/expand_resource_ref.tmpl",
289-
"templates/terraform/custom_flatten/go/bigquery_table_ref.go.tmpl",
289+
"templates/terraform/custom_flatten/bigquery_table_ref.go.tmpl",
290290
"templates/terraform/flatten_property_method.go.tmpl",
291291
"templates/terraform/expand_property_method.go.tmpl",
292292
"templates/terraform/update_mask.go.tmpl",

mmv1/api/resource/iam_policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (p *IamPolicy) UnmarshalYAML(unmarshal func(any) error) error {
125125
p.WrappedPolicyObj = true
126126
p.AllowedIamRole = "roles/viewer"
127127
p.ParentResourceAttribute = "id"
128-
p.ExampleConfigBody = "templates/terraform/iam/go/iam_attributes.go.tmpl"
128+
p.ExampleConfigBody = "templates/terraform/iam/iam_attributes.go.tmpl"
129129
p.SubstituteZoneValue = true
130130

131131
type iamPolicyAlias IamPolicy

mmv1/main.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ func GenerateProduct(productChannel chan string, providerToGenerate provider.Pro
200200
defer wg.Done()
201201
productName := <-productChannel
202202

203-
productYamlPath := path.Join(productName, "go_product.yaml")
203+
productYamlPath := path.Join(productName, "product.yaml")
204204

205205
var productOverridePath string
206206
if overrideDirectory != "" {
207-
productOverridePath = filepath.Join(overrideDirectory, productName, "go_product.yaml")
207+
productOverridePath = filepath.Join(overrideDirectory, productName, "product.yaml")
208208
}
209209

210210
_, baseProductErr := os.Stat(productYamlPath)
@@ -250,11 +250,6 @@ func GenerateProduct(productChannel chan string, providerToGenerate provider.Pro
250250
continue
251251
}
252252

253-
// Prepend "go_" to the Go yaml files' name to distinguish with the ruby yaml files
254-
if filepath.Base(resourceYamlPath) == "go_product.yaml" || !strings.HasPrefix(filepath.Base(resourceYamlPath), "go_") {
255-
continue
256-
}
257-
258253
if overrideDirectory != "" {
259254
// skip if resource will be merged in the override loop
260255
resourceOverridePath := filepath.Join(overrideDirectory, resourceYamlPath)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google Inc.
1+
# Copyright 2024 Google Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -11,80 +11,86 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
--- !ruby/object:Api::Resource
15-
name: FolderSettings
16-
base_url: 'folders/{{folder_id}}/accessApprovalSettings'
17-
self_link: 'folders/{{folder_id}}/accessApprovalSettings'
18-
create_verb: :PATCH
19-
update_verb: :PATCH
20-
update_mask: true
14+
---
15+
name: 'FolderSettings'
16+
legacy_name: 'google_folder_access_approval_settings'
2117
description: |
2218
Access Approval enables you to require your explicit approval whenever Google support and engineering need to access your customer content.
23-
references: !ruby/object:Api::Resource::ReferenceLinks
19+
references:
20+
guides:
2421
api: 'https://cloud.google.com/access-approval/docs/reference/rest/v1/folders'
25-
legacy_name: 'google_folder_access_approval_settings'
26-
import_format: ['folders/{{folder_id}}/accessApprovalSettings']
22+
docs:
23+
base_url: 'folders/{{folder_id}}/accessApprovalSettings'
24+
self_link: 'folders/{{folder_id}}/accessApprovalSettings'
25+
create_verb: 'PATCH'
26+
update_verb: 'PATCH'
27+
update_mask: true
28+
import_format:
29+
- 'folders/{{folder_id}}/accessApprovalSettings'
30+
timeouts:
31+
insert_minutes: 20
32+
update_minutes: 20
33+
delete_minutes: 20
34+
custom_code:
35+
constants: 'templates/terraform/constants/access_approval.go.tmpl'
36+
pre_create: 'templates/terraform/update_mask.go.tmpl'
37+
custom_delete: 'templates/terraform/custom_delete/clear_folder_access_approval_settings.go.tmpl'
2738
examples:
28-
- !ruby/object:Provider::Terraform::Examples
29-
skip_test: true
30-
name: 'folder_access_approval_full'
39+
- name: 'folder_access_approval_full'
3140
primary_resource_id: 'folder_access_approval'
3241
vars:
3342
folder_name: 'my-folder'
3443
test_env_vars:
35-
org_id: :ORG_ID
36-
- !ruby/object:Provider::Terraform::Examples
37-
skip_test: true
38-
name: 'folder_access_approval_active_key_version'
44+
org_id: 'ORG_ID'
45+
exclude_test: true
46+
- name: 'folder_access_approval_active_key_version'
3947
primary_resource_id: 'folder_access_approval'
4048
vars:
4149
folder_name: 'my-folder'
4250
test_env_vars:
43-
org_id: :ORG_ID
44-
custom_code: !ruby/object:Provider::Terraform::CustomCode
45-
custom_delete: templates/terraform/custom_delete/clear_folder_access_approval_settings.go.erb
46-
pre_create: templates/terraform/update_mask.erb
47-
constants: templates/terraform/constants/access_approval.go.erb
51+
org_id: 'ORG_ID'
52+
exclude_test: true
4853
parameters:
49-
- !ruby/object:Api::Type::String
50-
name: folder_id
54+
- name: 'folder_id'
55+
type: String
5156
description: |
5257
ID of the folder of the access approval settings.
58+
url_param_only: true
5359
required: true
5460
immutable: true
55-
url_param_only: true
5661
properties:
57-
- !ruby/object:Api::Type::String
58-
name: name
62+
- name: 'name'
63+
type: String
5964
description: |
6065
The resource name of the settings. Format is "folders/{folder_id}/accessApprovalSettings"
6166
output: true
62-
- !ruby/object:Api::Type::Array
63-
name: notificationEmails
67+
- name: 'notificationEmails'
68+
type: Array
6469
description: |
6570
A list of email addresses to which notifications relating to approval requests should be sent.
6671
Notifications relating to a resource will be sent to all emails in the settings of ancestor
6772
resources of that resource. A maximum of 50 email addresses are allowed.
68-
max_size: 50
69-
item_type: Api::Type::String
7073
is_set: true
7174
default_from_api: true
72-
- !ruby/object:Api::Type::Array
73-
name: enrolledServices
74-
required: true
75+
item_type:
76+
type: String
77+
max_size: 50
78+
- name: 'enrolledServices'
79+
type: Array
7580
description: |
7681
A list of Google Cloud Services for which the given resource has Access Approval enrolled.
7782
Access requests for the resource given by name against any of these services contained here will be required
7883
to have explicit approval. Enrollment can only be done on an all or nothing basis.
7984
8085
A maximum of 10 enrolled services will be enforced, to be expanded as the set of supported services is expanded.
8186
is_set: true
87+
required: true
8288
set_hash_func: accessApprovalEnrolledServicesHash
83-
item_type: !ruby/object:Api::Type::NestedObject
89+
item_type:
90+
type: NestedObject
8491
properties:
85-
- !ruby/object:Api::Type::String
86-
name: cloudProduct
87-
required: true
92+
- name: 'cloudProduct'
93+
type: String
8894
description: |
8995
The product for which Access Approval will be enrolled. Allowed values are listed (case-sensitive):
9096
* all
@@ -110,34 +116,35 @@ properties:
110116
* iam.googleapis.com
111117
* pubsub.googleapis.com
112118
* storage.googleapis.com
113-
- !ruby/object:Api::Type::Enum
114-
name: enrollmentLevel
119+
required: true
120+
- name: 'enrollmentLevel'
121+
type: Enum
115122
description: |
116123
The enrollment level of the service.
117-
default_value: :BLOCK_ALL
118-
values:
119-
- :BLOCK_ALL
120-
- !ruby/object:Api::Type::Boolean
121-
name: enrolledAncestor
122-
output: true
124+
default_value: "BLOCK_ALL"
125+
enum_values:
126+
- 'BLOCK_ALL'
127+
- name: 'enrolledAncestor'
128+
type: Boolean
123129
description: |
124130
If the field is true, that indicates that at least one service is enrolled for Access Approval in one or more ancestors of the Folder.
125-
- !ruby/object:Api::Type::String
126-
name: activeKeyVersion
131+
output: true
132+
- name: 'activeKeyVersion'
133+
type: String
127134
description: |
128135
The asymmetric crypto key version to use for signing approval requests.
129136
Empty active_key_version indicates that a Google-managed key should be used for signing.
130137
This property will be ignored if set by an ancestor of the resource, and new non-empty values may not be set.
131-
- !ruby/object:Api::Type::Boolean
132-
name: ancestorHasActiveKeyVersion
133-
output: true
138+
- name: 'ancestorHasActiveKeyVersion'
139+
type: Boolean
134140
description: |
135141
If the field is true, that indicates that an ancestor of this Folder has set active_key_version.
136-
- !ruby/object:Api::Type::Boolean
137-
name: invalidKeyVersion
138142
output: true
143+
- name: 'invalidKeyVersion'
144+
type: Boolean
139145
description: |
140146
If the field is true, that indicates that there is some configuration issue with the active_key_version
141147
configured on this Folder (e.g. it doesn't exist or the Access Approval service account doesn't have the
142148
correct permissions on it, etc.) This key version is not necessarily the effective key version at this level,
143149
as key versions are inherited top-down.
150+
output: true

0 commit comments

Comments
 (0)