diff --git a/config/tests/samples/create/harness.go b/config/tests/samples/create/harness.go index 5d4857db50..7a574992d6 100644 --- a/config/tests/samples/create/harness.go +++ b/config/tests/samples/create/harness.go @@ -309,6 +309,7 @@ func NewHarnessWithOptions(ctx context.Context, t *testing.T, opts *HarnessOptio testgcp.TestAttachedClusterName.Set("xks-cluster") testgcp.TestDependentNoNetworkProjectID.Set("mock-project") testgcp.TestDependentOrgProjectID.Set("example-project-01") + testgcp.TestDependentFolderProjectID.Set("example-project-02") testgcp.FirestoreTestProject.Set("cnrm-test-firestore") testgcp.IdentityPlatformTestProject.Set("kcc-identity-platform") testgcp.RecaptchaEnterpriseTestProject.Set("kcc-recaptcha-enterprise") @@ -355,6 +356,7 @@ func NewHarnessWithOptions(ctx context.Context, t *testing.T, opts *HarnessOptio ProjectNumber: 12345678, } testgcp.TestDependentOrgProjectID.Set("example-project-01") + testgcp.TestDependentFolderProjectID.Set("example-project-02") testgcp.FirestoreTestProject.Set("cnrm-test-firestore") testgcp.IdentityPlatformTestProject.Set("kcc-identity-platform") testgcp.RecaptchaEnterpriseTestProject.Set("kcc-recaptcha-enterprise") diff --git a/config/tests/samples/create/samples.go b/config/tests/samples/create/samples.go index 7ed5998d56..d2785ad256 100644 --- a/config/tests/samples/create/samples.go +++ b/config/tests/samples/create/samples.go @@ -518,7 +518,7 @@ func updateProjectResourceWithExistingResourceIDs(t *testing.T, unstructs []*uns } if projectInFolder { - dp = testgcp.GetDependentFolderProjectID(t) + dp = testgcp.TestDependentFolderProjectID.Get() } else if projectInOrg { dp = testgcp.TestDependentOrgProjectID.Get() } diff --git a/pkg/test/controller/k8s.go b/pkg/test/controller/k8s.go index 9a2e09b59f..c6acf52ffc 100644 --- a/pkg/test/controller/k8s.go +++ b/pkg/test/controller/k8s.go @@ -161,9 +161,9 @@ func ReplaceTestVars(t *testing.T, b []byte, uniqueID string, project testgcp.GC s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestOrgID.Key), fmt.Sprintf("\"%s\"", testgcp.TestOrgID.Get()), -1) s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentOrgProjectID.Key), fmt.Sprintf("\"%s\"", testgcp.TestDependentOrgProjectID.Get()), -1) s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentOrgProjectID.Key), fmt.Sprintf("projects/%s", testgcp.TestDependentOrgProjectID.Get()), -1) - s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentFolderProjectID), fmt.Sprintf("projects/%s", testgcp.GetDependentFolderProjectID(t)), -1) + s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentFolderProjectID.Key), fmt.Sprintf("projects/%s", testgcp.TestDependentFolderProjectID.Get()), -1) s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentOrgProjectIDWithoutQuotation), fmt.Sprintf("%s", testgcp.TestDependentOrgProjectID.Get()), -1) - s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentFolderProjectID), fmt.Sprintf("\"%s\"", testgcp.GetDependentFolderProjectID(t)), -1) + s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentFolderProjectID.Key), fmt.Sprintf("\"%s\"", testgcp.TestDependentFolderProjectID.Get()), -1) s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentFolder2ProjectID), fmt.Sprintf("projects/%s", testgcp.GetDependentFolder2ProjectID(t)), -1) s = strings.Replace(s, fmt.Sprintf("projects/${%s}", testgcp.TestDependentNoNetworkProjectID.Key), fmt.Sprintf("projects/%s", testgcp.TestDependentNoNetworkProjectID.Get()), -1) s = strings.Replace(s, fmt.Sprintf("${%s}", testgcp.TestDependentNoNetworkProjectID.Key), fmt.Sprintf("\"%s\"", testgcp.TestDependentNoNetworkProjectID.Get()), -1) diff --git a/pkg/test/gcp/gcp.go b/pkg/test/gcp/gcp.go index 2f244b207f..91b8f49c84 100644 --- a/pkg/test/gcp/gcp.go +++ b/pkg/test/gcp/gcp.go @@ -56,6 +56,8 @@ var ( TestFolder2ID = EnvVar{Key: "TEST_FOLDER_2_ID"} TestOrgID = EnvVar{Key: "TEST_ORG_ID"} TestDependentOrgProjectID = EnvVar{Key: "TEST_DEPENDENT_ORG_PROJECT_ID"} + TestDependentFolderProjectID = EnvVar{Key: "TEST_DEPENDENT_FOLDER_PROJECT_ID"} + TestDependentNoNetworkProjectID = EnvVar{Key: "TEST_DEPENDENT_NO_NETWORK_PROJECT_ID"} // A dependent project with default network disabled TestBillingAccountID = EnvVar{Key: "TEST_BILLING_ACCOUNT_ID"} IAMIntegrationTestsOrganizationID = EnvVar{Key: "IAM_INTEGRATION_TESTS_ORGANIZATION_ID"} IAMIntegrationTestsBillingAccountID = EnvVar{Key: "IAM_INTEGRATION_TESTS_BILLING_ACCOUNT_ID"} @@ -65,14 +67,12 @@ var ( FirestoreTestProject = EnvVar{Key: "FIRESTORE_TEST_PROJECT"} IdentityPlatformTestProject = EnvVar{Key: "IDENTITY_PLATFORM_TEST_PROJECT"} RecaptchaEnterpriseTestProject = EnvVar{Key: "RECAPTCHA_ENTERPRISE_TEST_PROJECT"} - TestDependentNoNetworkProjectID = EnvVar{Key: "TEST_DEPENDENT_NO_NETWORK_PROJECT_ID"} // A dependent project with default network disabled TestKCCVertexAIIndexBucket = EnvVar{Key: "KCC_VERTEX_AI_INDEX_TEST_BUCKET"} TestKCCVertexAIIndexDataURI = EnvVar{Key: "KCC_VERTEX_AI_INDEX_TEST_DATA_URI"} ) const ( TestDependentFolder2ProjectID = "TEST_DEPENDENT_FOLDER_2_PROJECT_ID" - TestDependentFolderProjectID = "TEST_DEPENDENT_FOLDER_PROJECT_ID" IsolatedTestOrgName = "ISOLATED_TEST_ORG_NAME" CloudFunctionsTestProject = "CLOUD_FUNCTIONS_TEST_PROJECT" InterconnectTestProject = "INTERCONNECT_TEST_PROJECT" @@ -83,7 +83,6 @@ const ( var ( testDependentFolder2ProjectID = os.Getenv(TestDependentFolder2ProjectID) - testDependentFolderProjectID = os.Getenv(TestDependentFolderProjectID) isolatedTestOrgName = os.Getenv(IsolatedTestOrgName) cloudFunctionsTestProject = os.Getenv(CloudFunctionsTestProject) interconnectTestProject = os.Getenv(InterconnectTestProject) @@ -158,10 +157,6 @@ func FindDefaultServiceAccount() (string, error) { return rawCreds["client_email"], nil } -func GetDependentFolderProjectID(_ *testing.T) string { - return testDependentFolderProjectID -} - func GetDependentFolder2ProjectID(_ *testing.T) string { return testDependentFolder2ProjectID } diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_generated_object_logmetricprojectref.golden.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_generated_object_logmetricprojectref.golden.yaml index 7a435f37f8..c5d98a1954 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_generated_object_logmetricprojectref.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_generated_object_logmetricprojectref.golden.yaml @@ -44,7 +44,6 @@ spec: unit: s valueType: DISTRIBUTION projectRef: - kind: Project name: otherproject resourceID: linearlogmetric-${uniqueId} valueExtractor: EXTRACT(jsonPayload.response) @@ -58,7 +57,7 @@ status: createTime: "1970-01-01T00:00:00Z" metricDescriptor: description: An updated sample log metric - name: projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId} + name: projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId} type: logging.googleapis.com/user/linearlogmetric-${uniqueId} observedGeneration: 2 updateTime: "1970-01-01T00:00:00Z" diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_http.log b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_http.log index 802a971213..cdbb797916 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/_http.log @@ -1,4 +1,4 @@ -GET https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false +GET https://cloudresourcemanager.googleapis.com/v1/projects/example-project-02?alt=json&prettyPrint=false User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager 403 Forbidden @@ -22,6 +22,35 @@ X-Xss-Protection: 0 --- +POST https://cloudbilling.googleapis.com/v1/billingAccounts/123456-777777-000001:testIamPermissions?alt=json&prettyPrint=false +Content-Type: application/json +User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager + +{ + "permissions": [ + "billing.resourceAssociations.create" + ] +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "permissions": [ + "billing.resourceAssociations.create" + ] +} + +--- + POST https://cloudresourcemanager.googleapis.com/v1/projects?alt=json&prettyPrint=false Content-Type: application/json User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager @@ -36,7 +65,7 @@ User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terr "id": "${testFolderId}", "type": "folder" }, - "projectId": "other${uniqueId}" + "projectId": "example-project-02" } 200 OK @@ -88,14 +117,65 @@ X-Xss-Protection: 0 }, "name": "projects/${projectNumber}", "parent": "folders/${testFolderId}", - "projectId": "other${uniqueId}", + "projectId": "example-project-02", "state": "ACTIVE" } } --- -GET https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false +PUT https://cloudbilling.googleapis.com/v1/projects/example-project-02/billingInfo?alt=json&prettyPrint=false +Content-Type: application/json +User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager + +{ + "billingAccountName": "billingAccounts/123456-777777-000001" +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "billingAccountName": "billingAccounts/123456-777777-000001", + "billingEnabled": true, + "name": "projects/example-project-02/billingInfo", + "projectId": "example-project-02" +} + +--- + +GET https://cloudbilling.googleapis.com/v1/projects/example-project-02/billingInfo?alt=json&prettyPrint=false +User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "billingAccountName": "billingAccounts/123456-777777-000001", + "billingEnabled": true, + "name": "projects/example-project-02/billingInfo", + "projectId": "example-project-02" +} + +--- + +GET https://cloudresourcemanager.googleapis.com/v1/projects/example-project-02?alt=json&prettyPrint=false User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager 200 OK @@ -121,13 +201,13 @@ X-Xss-Protection: 0 "id": "${testFolderId}", "type": "folder" }, - "projectId": "other${uniqueId}", + "projectId": "example-project-02", "projectNumber": "${projectNumber}" } --- -GET https://cloudbilling.googleapis.com/v1/projects/other${uniqueId}/billingInfo?alt=json&prettyPrint=false +GET https://cloudbilling.googleapis.com/v1/projects/example-project-02/billingInfo?alt=json&prettyPrint=false User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager 200 OK @@ -142,15 +222,15 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { - "billingAccountName": "", - "billingEnabled": false, - "name": "projects/other${uniqueId}/billingInfo", - "projectId": "other${uniqueId}" + "billingAccountName": "billingAccounts/123456-777777-000001", + "billingEnabled": true, + "name": "projects/example-project-02/billingInfo", + "projectId": "example-project-02" } --- -GET https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false +GET https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false User-Agent: google-api-go-client/0.5 404 Not Found @@ -174,7 +254,7 @@ X-Xss-Protection: 0 --- -POST https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics?alt=json&prettyPrint=false +POST https://logging.googleapis.com/v2/projects/example-project-02/metrics?alt=json&prettyPrint=false Content-Type: application/json User-Agent: google-api-go-client/0.5 @@ -260,7 +340,7 @@ X-Xss-Protection: 0 } ], "metricKind": "DELTA", - "name": "projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", + "name": "projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", "type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}", "unit": "bit", "valueType": "DISTRIBUTION" @@ -272,7 +352,7 @@ X-Xss-Protection: 0 --- -GET https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false +GET https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false User-Agent: google-api-go-client/0.5 200 OK @@ -316,7 +396,7 @@ X-Xss-Protection: 0 } ], "metricKind": "DELTA", - "name": "projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", + "name": "projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", "type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}", "unit": "bit", "valueType": "DISTRIBUTION" @@ -328,7 +408,7 @@ X-Xss-Protection: 0 --- -PUT https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false +PUT https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false Content-Type: application/json User-Agent: google-api-go-client/0.5 @@ -430,7 +510,7 @@ X-Xss-Protection: 0 } ], "metricKind": "DELTA", - "name": "projects/other${uniqueId}/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", + "name": "projects/example-project-02/metricDescriptors/logging.googleapis.com/user/linearlogmetric-${uniqueId}", "type": "logging.googleapis.com/user/linearlogmetric-${uniqueId}", "unit": "s", "valueType": "DISTRIBUTION" @@ -466,7 +546,7 @@ X-Xss-Protection: 0 --- -DELETE https://logging.googleapis.com/v2/projects/other${uniqueId}/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false +DELETE https://logging.googleapis.com/v2/projects/example-project-02/metrics/linearlogmetric-${uniqueId}?alt=json&prettyPrint=false User-Agent: google-api-go-client/0.5 200 OK @@ -480,77 +560,4 @@ X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 -{} - ---- - -GET https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false -User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager - -200 OK -Cache-Control: private -Content-Type: application/json; charset=UTF-8 -Server: ESF -Vary: Origin -Vary: X-Origin -Vary: Referer -X-Content-Type-Options: nosniff -X-Frame-Options: SAMEORIGIN -X-Xss-Protection: 0 - -{ - "createTime": "2024-04-01T12:34:56.123456Z", - "labels": { - "cnrm-test": "true", - "managed-by-cnrm": "true" - }, - "lifecycleState": "ACTIVE", - "name": "A second project", - "parent": { - "id": "${testFolderId}", - "type": "folder" - }, - "projectId": "other${uniqueId}", - "projectNumber": "${projectNumber}" -} - ---- - -GET https://cloudbilling.googleapis.com/v1/projects/other${uniqueId}/billingInfo?alt=json&prettyPrint=false -User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager - -200 OK -Cache-Control: private -Content-Type: application/json; charset=UTF-8 -Server: ESF -Vary: Origin -Vary: X-Origin -Vary: Referer -X-Content-Type-Options: nosniff -X-Frame-Options: SAMEORIGIN -X-Xss-Protection: 0 - -{ - "billingAccountName": "", - "billingEnabled": false, - "name": "projects/other${uniqueId}/billingInfo", - "projectId": "other${uniqueId}" -} - ---- - -DELETE https://cloudresourcemanager.googleapis.com/v1/projects/other${uniqueId}?alt=json&prettyPrint=false -User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager - -200 OK -Cache-Control: private -Content-Type: application/json; charset=UTF-8 -Server: ESF -Vary: Origin -Vary: X-Origin -Vary: Referer -X-Content-Type-Options: nosniff -X-Frame-Options: SAMEORIGIN -X-Xss-Protection: 0 - {} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/create.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/create.yaml index 622c6c3e06..3ff9c3bbe0 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/create.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/create.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -46,6 +46,5 @@ spec: width: 3.5 offset: 1.5 projectRef: - name: "otherproject" - kind: Project + name: otherproject resourceID: linearlogmetric-${uniqueId} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/dependencies.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/dependencies.yaml index ddcb411a3a..91b28961c8 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/dependencies.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/dependencies.yaml @@ -16,8 +16,12 @@ apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 kind: Project metadata: annotations: - cnrm.cloud.google.com/folder-id: ${TEST_FOLDER_ID} + cnrm.cloud.google.com/deletion-policy: "abandon" name: otherproject spec: + resourceID: ${TEST_DEPENDENT_FOLDER_PROJECT_ID} name: "A second project" - resourceID: other${uniqueId} + folderRef: + external: ${TEST_FOLDER_ID} + billingAccountRef: + external: ${TEST_BILLING_ACCOUNT_ID} diff --git a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/update.yaml b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/update.yaml index ad0bdabba4..876fc742c8 100644 --- a/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/update.yaml +++ b/pkg/test/resourcefixture/testdata/basic/logging/v1beta1/logginglogmetric/logmetricprojectref/update.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -50,6 +50,5 @@ spec: width: 2.5 offset: 0.5 projectRef: - name: "otherproject" - kind: Project + name: otherproject resourceID: linearlogmetric-${uniqueId}