github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_resourcegroup_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/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 TestTerraformAzureResourceGroupExample(t *testing.T) {
    19  	t.Parallel()
    20  
    21  	// subscriptionID is overridden by the environment variable "ARM_SUBSCRIPTION_ID"
    22  	subscriptionID := ""
    23  	uniquePostfix := random.UniqueId()
    24  
    25  	// website::tag::1:: Configure Terraform setting up a path to Terraform code.
    26  	terraformOptions := &terraform.Options{
    27  		// The path to where our Terraform code is located
    28  		TerraformDir: "../../examples/azure/terraform-azure-resourcegroup-example",
    29  		Vars: map[string]interface{}{
    30  			"postfix": uniquePostfix,
    31  		},
    32  	}
    33  
    34  	// website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created
    35  	defer terraform.Destroy(t, terraformOptions)
    36  
    37  	// website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors.
    38  	terraform.InitAndApply(t, terraformOptions)
    39  
    40  	// website::tag::3:: Run `terraform output` to get the values of output variables
    41  	resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")
    42  
    43  	// website::tag::4:: Verify the resource group exists
    44  	exists := azure.ResourceGroupExists(t, resourceGroupName, subscriptionID)
    45  	assert.True(t, exists, "Resource group does not exist")
    46  }