github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/test/azure/terraform_azure_disk_example_test.go (about)

     1  // +build azure
     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  
    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 TestTerraformAzureDiskExample(t *testing.T) {
    20  	t.Parallel()
    21  
    22  	// Subscription ID, leave blank if available as an Environment Var
    23  	subID := ""
    24  	uniquePostfix := random.UniqueId()
    25  
    26  	// Configure Terraform setting up a path to Terraform code.
    27  	terraformOptions := &terraform.Options{
    28  		// The path to where our Terraform code is located
    29  		TerraformDir: "../../examples/azure/terraform-azure-disk-example",
    30  
    31  		// Variables to pass to our Terraform code using -var options
    32  		Vars: map[string]interface{}{
    33  			"postfix": uniquePostfix,
    34  		},
    35  	}
    36  
    37  	// At the end of the test, run `terraform destroy` to clean up any resources that were created
    38  	defer terraform.Destroy(t, terraformOptions)
    39  
    40  	// Run `terraform init` and `terraform apply`. Fail the test if there are any errors.
    41  	terraform.InitAndApply(t, terraformOptions)
    42  
    43  	// Run `terraform output` to get the values of output variables
    44  	resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")
    45  	expectedDiskName := terraform.Output(t, terraformOptions, "disk_name")
    46  	expectedDiskType := terraform.Output(t, terraformOptions, "disk_type")
    47  
    48  	// Check the Disk Type
    49  	actualDisk := azure.GetDisk(t, expectedDiskName, resourceGroupName, subID)
    50  	assert.Equal(t, compute.DiskStorageAccountTypes(expectedDiskType), actualDisk.Sku.Name)
    51  }