Skip to content

Commit

Permalink
Add envvar GOOGLE_CHRONICLE_INSTANCE_ID for tests (#12536)
Browse files Browse the repository at this point in the history
  • Loading branch information
roaks3 authored Dec 18, 2024
1 parent 1dbed42 commit 0052688
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .ci/gcb-pr-downstream-generation-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,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_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"]
secretEnv: ["GITHUB_TOKEN_DOWNSTREAMS", "GITHUB_TOKEN_MAGIC_MODULES", "GOOGLE_BILLING_ACCOUNT", "GOOGLE_CHRONICLE_INSTANCE_ID", "GOOGLE_CUST_ID", "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 @@ -290,6 +290,8 @@ availableSecrets:
env: GITHUB_TOKEN_MAGIC_MODULES
- versionName: projects/673497134629/secrets/ci-test-billing-account/versions/latest
env: GOOGLE_BILLING_ACCOUNT
- versionName: projects/673497134629/secrets/ci-test-chronicle-instance-id/versions/latest
env: GOOGLE_CHRONICLE_INSTANCE_ID
- versionName: projects/673497134629/secrets/ci-test-cust-id/versions/latest
env: GOOGLE_CUST_ID
- versionName: projects/673497134629/secrets/ci-test-identity-user/versions/latest
Expand Down
3 changes: 3 additions & 0 deletions .ci/gcb-push-downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ steps:
secretEnv:
- "GITHUB_TOKEN_DOWNSTREAMS"
- "GOOGLE_BILLING_ACCOUNT"
- "GOOGLE_CHRONICLE_INSTANCE_ID"
- "GOOGLE_CUST_ID"
- "GOOGLE_IDENTITY_USER"
- "GOOGLE_MASTER_BILLING_ACCOUNT"
Expand Down Expand Up @@ -224,6 +225,8 @@ availableSecrets:
env: GITHUB_TOKEN_DOWNSTREAMS
- versionName: projects/673497134629/secrets/ci-test-billing-account/versions/latest
env: GOOGLE_BILLING_ACCOUNT
- versionName: projects/673497134629/secrets/ci-test-chronicle-instance-id/versions/latest
env: GOOGLE_CHRONICLE_INSTANCE_ID
- versionName: projects/673497134629/secrets/ci-test-cust-id/versions/latest
env: GOOGLE_CUST_ID
- versionName: projects/673497134629/secrets/ci-test-identity-user/versions/latest
Expand Down
4 changes: 3 additions & 1 deletion .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/magician/exec.sh'
secretEnv: ["GOOGLE_BILLING_ACCOUNT", "GOOGLE_CUST_ID", "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", "GITHUB_TOKEN_CLASSIC"]
secretEnv: ["GOOGLE_BILLING_ACCOUNT", "GOOGLE_CHRONICLE_INSTANCE_ID", "GOOGLE_CUST_ID", "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", "GITHUB_TOKEN_CLASSIC"]
env:
- "GOOGLE_REGION=us-central1"
- "GOOGLE_ZONE=us-central1-a"
Expand All @@ -22,6 +22,8 @@ availableSecrets:
secretManager:
- versionName: projects/673497134629/secrets/ci-test-billing-account/versions/latest
env: GOOGLE_BILLING_ACCOUNT
- versionName: projects/673497134629/secrets/ci-test-chronicle-instance-id/versions/latest
env: GOOGLE_CHRONICLE_INSTANCE_ID
- versionName: projects/673497134629/secrets/ci-test-cust-id/versions/latest
env: GOOGLE_CUST_ID
- versionName: projects/673497134629/secrets/ci-test-identity-user/versions/latest
Expand Down
4 changes: 3 additions & 1 deletion .ci/magician/cmd/check_cassettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ var ccRequiredEnvironmentVariables = [...]string{
"SA_KEY",
}

var ccOptionalEnvironmentVariables = [...]string{}
var ccOptionalEnvironmentVariables = [...]string{
"GOOGLE_CHRONICLE_INSTANCE_ID",
}

var checkCassettesCmd = &cobra.Command{
Use: "check-cassettes",
Expand Down
1 change: 1 addition & 0 deletions .ci/magician/cmd/test_eap_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var tevRequiredEnvironmentVariables = [...]string{
}

var tevOptionalEnvironmentVariables = [...]string{
"GOOGLE_CHRONICLE_INSTANCE_ID",
"GOOGLE_CUST_ID",
"GOOGLE_IDENTITY_USER",
"GOOGLE_MASTER_BILLING_ACCOUNT",
Expand Down
4 changes: 3 additions & 1 deletion .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ var ttvRequiredEnvironmentVariables = [...]string{
"USER",
}

var ttvOptionalEnvironmentVariables = [...]string{}
var ttvOptionalEnvironmentVariables = [...]string{
"GOOGLE_CHRONICLE_INSTANCE_ID",
}

type analytics struct {
ReplayingResult vcr.Result
Expand Down
4 changes: 3 additions & 1 deletion .ci/magician/cmd/vcr_cassette_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ var vcuRequiredEnvironmentVariables = [...]string{
"GITHUB_TOKEN_CLASSIC",
}

var vcuOptionalEnvironmentVariables = [...]string{}
var vcuOptionalEnvironmentVariables = [...]string{
"GOOGLE_CHRONICLE_INSTANCE_ID",
}

var (
//go:embed templates/vcr/vcr_cassettes_update_replaying.tmpl
Expand Down
1 change: 1 addition & 0 deletions .ci/magician/vcr/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var safeToLog = map[string]bool{
"GOCACHE": true,
"GOOGLE_APPLICATION_CREDENTIALS": false,
"GOOGLE_BILLING_ACCOUNT": false,
"GOOGLE_CHRONICLE_INSTANCE_ID": true,
"GOOGLE_CREDENTIALS": false,
"GOOGLE_CUST_ID": true,
"GOOGLE_IDENTITY_USER": true,
Expand Down
2 changes: 2 additions & 0 deletions mmv1/api/resource/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Examples struct {
// - :SERVICE_ACCT
// - :CUST_ID
// - :IDENTITY_USER
// - :CHRONICLE_ID
// This list corresponds to the `get*FromEnv` methods in provider_test.go.
TestEnvVars map[string]string `yaml:"test_env_vars,omitempty"`

Expand Down Expand Up @@ -226,6 +227,7 @@ func (e *Examples) SetHCLText() {
"CUST_ID": "A01b123xz",
"IDENTITY_USER": "cloud_identity_user",
"PAP_DESCRIPTION": "description",
"CHRONICLE_ID": "00000000-0000-0000-0000-000000000000",
}

// Apply doc defaults to test_env_vars from YAML
Expand Down
2 changes: 2 additions & 0 deletions mmv1/provider/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (td *TemplateData) GenerateTestFile(filePath string, resource api.Resource)
CUST_ID: "A01b123xz",
IDENTITY_USER: "cloud_identity_user",
PAP_DESCRIPTION: "description",
CHRONICLE_ID: "00000000-0000-0000-0000-000000000000",
}

td.GenerateFile(filePath, templatePath, tmplInput, true, templates...)
Expand Down Expand Up @@ -297,4 +298,5 @@ type TestInput struct {
CUST_ID string
IDENTITY_USER string
PAP_DESCRIPTION string
CHRONICLE_ID string
}
2 changes: 2 additions & 0 deletions mmv1/templates/terraform/env_var_context.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"{{$varKey}}": envvar.GetTestIdentityUserFromEnv(t),
{{- else if eq $varVal "PAP_DESCRIPTION" }}
"{{$varKey}}": envvar.GetTestPublicAdvertisedPrefixDescriptionFromEnv(t),
{{- else if eq $varVal "CHRONICLE_ID" }}
"{{$varKey}}": envvar.GetTestChronicleInstanceIdFromEnv(t),
{{- else if eq $varVal "ZONE" }}
"{{$varKey}}": envvar.GetTestZoneFromEnv(),
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class AllContextParameters(
val org2Beta: String,
val org2Vcr: String,

// GOOGLE_CHRONICLE_INSTANCE_ID
val chronicleInstanceIdGa: String,
val chronicleInstanceIdBeta: String,
val chronicleInstanceIdVcr: String,

// Values that are the same across GA, Beta, and VCR testing environments
val billingAccount: String, // GOOGLE_BILLING_ACCOUNT
val billingAccount2: String, // GOOGLE_BILLING_ACCOUNT_2
Expand Down Expand Up @@ -83,6 +88,7 @@ class AccTestConfiguration(
val masterBillingAccount: String,
val org: String,
val org2: String,
val chronicleInstanceId: String,
val orgDomain: String,
val project: String,
val projectNumber: String,
Expand All @@ -108,6 +114,7 @@ fun getGaAcceptanceTestConfig(allConfig: AllContextParameters): AccTestConfigura
allConfig.masterBillingAccountGa,
allConfig.org,
allConfig.org2Ga,
allConfig.chronicleInstanceIdGa,
allConfig.orgDomain,
allConfig.projectGa,
allConfig.projectNumberGa,
Expand All @@ -130,6 +137,7 @@ fun getBetaAcceptanceTestConfig(allConfig: AllContextParameters): AccTestConfigu
allConfig.masterBillingAccountBeta,
allConfig.org,
allConfig.org2Beta,
allConfig.chronicleInstanceIdBeta,
allConfig.orgDomain,
allConfig.projectBeta,
allConfig.projectNumberBeta,
Expand All @@ -152,6 +160,7 @@ fun getVcrAcceptanceTestConfig(allConfig: AllContextParameters): AccTestConfigur
allConfig.masterBillingAccountVcr,
allConfig.org,
allConfig.org2Vcr,
allConfig.chronicleInstanceIdVcr,
allConfig.orgDomain,
allConfig.projectVcr,
allConfig.projectNumberVcr,
Expand Down Expand Up @@ -180,6 +189,7 @@ fun ParametrizedWithType.configureGoogleSpecificTestParameters(config: AccTestCo
hiddenVariable("env.GOOGLE_SERVICE_ACCOUNT", config.serviceAccount, "The service account")
hiddenVariable("env.GOOGLE_ZONE", config.zone, "The google zone to use")
hiddenVariable("env.GOOGLE_IDENTITY_USER", config.identityUser, "The user for the identity platform")
hiddenVariable("env.GOOGLE_CHRONICLE_INSTANCE_ID", config.chronicleInstanceId, "The id of the Chronicle instance")
hiddenPasswordVariable("env.GOOGLE_CREDENTIALS", config.credentials, "The Google credentials for this test runner")
}

Expand Down
7 changes: 7 additions & 0 deletions mmv1/third_party/terraform/.teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ val masterBillingAccountVcr = DslContext.getParameter("masterBillingAccountVcr"
val org2Ga = DslContext.getParameter("org2Ga", "")
val org2Beta = DslContext.getParameter("org2Beta", "")
val org2Vcr = DslContext.getParameter("org2Vcr", "")
// GOOGLE_CHRONICLE_INSTANCE_ID
val chronicleInstanceIdGa = DslContext.getParameter("chronicleInstanceIdGa", "")
val chronicleInstanceIdBeta = DslContext.getParameter("chronicleInstanceIdBeta", "")
val chronicleInstanceIdVcr = DslContext.getParameter("chronicleInstanceIdVcr", "")

// Values that are the same across GA, Beta, and VCR testing environments
val billingAccount = DslContext.getParameter("billingAccount", "") // GOOGLE_BILLING_ACCOUNT
Expand Down Expand Up @@ -84,6 +88,9 @@ var allContextParams = AllContextParameters(
org2Ga,
org2Beta,
org2Vcr,
chronicleInstanceIdGa,
chronicleInstanceIdBeta,
chronicleInstanceIdVcr,
billingAccount,
billingAccount2,
custId,
Expand Down
3 changes: 3 additions & 0 deletions mmv1/third_party/terraform/.teamcity/tests/test_utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ fun testContextParameters(): AllContextParameters {
"org2Ga",
"org2Beta",
"org2Vcr",
"chronicleInstanceIdGa",
"chronicleInstanceIdBeta",
"chronicleInstanceIdVcr",
"billingAccount",
"billingAccount2",
"custId",
Expand Down
12 changes: 12 additions & 0 deletions mmv1/third_party/terraform/envvar/envvar_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ var PapDescriptionEnvVars = []string{
"GOOGLE_PUBLIC_AVERTISED_PREFIX_DESCRIPTION",
}

// This value is the instance id of a pre-configured Chronicle instance, for the purpose of
// integration tests. It is needed because the instance is 1-to-1 with a test project, and it
// cannot be created within the test org.
var ChronicleInstanceIdEnvVars = []string{
"GOOGLE_CHRONICLE_INSTANCE_ID",
}

var ImpersonateServiceAccountEnvVars = []string{
"GOOGLE_IMPERSONATE_SERVICE_ACCOUNT",
}
Expand Down Expand Up @@ -203,6 +210,11 @@ func GetTestPublicAdvertisedPrefixDescriptionFromEnv(t *testing.T) string {
return transport_tpg.MultiEnvSearch(PapDescriptionEnvVars)
}

func GetTestChronicleInstanceIdFromEnv(t *testing.T) string {
SkipIfEnvNotSet(t, ChronicleInstanceIdEnvVars...)
return transport_tpg.MultiEnvSearch(ChronicleInstanceIdEnvVars)
}

func SkipIfEnvNotSet(t *testing.T, envs ...string) {
if t == nil {
log.Printf("[DEBUG] Not running inside of test - skip skipping")
Expand Down

0 comments on commit 0052688

Please sign in to comment.