Skip to content

Commit

Permalink
Merge branch 'main' into renovate/github.com-googlecloudplatform-clou…
Browse files Browse the repository at this point in the history
…d-foundation-toolkit-infra-blueprint-test-0.x
  • Loading branch information
Shabirmean authored Apr 28, 2023
2 parents 3b45cd4 + 383a8a4 commit 8a14635
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/gh_runner_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ tfenv install 1.0.6
tfenv install 1.1.3
tfenv install 1.1.9
tfenv install 1.3.3
tfenv use 1.3.3
tfenv install 1.3.9
tfenv use 1.3.9

# install the golint binary
go install golang.org/x/lint/golint@latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_any_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Terraform Checkstyle
timeout-minutes: 20
run: |
tfenv use 1.3.3
tfenv use 1.3.9
terraform fmt -recursive -check -diff ./
- name: Golang Checkstyle
timeout-minutes: 20
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
run: |
echo "Terraform validating: $SAMPLE_DIR"
cd $SAMPLE_DIR
tfenv use 1.3.3
tfenv use 1.3.9
terraform init -backend=false
terraform validate -json .
# Run the Golang unit tests in any of the samples
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_main_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Terraform Checkstyle
timeout-minutes: 20
run: |
tfenv use 1.3.3
tfenv use 1.3.9
terraform fmt -recursive -check -diff ./
- name: Golang Checkstyle
timeout-minutes: 20
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
run: |
echo "Terraform validating: $SAMPLE_DIR"
cd $SAMPLE_DIR
tfenv use 1.3.3
tfenv use 1.3.9
terraform init -backend=false
terraform validate -json .
go-unit-tests:
Expand Down
44 changes: 43 additions & 1 deletion anthos-bm-gcp-terraform/test/unit/main_custom_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,32 @@ func TestUnit_MainScript_InstallMode(goTester *testing.T) {
util.LogError(err, "Failed to read current working directory")
credentialsFile := fmt.Sprintf("%s/credentials_file.json", workingDir)

dummyCredentials := `
{
"type": "service_account",
"project_id": "temp-proj",
"private_key_id": "pkey-id",
"private_key": "-----BEGIN PRIVATE KEY-----\npkey\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "12344321",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
}
`
if _, err := os.Stat(credentialsFile); err == nil {
os.Remove(credentialsFile)
}
tmpFile, err := os.Create(credentialsFile)
util.LogError(err, fmt.Sprintf("Could not create temporary file at %s", credentialsFile))
defer tmpFile.Close()
defer os.Remove(credentialsFile)

_, err = tmpFile.WriteString(dummyCredentials)
util.LogError(err, fmt.Sprintf("Could not write to temporary file at %s", credentialsFile))
tmpFile.Sync()

mode := "install"
resourcesPath := "./resources"
bootDiskSize := 175
Expand Down Expand Up @@ -95,7 +116,7 @@ func TestUnit_MainScript_InstallMode(goTester *testing.T) {
strings.HasSuffix(moduleAddress, "vm_hosts") ||
strings.HasSuffix(moduleAddress, "service_accounts") ||
strings.Contains(moduleAddress, "google_apis") ||
strings.Contains(moduleAddress, "init_hosts") ||
strings.Contains(moduleAddress, "init_hosts") ||
strings.Contains(moduleAddress, "gke_hub_membership") {
continue
} else if strings.Contains(moduleAddress, "install_abm") {
Expand Down Expand Up @@ -123,11 +144,32 @@ func TestUnit_MainScript_ManualLB(goTester *testing.T) {
util.LogError(err, "Failed to read current working directory")
credentialsFile := fmt.Sprintf("%s/credentials_file.json", workingDir)

dummyCredentials := `
{
"type": "service_account",
"project_id": "temp-proj",
"private_key_id": "pkey-id",
"private_key": "-----BEGIN PRIVATE KEY-----\npkey\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "12344321",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
}
`
if _, err := os.Stat(credentialsFile); err == nil {
os.Remove(credentialsFile)
}
tmpFile, err := os.Create(credentialsFile)
util.LogError(err, fmt.Sprintf("Could not create temporary file at %s", credentialsFile))
defer tmpFile.Close()
defer os.Remove(credentialsFile)

_, err = tmpFile.WriteString(dummyCredentials)
util.LogError(err, fmt.Sprintf("Could not write to temporary file at %s", credentialsFile))
tmpFile.Sync()

bootDiskSize := 175
abmClusterID := "test-abm-cluster-id"
resourcesPath := "./resources"
Expand Down
43 changes: 43 additions & 0 deletions anthos-bm-gcp-terraform/test/unit/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,32 @@ func TestUnit_MainScript(goTester *testing.T) {
util.LogError(err, "Failed to read current working directory")
credentialsFile := fmt.Sprintf("%s/credentials_file.json", workingDir)

dummyCredentials := `
{
"type": "service_account",
"project_id": "temp-proj",
"private_key_id": "pkey-id",
"private_key": "-----BEGIN PRIVATE KEY-----\npkey\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "12344321",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
}
`
if _, err := os.Stat(credentialsFile); err == nil {
os.Remove(credentialsFile)
}
tmpFile, err := os.Create(credentialsFile)
util.LogError(err, fmt.Sprintf("Could not create temporary file at %s", credentialsFile))
defer tmpFile.Close()
defer os.Remove(credentialsFile)

_, err = tmpFile.WriteString(dummyCredentials)
util.LogError(err, fmt.Sprintf("Could not write to temporary file at %s", credentialsFile))
tmpFile.Sync()

resourcesPath := "./resources"
username := "test_username"
minCPUPlatform := "test_cpu_platform"
Expand Down Expand Up @@ -131,6 +152,7 @@ func TestUnit_MainScript(goTester *testing.T) {
var terraformPlan util.MainModulePlan
err = json.Unmarshal([]byte(tfPlanJSON), &terraformPlan)
util.LogError(err, "Failed to parse the JSON plan into the MainModulePlan struct in unit/module_main.go")
util.WriteToFile(tfPlanJSON, "../../plan.json")
/**
* Pro tip:
* Write the json to a file using the util.WriteToFile() method to easily debug
Expand Down Expand Up @@ -280,11 +302,32 @@ func TestUnit_MainScript_ValidateDefaults(goTester *testing.T) {
credentialsFile := fmt.Sprintf("%s/credentials_file.json", workingDir)
resourcesPath := "./resources"

dummyCredentials := `
{
"type": "service_account",
"project_id": "temp-proj",
"private_key_id": "pkey-id",
"private_key": "-----BEGIN PRIVATE KEY-----\npkey\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "12344321",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
}
`
if _, err := os.Stat(credentialsFile); err == nil {
os.Remove(credentialsFile)
}
tmpFile, err := os.Create(credentialsFile)
util.LogError(err, fmt.Sprintf("Could not create temporary file at %s", credentialsFile))
defer tmpFile.Close()
defer os.Remove(credentialsFile)

_, err = tmpFile.WriteString(dummyCredentials)
util.LogError(err, fmt.Sprintf("Could not write to temporary file at %s", credentialsFile))
tmpFile.Sync()

machineType := "test_machine_type"
tfPlanOutput := "terraform_test.tfplan"
tfPlanOutputArg := fmt.Sprintf("-out=%s", tfPlanOutput)
Expand Down
1 change: 0 additions & 1 deletion anthos-bm-gcp-terraform/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ terraform {
provider_meta "google" {
module_name = "anthos-samples/terraform/anthos-bm-terraform:gce/v0.14.0"
}

}

provider "google" {
Expand Down

0 comments on commit 8a14635

Please sign in to comment.