github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_aci_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  	"strings"
    11  
    12  	"testing"
    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 TestTerraformAzureACIExample(t *testing.T) {
    21  	t.Parallel()
    22  
    23  	uniquePostfix := strings.ToLower(random.UniqueId())
    24  
    25  	// website::tag::1:: Configure Terraform setting up a path to Terraform code.
    26  	terraformOptions := &terraform.Options{
    27  		TerraformDir: "../../examples/azure/terraform-azure-aci-example",
    28  		Vars: map[string]interface{}{
    29  			"postfix": uniquePostfix,
    30  		},
    31  	}
    32  
    33  	// website::tag::5:: 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  	aciName := terraform.Output(t, terraformOptions, "container_instance_name")
    42  	ipAddress := terraform.Output(t, terraformOptions, "ip_address")
    43  	fqdn := terraform.Output(t, terraformOptions, "fqdn")
    44  
    45  	// website::tag::4:: Assert
    46  	assert.True(t, azure.ContainerInstanceExists(t, aciName, resourceGroupName, ""))
    47  
    48  	actualInstance := azure.GetContainerInstance(t, aciName, resourceGroupName, "")
    49  
    50  	assert.Equal(t, ipAddress, *actualInstance.ContainerGroupProperties.IPAddress.IP)
    51  	assert.Equal(t, fqdn, *actualInstance.ContainerGroupProperties.IPAddress.Fqdn)
    52  }