github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_acr_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 TestTerraformAzureACRExample(t *testing.T) {
    21  	t.Parallel()
    22  
    23  	uniquePostfix := strings.ToLower(random.UniqueId())
    24  	acrSKU := "Premium"
    25  
    26  	// website::tag::1:: Configure Terraform setting up a path to Terraform code.
    27  	terraformOptions := &terraform.Options{
    28  		TerraformDir: "../../examples/azure/terraform-azure-acr-example",
    29  		Vars: map[string]interface{}{
    30  			"postfix": uniquePostfix,
    31  			"sku":     acrSKU,
    32  		},
    33  	}
    34  
    35  	// website::tag::5:: At the end of the test, run `terraform destroy` to clean up any resources that were created
    36  	defer terraform.Destroy(t, terraformOptions)
    37  
    38  	// website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors.
    39  	terraform.InitAndApply(t, terraformOptions)
    40  
    41  	// website::tag::3:: Run `terraform output` to get the values of output variables
    42  	resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")
    43  	acrName := terraform.Output(t, terraformOptions, "container_registry_name")
    44  	loginServer := terraform.Output(t, terraformOptions, "login_server")
    45  
    46  	// website::tag::4:: Assert
    47  	assert.True(t, azure.ContainerRegistryExists(t, acrName, resourceGroupName, ""))
    48  
    49  	actualACR := azure.GetContainerRegistry(t, acrName, resourceGroupName, "")
    50  
    51  	assert.Equal(t, loginServer, *actualACR.LoginServer)
    52  	assert.True(t, *actualACR.AdminUserEnabled)
    53  	assert.Equal(t, acrSKU, string(actualACR.Sku.Name))
    54  }