Skip to content

Commit

Permalink
Revert "sync-main-FEATURE-BRANCH-ephemeral-resources #1 (#11822)"
Browse files Browse the repository at this point in the history
This reverts commit bd43b7e.
  • Loading branch information
SarahFrench authored Sep 26, 2024
1 parent bd43b7e commit 99c4d5e
Show file tree
Hide file tree
Showing 6,705 changed files with 491,829 additions and 66,980 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
31 changes: 21 additions & 10 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ ifeq ($(ENGINE),tpgtools)
# exist so exclusively build base tpgtools implementation
mmv1_compile=-p does-not-exist
else ifneq ($(PRODUCT),)
mmv1_compile=--product $(PRODUCT)
mmv1_compile=-p products/$(PRODUCT)
else
mmv1_compile=-a
endif

# tpgtools setup
Expand All @@ -24,12 +26,12 @@ else
endif

ifneq ($(RESOURCE),)
mmv1_compile += --resource $(RESOURCE)
mmv1_compile += -t $(RESOURCE)
tpgtools_compile += --resource $(RESOURCE)
endif

ifneq ($(OVERRIDES),)
mmv1_compile += --overrides $(OVERRIDES)
mmv1_compile += -r $(OVERRIDES)
tpgtools_compile += --overrides $(OVERRIDES)/tpgtools/overrides --path $(OVERRIDES)/tpgtools/api
serialize_compile = --overrides $(OVERRIDES)/tpgtools/overrides --path $(OVERRIDES)/tpgtools/api
else
Expand Down Expand Up @@ -60,11 +62,12 @@ terraform build provider:

mmv1:
cd mmv1;\
bundle; \
if [ "$(VERSION)" = "ga" ]; then \
go run . --output $(OUTPUT_PATH) --version ga --no-docs $(mmv1_compile); \
go run . --output $(OUTPUT_PATH) --version beta --no-code $(mmv1_compile); \
bundle exec compiler.rb -e terraform -o $(OUTPUT_PATH) -v ga --no-docs $(mmv1_compile); \
bundle exec compiler.rb -e terraform -o $(OUTPUT_PATH) -v beta --no-code $(mmv1_compile); \
else \
go run . --output $(OUTPUT_PATH) --version $(VERSION) $(mmv1_compile); \
bundle exec compiler.rb -e terraform -o $(OUTPUT_PATH) -v $(VERSION) $(mmv1_compile); \
fi

tpgtools:
Expand All @@ -88,16 +91,24 @@ clean-tgc:

tgc:
cd mmv1;\
go run . --version beta --provider tgc --output $(OUTPUT_PATH)/tfplan2cai $(mmv1_compile);\
go run . --version beta --provider tgc_cai2hcl --output $(OUTPUT_PATH)/cai2hcl $(mmv1_compile);\
bundle;\
bundle exec compiler -e terraform -f tgc -v beta -o $(OUTPUT_PATH)/tfplan2cai $(mmv1_compile);\
bundle exec compiler -e terraform -f tgc_cai2hcl -v beta -o $(OUTPUT_PATH)/cai2hcl $(mmv1_compile);\

tgc-go:
cd mmv1;\
go run . --version beta --provider tgc --output $(OUTPUT_PATH)/tfplan2cai;\
go run . --version beta --provider tgc_cai2hcl --output $(OUTPUT_PATH)/cai2hcl;\

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

test:
cd mmv1; \
go test ./...
bundle; \
bundle exec rake test

serialize:
cd tpgtools;\
Expand Down
8 changes: 4 additions & 4 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type Resource struct {
//
// references:
// guides:
// 'Guide name': 'official_documentation_url'
// api: 'rest_api_reference_url/version'
// 'Guide name': 'official_documentation_url'
// api: 'rest_api_reference_url/version'
//
References resource.ReferenceLinks

Expand Down Expand Up @@ -190,7 +190,7 @@ type Resource struct {
//
// import_format:
// - example_import_one
// - example_import_two
// - example_import_two
//
ImportFormat []string `yaml:"import_format"`

Expand Down Expand Up @@ -760,7 +760,7 @@ func getLabelsFieldNote(title string) string {
}

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

// ====================
Expand Down
4 changes: 2 additions & 2 deletions mmv1/api/resource/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (e *Examples) UnmarshalYAML(unmarshal func(any) error) error {
}

if e.ConfigPath == "" {
e.ConfigPath = fmt.Sprintf("templates/terraform/examples/%s.tf.tmpl", e.Name)
e.ConfigPath = fmt.Sprintf("templates/terraform/examples/go/%s.tf.tmpl", e.Name)
}
e.SetHCLText()

Expand Down Expand Up @@ -286,7 +286,7 @@ func ExecuteTemplate(e any, templatePath string, appendNewline bool) string {
templates := []string{
templatePath,
"templates/terraform/expand_resource_ref.tmpl",
"templates/terraform/custom_flatten/bigquery_table_ref.go.tmpl",
"templates/terraform/custom_flatten/go/bigquery_table_ref.go.tmpl",
"templates/terraform/flatten_property_method.go.tmpl",
"templates/terraform/expand_property_method.go.tmpl",
"templates/terraform/update_mask.go.tmpl",
Expand Down
2 changes: 1 addition & 1 deletion mmv1/api/resource/iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p *IamPolicy) UnmarshalYAML(unmarshal func(any) error) error {
p.WrappedPolicyObj = true
p.AllowedIamRole = "roles/viewer"
p.ParentResourceAttribute = "id"
p.ExampleConfigBody = "templates/terraform/iam/iam_attributes.go.tmpl"
p.ExampleConfigBody = "templates/terraform/iam/go/iam_attributes.go.tmpl"
p.SubstituteZoneValue = true

type iamPolicyAlias IamPolicy
Expand Down
34 changes: 18 additions & 16 deletions mmv1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,20 @@ func main() {
})

var providerToGenerate provider.Provider
var productsForVersion []*api.Product

productFileChannel := make(chan string, len(allProductFiles))
productsForVersionChannel := make(chan *api.Product, len(allProductFiles))
ch := make(chan string, len(allProductFiles))
for _, pf := range allProductFiles {
productFileChannel <- pf
ch <- pf
}

for i := 0; i < len(allProductFiles); i++ {
wg.Add(1)
go GenerateProduct(productFileChannel, providerToGenerate, productsForVersionChannel, startTime, productsToGenerate, *resourceToGenerate, *overrideDirectory, generateCode, generateDocs)
go GenerateProduct(ch, providerToGenerate, &productsForVersion, startTime, productsToGenerate, *resourceToGenerate, *overrideDirectory, generateCode, generateDocs)
}
wg.Wait()

close(productFileChannel)
close(productsForVersionChannel)

var productsForVersion []*api.Product

for p := range productsForVersionChannel {
productsForVersion = append(productsForVersion, p)
}
close(ch)

slices.SortFunc(productsForVersion, func(p1, p2 *api.Product) int {
return strings.Compare(strings.ToLower(p1.Name), strings.ToLower(p2.Name))
Expand All @@ -192,19 +185,21 @@ func main() {

if generateCode {
providerToGenerate.CompileCommonFiles(*outputPath, productsForVersion, "")

// TODO rewrite: product overrides
}
}

func GenerateProduct(productChannel chan string, providerToGenerate provider.Provider, productsForVersionChannel chan *api.Product, startTime time.Time, productsToGenerate []string, resourceToGenerate, overrideDirectory string, generateCode, generateDocs bool) {
func GenerateProduct(productChannel chan string, providerToGenerate provider.Provider, productsForVersion *[]*api.Product, startTime time.Time, productsToGenerate []string, resourceToGenerate, overrideDirectory string, generateCode, generateDocs bool) {

defer wg.Done()
productName := <-productChannel

productYamlPath := path.Join(productName, "product.yaml")
productYamlPath := path.Join(productName, "go_product.yaml")

var productOverridePath string
if overrideDirectory != "" {
productOverridePath = filepath.Join(overrideDirectory, productName, "product.yaml")
productOverridePath = filepath.Join(overrideDirectory, productName, "go_product.yaml")
}

_, baseProductErr := os.Stat(productYamlPath)
Expand Down Expand Up @@ -250,6 +245,11 @@ func GenerateProduct(productChannel chan string, providerToGenerate provider.Pro
continue
}

// Prepend "go_" to the Go yaml files' name to distinguish with the ruby yaml files
if filepath.Base(resourceYamlPath) == "go_product.yaml" || !strings.HasPrefix(filepath.Base(resourceYamlPath), "go_") {
continue
}

if overrideDirectory != "" {
// skip if resource will be merged in the override loop
resourceOverridePath := filepath.Join(overrideDirectory, resourceYamlPath)
Expand Down Expand Up @@ -308,6 +308,8 @@ func GenerateProduct(productChannel chan string, providerToGenerate provider.Pro
resources = append(resources, resource)
}

// TODO rewrite: override resources

// Sort resources by name
sort.Slice(resources, func(i, j int) bool {
return resources[i].Name < resources[j].Name
Expand All @@ -320,7 +322,7 @@ func GenerateProduct(productChannel chan string, providerToGenerate provider.Pro

providerToGenerate = setProvider(*forceProvider, *version, productApi, startTime)

productsForVersionChannel <- productApi
*productsForVersion = append(*productsForVersion, productApi)

if !slices.Contains(productsToGenerate, productName) {
log.Printf("%s not specified, skipping generation", productName)
Expand Down
115 changes: 54 additions & 61 deletions mmv1/products/accessapproval/FolderSettings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Google Inc.
# Copyright 2023 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
Expand All @@ -11,86 +11,80 @@
# See the License for the specific language governing permissions and
# limitations under the License.

---
name: 'FolderSettings'
legacy_name: 'google_folder_access_approval_settings'
description: |
Access Approval enables you to require your explicit approval whenever Google support and engineering need to access your customer content.
references:
guides:
api: 'https://cloud.google.com/access-approval/docs/reference/rest/v1/folders'
docs:
--- !ruby/object:Api::Resource
name: FolderSettings
base_url: 'folders/{{folder_id}}/accessApprovalSettings'
self_link: 'folders/{{folder_id}}/accessApprovalSettings'
create_verb: 'PATCH'
update_verb: 'PATCH'
create_verb: :PATCH
update_verb: :PATCH
update_mask: true
import_format:
- 'folders/{{folder_id}}/accessApprovalSettings'
timeouts:
insert_minutes: 20
update_minutes: 20
delete_minutes: 20
custom_code:
constants: 'templates/terraform/constants/access_approval.go.tmpl'
pre_create: 'templates/terraform/update_mask.go.tmpl'
custom_delete: 'templates/terraform/custom_delete/clear_folder_access_approval_settings.go.tmpl'
description: |
Access Approval enables you to require your explicit approval whenever Google support and engineering need to access your customer content.
references: !ruby/object:Api::Resource::ReferenceLinks
api: 'https://cloud.google.com/access-approval/docs/reference/rest/v1/folders'
legacy_name: 'google_folder_access_approval_settings'
import_format: ['folders/{{folder_id}}/accessApprovalSettings']
examples:
- name: 'folder_access_approval_full'
- !ruby/object:Provider::Terraform::Examples
skip_test: true
name: 'folder_access_approval_full'
primary_resource_id: 'folder_access_approval'
vars:
folder_name: 'my-folder'
test_env_vars:
org_id: 'ORG_ID'
exclude_test: true
- name: 'folder_access_approval_active_key_version'
org_id: :ORG_ID
- !ruby/object:Provider::Terraform::Examples
skip_test: true
name: 'folder_access_approval_active_key_version'
primary_resource_id: 'folder_access_approval'
vars:
folder_name: 'my-folder'
test_env_vars:
org_id: 'ORG_ID'
exclude_test: true
org_id: :ORG_ID
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_delete: templates/terraform/custom_delete/clear_folder_access_approval_settings.go.erb
pre_create: templates/terraform/update_mask.erb
constants: templates/terraform/constants/access_approval.go.erb
parameters:
- name: 'folder_id'
type: String
- !ruby/object:Api::Type::String
name: folder_id
description: |
ID of the folder of the access approval settings.
url_param_only: true
required: true
immutable: true
url_param_only: true
properties:
- name: 'name'
type: String
- !ruby/object:Api::Type::String
name: name
description: |
The resource name of the settings. Format is "folders/{folder_id}/accessApprovalSettings"
output: true
- name: 'notificationEmails'
type: Array
- !ruby/object:Api::Type::Array
name: notificationEmails
description: |
A list of email addresses to which notifications relating to approval requests should be sent.
Notifications relating to a resource will be sent to all emails in the settings of ancestor
resources of that resource. A maximum of 50 email addresses are allowed.
max_size: 50
item_type: Api::Type::String
is_set: true
default_from_api: true
item_type:
type: String
max_size: 50
- name: 'enrolledServices'
type: Array
- !ruby/object:Api::Type::Array
name: enrolledServices
required: true
description: |
A list of Google Cloud Services for which the given resource has Access Approval enrolled.
Access requests for the resource given by name against any of these services contained here will be required
to have explicit approval. Enrollment can only be done on an all or nothing basis.
A maximum of 10 enrolled services will be enforced, to be expanded as the set of supported services is expanded.
is_set: true
required: true
set_hash_func: accessApprovalEnrolledServicesHash
item_type:
type: NestedObject
item_type: !ruby/object:Api::Type::NestedObject
properties:
- name: 'cloudProduct'
type: String
- !ruby/object:Api::Type::String
name: cloudProduct
required: true
description: |
The product for which Access Approval will be enrolled. Allowed values are listed (case-sensitive):
* all
Expand All @@ -116,35 +110,34 @@ properties:
* iam.googleapis.com
* pubsub.googleapis.com
* storage.googleapis.com
required: true
- name: 'enrollmentLevel'
type: Enum
- !ruby/object:Api::Type::Enum
name: enrollmentLevel
description: |
The enrollment level of the service.
default_value: "BLOCK_ALL"
enum_values:
- 'BLOCK_ALL'
- name: 'enrolledAncestor'
type: Boolean
default_value: :BLOCK_ALL
values:
- :BLOCK_ALL
- !ruby/object:Api::Type::Boolean
name: enrolledAncestor
output: true
description: |
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.
output: true
- name: 'activeKeyVersion'
type: String
- !ruby/object:Api::Type::String
name: activeKeyVersion
description: |
The asymmetric crypto key version to use for signing approval requests.
Empty active_key_version indicates that a Google-managed key should be used for signing.
This property will be ignored if set by an ancestor of the resource, and new non-empty values may not be set.
- name: 'ancestorHasActiveKeyVersion'
type: Boolean
- !ruby/object:Api::Type::Boolean
name: ancestorHasActiveKeyVersion
output: true
description: |
If the field is true, that indicates that an ancestor of this Folder has set active_key_version.
- !ruby/object:Api::Type::Boolean
name: invalidKeyVersion
output: true
- name: 'invalidKeyVersion'
type: Boolean
description: |
If the field is true, that indicates that there is some configuration issue with the active_key_version
configured on this Folder (e.g. it doesn't exist or the Access Approval service account doesn't have the
correct permissions on it, etc.) This key version is not necessarily the effective key version at this level,
as key versions are inherited top-down.
output: true
Loading

0 comments on commit 99c4d5e

Please sign in to comment.