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