Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
wj-chen committed Apr 30, 2024
2 parents fb78900 + a184883 commit d75edd5
Show file tree
Hide file tree
Showing 74 changed files with 3,139 additions and 1,815 deletions.
4 changes: 1 addition & 3 deletions .ci/gcb-generate-diffs-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ steps:
- name: 'gcr.io/graphite-docker-images/go-plus'
id: gcb-tpg-vcr-test
entrypoint: '/workspace/.ci/scripts/go-plus/magician/exec.sh'
secretEnv: ["GITHUB_TOKEN_DOWNSTREAMS", "GITHUB_TOKEN_MAGIC_MODULES", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION", "GOOGLE_TPU_V2_VM_RUNTIME_VERSION"]
secretEnv: ["GITHUB_TOKEN_DOWNSTREAMS", "GITHUB_TOKEN_MAGIC_MODULES", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION"]
waitFor: ["diff"]
env:
- BASE_BRANCH=$_BASE_BRANCH
Expand Down Expand Up @@ -318,5 +318,3 @@ availableSecrets:
env: SA_KEY
- versionName: projects/673497134629/secrets/ci-test-public-advertised-prefix-description/versions/latest
env: GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION
- versionName: projects/673497134629/secrets/ci-test-tpu-v2-vm-runtime-version/versions/latest
env: GOOGLE_TPU_V2_VM_RUNTIME_VERSION
3 changes: 0 additions & 3 deletions .ci/gcb-push-downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ steps:
- "GOOGLE_SERVICE_ACCOUNT"
- "SA_KEY"
- "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION"
- "GOOGLE_TPU_V2_VM_RUNTIME_VERSION"
env:
- "COMMIT_SHA=$COMMIT_SHA"
- "GOOGLE_REGION=us-central1"
Expand Down Expand Up @@ -253,5 +252,3 @@ availableSecrets:
env: SA_KEY
- versionName: projects/673497134629/secrets/ci-test-public-advertised-prefix-description/versions/latest
env: GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION
- versionName: projects/673497134629/secrets/ci-test-tpu-v2-vm-runtime-version/versions/latest
env: GOOGLE_TPU_V2_VM_RUNTIME_VERSION
4 changes: 1 addition & 3 deletions .ci/gcb-vcr-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ steps:
- name: 'gcr.io/graphite-docker-images/go-plus'
id: gcb-vcr-nightly
entrypoint: '/workspace/.ci/scripts/go-plus/vcr-cassette-update/vcr_cassette_update.sh'
secretEnv: ["GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION", "GOOGLE_TPU_V2_VM_RUNTIME_VERSION"]
secretEnv: ["GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "GOOGLE_FIRESTORE_PROJECT", "GOOGLE_IDENTITY_USER", "GOOGLE_MASTER_BILLING_ACCOUNT", "GOOGLE_ORG", "GOOGLE_ORG_2", "GOOGLE_ORG_DOMAIN", "GOOGLE_PROJECT", "GOOGLE_PROJECT_NUMBER", "GOOGLE_SERVICE_ACCOUNT", "SA_KEY", "GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION"]
args:
- $BUILD_ID

Expand Down Expand Up @@ -41,5 +41,3 @@ availableSecrets:
env: SA_KEY
- versionName: projects/673497134629/secrets/ci-test-public-advertised-prefix-description/versions/latest
env: GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION
- versionName: projects/673497134629/secrets/ci-test-tpu-v2-vm-runtime-version/versions/latest
env: GOOGLE_TPU_V2_VM_RUNTIME_VERSION
1 change: 1 addition & 0 deletions .ci/infra/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ After applying this configuration:
- Create a `support@` group in the Google Workspace Admin Console, add new service account as a member, and make it an owner
- Enroll in Cloud Armor Managed Protection Plus tier
- Add Cloud Identity Premium Plan to the Google Workspace domain
- Perform the Privileged Access Manager set-up https://pantheon.corp.google.com/iam-admin/pam/setup

Quotas that will need to be adjusted to support all tests:
- Project quota for the new service account
Expand Down
25 changes: 19 additions & 6 deletions .ci/infra/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ resource "google_organization_iam_member" "sa_access_boundary_admin" {
member = google_service_account.sa.member
}

resource "google_organization_iam_member" "sa_apphub_admin" {
org_id = data.google_organization.org.org_id
role = "roles/apphub.admin"
member = google_service_account.sa.member
}

resource "google_organization_iam_member" "sa_assuredworkloads_admin" {
org_id = data.google_organization.org.org_id
role = "roles/assuredworkloads.admin"
Expand Down Expand Up @@ -63,6 +69,18 @@ resource "google_organization_iam_member" "sa_compute_xpn_admin" {
member = google_service_account.sa.member
}

resource "google_organization_iam_member" "sa_contentwarehouse_admin" {
org_id = data.google_organization.org.org_id
role = "roles/contentwarehouse.admin"
member = google_service_account.sa.member
}

resource "google_organization_iam_member" "sa_contentwarehouse_document_admin" {
org_id = data.google_organization.org.org_id
role = "roles/contentwarehouse.documentAdmin"
member = google_service_account.sa.member
}

resource "google_organization_iam_member" "sa_deny_admin" {
org_id = data.google_organization.org.org_id
role = "roles/iam.denyAdmin"
Expand Down Expand Up @@ -135,12 +153,6 @@ resource "google_organization_iam_member" "sa_storage_admin" {
member = google_service_account.sa.member
}

resource "google_organization_iam_member" "apphub_admin" {
org_id = data.google_organization.org.org_id
role = "roles/apphub.admin"
member = google_service_account.sa.member
}

resource "google_billing_account_iam_member" "sa_master_billing_admin" {
billing_account_id = data.google_billing_account.master_acct.id
role = "roles/billing.admin"
Expand Down Expand Up @@ -286,6 +298,7 @@ module "project-services" {
"oslogin.googleapis.com",
"parallelstore.googleapis.com",
"privateca.googleapis.com",
"privilegedaccessmanager.googleapis.com",
"pubsub.googleapis.com",
"pubsublite.googleapis.com",
"publicca.googleapis.com",
Expand Down
1 change: 0 additions & 1 deletion .ci/magician/cmd/check_cassettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var ccEnvironmentVariables = [...]string{
"GOOGLE_REGION",
"GOOGLE_SERVICE_ACCOUNT",
"GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION",
"GOOGLE_TPU_V2_VM_RUNTIME_VERSION",
"GOOGLE_ZONE",
"PATH",
"SA_KEY",
Expand Down
1 change: 0 additions & 1 deletion .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var ttvEnvironmentVariables = [...]string{
"GOOGLE_REGION",
"GOOGLE_SERVICE_ACCOUNT",
"GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION",
"GOOGLE_TPU_V2_VM_RUNTIME_VERSION",
"GOOGLE_ZONE",
"HOME",
"PATH",
Expand Down
15 changes: 10 additions & 5 deletions .ci/magician/github/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ var (
id: "SarahFrench",
startDate: newDate(2024, 4, 20, bstLoc),
endDate: newDate(2024, 4, 23, bstLoc),
},
{
id: "slevenick",
startDate: newDate(2024, 4, 20, pdtLoc),
endDate: newDate(2024, 4, 27, pdtLoc),
},
{
id: "slevenick",
startDate: newDate(2024, 4, 20, pdtLoc),
endDate: newDate(2024, 4, 27, pdtLoc),
},
{
id: "ScottSuarez",
startDate: newDate(2024, 4, 30, pdtLoc),
endDate: newDate(2024, 7, 31, pdtLoc),
},
}
)
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/request-reviewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ on:
- ready_for_review
- reopened
- synchronize
branches:
- 'main'
- 'FEATURE-BRANCH-*'
issue_comment:
types:
- created

jobs:
request-review:
if: github.event.pull_request.draft == false
if: github.event.pull_request && github.event.pull_request.draft == false && (github.event.sender.login == github.event.pull_request.user.login || github.event.action != 'created')
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand Down
19 changes: 12 additions & 7 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Resource struct {
//
// [Optional] (Api::Resource::IamPolicy) Configuration of a resource's
// resource-specific IAM Policy.
IamPolicy resource.IamPolicy `yaml:"iam_policy"`
IamPolicy *resource.IamPolicy `yaml:"iam_policy"`

// [Optional] If set to true, don't generate the resource itself; only
// generate the IAM policy.
Expand Down Expand Up @@ -964,13 +964,18 @@ func (r Resource) GetIdFormat() string {
// ====================
// Template Methods
// ====================
// Functions used to create slices of resource properties that could not otherwise be called from within generating templates.

// Prints a dot notation path to where the field is nested within the parent
// object when called on a property. eg: parent.meta.label.foo
// Redefined on Resource to terminate the calls up the parent chain.
func (r Resource) ReadProperties() []*Type {
return google.Reject(r.GettableProperties(), func(p *Type) bool {
return p.IgnoreRead
})
}

// checks a resource for if it has properties that have FlattenObject=true on fields where IgnoreRead=false
// used to decide whether or not to import "google.golang.org/api/googleapi"
func (r Resource) FlattenedProperties() []*Type {
return google.Select(google.Reject(r.GettableProperties(), func(p *Type) bool { return p.IgnoreRead }), func(p *Type) bool { return p.FlattenObject })
return google.Select(r.ReadProperties(), func(p *Type) bool {
return p.FlattenObject
})
}


30 changes: 29 additions & 1 deletion mmv1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"sort"
"strings"
"time"

"golang.org/x/exp/slices"

Expand Down Expand Up @@ -68,6 +69,7 @@ func main() {
log.Fatalf("No product.yaml file found.")
}

startTime := time.Now()
log.Printf("Generating MM output to '%s'", *outputPath)
log.Printf("Using %s version", *version)

Expand All @@ -80,6 +82,7 @@ func main() {
return false
})

var productsForVersion []map[string]interface{}
for _, productName := range allProductFiles {
productYamlPath := path.Join(productName, "go_product.yaml")

Expand Down Expand Up @@ -137,7 +140,7 @@ func main() {
productApi.Validate()

// TODO Q2: set other providers via flag
providerToGenerate := provider.NewTerraform(productApi, *version)
providerToGenerate := provider.NewTerraform(productApi, *version, startTime)

if !slices.Contains(productsToGenerate, productName) {
log.Printf("%s not specified, skipping generation", productName)
Expand All @@ -146,8 +149,33 @@ func main() {

log.Printf("%s: Generating files", productName)
providerToGenerate.Generate(*outputPath, productName, generateCode, generateDocs)

// we need to preserve a single provider instance to use outside of this loop.
productsForVersion = append(productsForVersion, map[string]interface{}{
"Definitions": productApi,
"Provider": providerToGenerate,
})
}

// TODO Q2: copy common files
}

slices.SortFunc(productsForVersion, func(p1, p2 map[string]interface{}) int {
return strings.Compare(strings.ToLower(p1["Definitions"].(*api.Product).Name), strings.ToLower(p2["Definitions"].(*api.Product).Name))
})

// In order to only copy/compile files once per provider this must be called outside
// of the products loop. This will get called with the provider from the final iteration
// of the loop
finalProduct := productsForVersion[len(productsForVersion)-1]
provider := finalProduct["Provider"].(*provider.Terraform)

provider.CopyCommonFiles(*outputPath, generateCode, generateDocs)

log.Printf("Compiling common files for terraform")
if generateCode {
provider.CompileCommonFiles(*outputPath, productsForVersion, "")

// TODO Q2: product overrides
}
}
50 changes: 50 additions & 0 deletions mmv1/products/alloydb/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,56 @@ properties:
description: |
Name of the primary cluster must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'
- !ruby/object:Api::Type::NestedObject
name: 'maintenanceUpdatePolicy'
description: |
MaintenanceUpdatePolicy defines the policy for system updates.
properties:
- !ruby/object:Api::Type::Array
name: 'maintenanceWindows'
description: |
Preferred windows to perform maintenance. Currently limited to 1.
item_type: !ruby/object:Api::Type::NestedObject
name: 'maintenanceWindow'
description: |
specifies a preferred day and time for maintenance.
properties:
- !ruby/object:Api::Type::Enum
name: 'day'
required: true
description: |
Preferred day of the week for maintenance, e.g. MONDAY, TUESDAY, etc.
values:
- :MONDAY
- :TUESDAY
- :WEDNESDAY
- :THURSDAY
- :FRIDAY
- :SATURDAY
- :SUNDAY
- !ruby/object:Api::Type::NestedObject
name: 'startTime'
required: true
description: |
Preferred time to start the maintenance operation on the specified day. Maintenance will start within 1 hour of this time.
properties:
- !ruby/object:Api::Type::Integer
name: hours
required: true
description: |
Hours of day in 24 hour format. Should be from 0 to 23.
- !ruby/object:Api::Type::Integer
name: minutes
description: |
Minutes of hour of day. Currently, only the value 0 is supported.
- !ruby/object:Api::Type::Integer
name: seconds
description: |
Seconds of minutes of the time. Currently, only the value 0 is supported.
- !ruby/object:Api::Type::Integer
name: nanos
description: |
Fractions of seconds in nanoseconds. Currently, only the value 0 is supported.
virtual_fields:
- !ruby/object:Api::Type::Enum
name: 'deletion_policy'
Expand Down
45 changes: 2 additions & 43 deletions mmv1/products/documentaiwarehouse/DocumentSchema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,10 @@ custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/document_ai_warehouse_document_schema.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
# docs only, testing is done in an update test
skip_test: true
name: "document_ai_warehouse_document_schema_text"
primary_resource_id: "example_text"
vars:
document_schema_name: "schema-name-text"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_integer"
primary_resource_id: "example_integer"
vars:
document_schema_name: "schema-name-integer"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_float"
primary_resource_id: "example_float"
vars:
document_schema_name: "schema-name-float"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_property"
primary_resource_id: "example_property"
vars:
document_schema_name: "schema-name-property"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_property_enum"
primary_resource_id: "example_property_enum"
vars:
document_schema_name: "schema-name-property-enum"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_enum"
primary_resource_id: "example_enum"
vars:
document_schema_name: "schema-name-enum"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_map"
primary_resource_id: "example_map"
vars:
document_schema_name: "schema-name-map"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_datetime"
primary_resource_id: "example_datetime"
vars:
document_schema_name: "schema-name-datetime"
- !ruby/object:Provider::Terraform::Examples
name: "document_ai_warehouse_document_schema_timestamp"
primary_resource_id: "example_timestamp"
vars:
document_schema_name: "schema-name-timestamp"
parameters:
- !ruby/object:Api::Type::String
name: 'project_number'
Expand Down Expand Up @@ -343,4 +303,3 @@ properties:
send_empty_value: true
allow_empty_object: true
properties: []

Loading

0 comments on commit d75edd5

Please sign in to comment.