Skip to content

Commit

Permalink
resolved issues from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver.michels committed Feb 18, 2021
1 parent 6c08bdd commit e1ef32a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
5 changes: 2 additions & 3 deletions examples/azure/terraform-azure-postgresql-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains a Terraform module that deploys resources in [Azure](https://azure.microsoft.com/) to demonstrate how you can use Terratest to write automated tests for your Azure Terraform code.
This module deploys a database for PostgreSQL.

- A [Azure PostgreSQL Database](https://azure.microsoft.com/services/mysql/).
- A [Azure PostgreSQL Database](https://azure.microsoft.com/services/postgresql/).

Check out [test/azure/terraform_azure_postgresqldb_example_test.go](./../../../test/azure/terraform_azure_postgresqldb_example_test.go) to see how you can write automated tests for this module and validate the configuration of the parameters and options.

Expand All @@ -27,6 +27,5 @@ Check out [test/azure/terraform_azure_postgresqldb_example_test.go](./../../../t
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`
1. Configure your Terratest [Go test environment](../README.md)
1. `cd test/azure`
1. `go build terraform_azure_mysqldb_example_test.go`
1. `go build terraform_azure_postgresql_example_test.go`
1. `go test -v -timeout 60m -tags azure -run TestPostgreSQLDatabase`

17 changes: 14 additions & 3 deletions examples/azure/terraform-azure-postgresql-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ provider "azurerm" {
# DEPLOY A RESOURCE GROUP
# ---------------------------------------------------------------------------------------------------------------------
resource "azurerm_resource_group" "rg" {
name = "postgresql-rg"
location = "West Europe"
name = "${var.resource_group_name}-${var.postfix}"
location = var.location
}

# ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -36,7 +36,7 @@ resource "azurerm_postgresql_server" "postgresqlserver" {
auto_grow_enabled = true

administrator_login = "pgsqladmin"
administrator_login_password = "H@Sh1CoR3!"
administrator_login_password = random_password.password.result
version = "11"
ssl_enforcement_enabled = true
}
Expand All @@ -51,3 +51,14 @@ resource "azurerm_postgresql_database" "postgresqldb" {
charset = "UTF8"
collation = "English_United States.1252"
}

# ---------------------------------------------------------------------------------------------------------------------
# Use a random password geneerator
# ---------------------------------------------------------------------------------------------------------------------
resource "random_password" "password" {
length = 20
special = true
upper = true
lower = true
number = true
}
8 changes: 4 additions & 4 deletions examples/azure/terraform-azure-postgresql-example/output.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
output "sku_name" {
value = azurerm_postgresql_server.postgresqlserver.sku_name
value = azurerm_postgresql_server.postgresqlserver.sku_name
}

output "servername" {
value = azurerm_postgresql_server.postgresqlserver.name
value = azurerm_postgresql_server.postgresqlserver.name

}

output "rgname" {
value = azurerm_resource_group.rg.name
value = azurerm_resource_group.rg.name
}
32 changes: 32 additions & 0 deletions examples/azure/terraform-azure-postgresql-example/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# ---------------------------------------------------------------------------------------------------------------------
# ENVIRONMENT VARIABLES
# Define these secrets as environment variables
# ---------------------------------------------------------------------------------------------------------------------

# ARM_CLIENT_ID
# ARM_CLIENT_SECRET
# ARM_SUBSCRIPTION_ID
# ARM_TENANT_ID

# ---------------------------------------------------------------------------------------------------------------------
# REQUIRED PARAMETERS
# You must provide a value for each of these parameters.
# ---------------------------------------------------------------------------------------------------------------------

# ---------------------------------------------------------------------------------------------------------------------
# OPTIONAL PARAMETERS
# These parameters have reasonable defaults.
# ---------------------------------------------------------------------------------------------------------------------

variable "resource_group_name" {
description = "Name for the resource group holding resources for this example"
type = string
default = "terratest-postgres-rg"
}

variable "location" {
description = "The Azure region in which to deploy this sample"
type = string
default = "East US"
}

variable "postfix" {
description = "A postfix string to centrally mitigate resource name collisions."
type = string
Expand Down
1 change: 1 addition & 0 deletions test/azure/terraform_azure_postgresql_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestPostgreSQLDatabase(t *testing.T) {
// website::tag::4:: Get the Server details and assert them against the terraform output
actualServer := azure.GetPostgresqlServer(t, rgName, actualServername, subscriptionID)
// Verify
assert.NotNil(t, actualServer)
assert.Equal(t, expectedServername, actualServername)
assert.Equal(t, expectedSkuName, *actualServer.Sku.Name)

Expand Down

0 comments on commit e1ef32a

Please sign in to comment.