forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterraform_azure_example_test.go
42 lines (31 loc) · 1.51 KB
/
terraform_azure_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build azure
// NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for
// CircleCI.
package test
import (
"testing"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute"
"github.com/gruntwork-io/terratest/modules/azure"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
// An example of how to test the Terraform module in examples/terraform-azure-example using Terratest.
func TestTerraformAzureExample(t *testing.T) {
t.Parallel()
terraformOptions := &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../examples/terraform-azure-example",
}
// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer terraform.Destroy(t, terraformOptions)
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
// Run `terraform output` to get the value of an output variable
vmName := terraform.Output(t, terraformOptions, "vm_name")
resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")
// Look up the size of the given Virtual Machine
actualVMSize := azure.GetSizeOfVirtualMachine(t, vmName, resourceGroupName, "")
expectedVMSize := compute.VirtualMachineSizeTypes("Standard_B1s")
// Test that the Virtual Machine size matches the Terraform specification
assert.Equal(t, expectedVMSize, actualVMSize)
}