github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/test/azure/terraform_azure_postgresql_example_test.go (about)

     1  // +build azure
     2  
     3  // NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for
     4  // CircleCI.
     5  
     6  package test
     7  
     8  import (
     9  	"os"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/gruntwork-io/terratest/modules/azure"
    14  	"github.com/gruntwork-io/terratest/modules/random"
    15  	"github.com/gruntwork-io/terratest/modules/terraform"
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestPostgreSQLDatabase(t *testing.T) {
    20  	t.Parallel()
    21  
    22  	uniquePostfix := strings.ToLower(random.UniqueId())
    23  
    24  	// website::tag::1:: Configure Terraform setting up a path to Terraform code.
    25  	terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
    26  		TerraformDir: "../../examples/azure/terraform-azure-postgresql-example",
    27  		Vars: map[string]interface{}{
    28  			"postfix": uniquePostfix,
    29  		},
    30  		NoColor: true,
    31  	})
    32  	// website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created
    33  	defer terraform.Destroy(t, terraformOptions)
    34  
    35  	// website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors.
    36  	terraform.InitAndApply(t, terraformOptions)
    37  
    38  	subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
    39  
    40  	// website::tag::3:: Run `terraform output` to get the values of output variables
    41  	expectedServername := "postgresqlserver-" + uniquePostfix // see fixture
    42  	actualServername := terraform.Output(t, terraformOptions, "servername")
    43  	rgName := terraform.Output(t, terraformOptions, "rgname")
    44  	expectedSkuName := terraform.Output(t, terraformOptions, "sku_name")
    45  
    46  	// website::tag::4:: Get the Server details and assert them against the terraform output
    47  	actualServer := azure.GetPostgreSQLServer(t, rgName, actualServername, subscriptionID)
    48  	// Verify
    49  	assert.NotNil(t, actualServer)
    50  	assert.Equal(t, expectedServername, actualServername)
    51  	assert.Equal(t, expectedSkuName, *actualServer.Sku.Name)
    52  
    53  }