github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/test/azure/terraform_azure_example_test.go (about) 1 // +build azure azureslim,compute 2 3 // NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for 4 // CircleCI. 5 6 package test 7 8 import ( 9 "testing" 10 11 "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" 12 "github.com/gruntwork-io/terratest/modules/azure" 13 "github.com/gruntwork-io/terratest/modules/random" 14 "github.com/gruntwork-io/terratest/modules/terraform" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestTerraformAzureExample(t *testing.T) { 19 t.Parallel() 20 21 uniquePostfix := random.UniqueId() 22 23 // website::tag::1:: Configure Terraform setting up a path to Terraform code. 24 terraformOptions := &terraform.Options{ 25 // The path to where our Terraform code is located 26 TerraformDir: "../../examples/azure/terraform-azure-example", 27 Vars: map[string]interface{}{ 28 "postfix": uniquePostfix, 29 }, 30 } 31 32 // website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created 33 defer terraform.Destroy(t, terraformOptions) 34 35 // website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. 36 terraform.InitAndApply(t, terraformOptions) 37 38 // website::tag::3:: Run `terraform output` to get the values of output variables 39 vmName := terraform.Output(t, terraformOptions, "vm_name") 40 resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name") 41 42 // website::tag::4:: Look up the size of the given Virtual Machine and ensure it matches the output. 43 actualVMSize := azure.GetSizeOfVirtualMachine(t, vmName, resourceGroupName, "") 44 expectedVMSize := compute.VirtualMachineSizeTypes("Standard_B1s") 45 assert.Equal(t, expectedVMSize, actualVMSize) 46 }