Created
September 29, 2022 05:41
-
-
Save smilelikeshit/bd1a198c80a7ab3c26bad837045f4211 to your computer and use it in GitHub Desktop.
Terratest validated Cluster Name from GKE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"path/filepath" | |
"testing" | |
"github.com/gruntwork-io/terratest/modules/logger" | |
"github.com/gruntwork-io/terratest/modules/terraform" | |
test_structure "github.com/gruntwork-io/terratest/modules/test-structure" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestGKEClusterName(t *testing.T) { | |
t.Parallel() | |
// expected value cluster name | |
expectedClusterName := "kubernetes-test" | |
// expected value zone name | |
// enable regional zonal | |
expectedZoneName := "asia-southeast1-a" | |
// copy folder terraform project to tmp | |
outFolder := test_structure.CopyTerraformFolderToTemp(t, "./", "test_tmp") | |
// website::tag::1::Configure Terraform setting path to Terraform code, bucket name, and instance name. Construct | |
// the terraform options with default retryable errors to handle the most common retryable errors in terraform | |
// testing. | |
planFilePath := filepath.Join(outFolder, "plan_tmp.out") | |
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | |
// The path to where our Terraform code is located | |
TerraformDir: ".", | |
// Variables to pass to our Terraform code using -var options | |
Vars: map[string]interface{}{}, | |
PlanFilePath: planFilePath, | |
Logger: logger.Discard, | |
}) | |
// output terraform plan out | |
planOut := terraform.InitAndPlanAndShowWithStruct(t, terraformOptions) | |
gkeClusterStruct := planOut.ResourcePlannedValuesMap["module.gke.google_container_cluster.primary"] | |
gkeResponseClusterName := gkeClusterStruct.AttributeValues["name"] | |
gkeResponseClusterLocation := gkeClusterStruct.AttributeValues["location"] | |
// expected cluster name is kubernetes-test | |
assert.Equal(t, expectedClusterName, gkeResponseClusterName) | |
// expected zonal is asia-southeast1 | |
assert.Equal(t, expectedZoneName, gkeResponseClusterLocation) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment