github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_disk_example_test.go (about)

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