github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_frontdoor_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 TestTerraformAzureFrontDoorExample(t *testing.T) {
    19  	t.Parallel()
    20  
    21  	subscriptionID := ""
    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-frontdoor-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  	resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")
    41  	frontDoorName := terraform.Output(t, terraformOptions, "front_door_name")
    42  	frontDoorUrl := terraform.Output(t, terraformOptions, "front_door_url")
    43  	frontendEndpointName := terraform.Output(t, terraformOptions, "front_door_endpoint_name")
    44  
    45  	// website::tag::4:: Get FrontDoor details and assert them against the terraform output
    46  	// NOTE: the value of subscriptionID can be left blank, it will be replaced by the value
    47  	//       of the environment variable ARM_SUBSCRIPTION_ID
    48  
    49  	frontDoorExists := azure.FrontDoorExists(t, frontDoorName, resourceGroupName, subscriptionID)
    50  	assert.True(t, frontDoorExists)
    51  
    52  	actualFrontDoorInstance := azure.GetFrontDoor(t, frontDoorName, resourceGroupName, subscriptionID)
    53  	assert.Equal(t, frontDoorName, *actualFrontDoorInstance.Name)
    54  
    55  	endpointExists := azure.FrontDoorFrontendEndpointExists(t, frontendEndpointName, frontDoorName, resourceGroupName, subscriptionID)
    56  	assert.True(t, endpointExists)
    57  
    58  	actualFrontDoorEndpoint := azure.GetFrontDoorFrontendEndpoint(t, frontendEndpointName, frontDoorName, resourceGroupName, subscriptionID)
    59  	endpointProperties := *actualFrontDoorEndpoint.FrontendEndpointProperties
    60  	assert.Equal(t, frontDoorUrl, *endpointProperties.HostName)
    61  }