-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* AFD instance & endpoint function * terraform format fixes * PR fixes * Includes more PR changes previously missed * missed renames in example tests
- Loading branch information
1 parent
e19192d
commit 9f1ad42
Showing
9 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
examples/azure/terraform-azure-frontdoor-example/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Terraform Azure Front Door Example | ||
|
||
This folder contains a simple 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 an [Azure Front Door](https://azure.microsoft.com/en-us/services/frontdoor/). | ||
|
||
Check out [test/azure/terraform_azure_frontdoor_example_test.go](./../../../test/azure/terraform_azure_frontdoor_example_test.go) to see how you can write automated tests for this module and validate the configuration of the parameters and options. | ||
|
||
**WARNING**: This module and the automated tests for it deploy real resources into your Azure account which can cost you money. | ||
|
||
## Running this module manually | ||
|
||
1. Sign up for [Azure](https://azure.microsoft.com/). | ||
1. Configure your Azure credentials using one of the [supported methods for Azure CLI | ||
tools](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) | ||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
1. Ensure [environment variables](../README.md#review-environment-variables) are available | ||
1. Run `terraform init` | ||
1. Run `terraform apply` | ||
1. When you're done, run `terraform destroy`. | ||
|
||
## Running automated tests against this module | ||
|
||
1. Sign up for [Azure](https://azure.microsoft.com/) | ||
1. Configure your Azure credentials using one of the [supported methods for Azure CLI | ||
tools](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) | ||
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_frontdoor_example_test.go` | ||
1. `go test -v -timeout 60m -tags azure -run TestTerraformAzureFrontDoorExample` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY AN AZURE FRONT DOOR | ||
# This is an example of how to deploy an Azure Front Door with the minimum resources. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# See test/azure/terraform_azure_frontdoor_example_test.go for how to write automated tests for this code. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
terraform { | ||
required_version = ">=0.14.0" | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY A RESOURCE GROUP | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "azurerm_resource_group" "rg" { | ||
name = "terratest-frontdoor-rg-${var.postfix}" | ||
location = var.location | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY FRONT DOOR | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "azurerm_frontdoor" "frontdoor" { | ||
name = "terratest-afd-${var.postfix}" | ||
resource_group_name = azurerm_resource_group.rg.name | ||
enforce_backend_pools_certificate_name_check = false | ||
|
||
routing_rule { | ||
name = "terratestRoutingRule1" | ||
accepted_protocols = ["Http", "Https"] | ||
patterns_to_match = ["/*"] | ||
frontend_endpoints = ["terratestEndpoint"] | ||
forwarding_configuration { | ||
forwarding_protocol = "MatchRequest" | ||
backend_pool_name = "terratestBackend" | ||
} | ||
} | ||
|
||
backend_pool_load_balancing { | ||
name = "terratestLoadBalanceSetting" | ||
} | ||
|
||
backend_pool_health_probe { | ||
name = "terratestHealthProbeSetting" | ||
} | ||
|
||
backend_pool { | ||
name = "terratestBackend" | ||
backend { | ||
host_header = var.backend_host | ||
address = var.backend_host | ||
http_port = 80 | ||
https_port = 443 | ||
} | ||
|
||
load_balancing_name = "terratestLoadBalanceSetting" | ||
health_probe_name = "terratestHealthProbeSetting" | ||
} | ||
|
||
frontend_endpoint { | ||
name = "terratestEndpoint" | ||
host_name = "terratest-afd-${var.postfix}.azurefd.net" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/azure/terraform-azure-frontdoor-example/output.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
output "resource_group_name" { | ||
value = azurerm_resource_group.rg.name | ||
} | ||
|
||
output "front_door_name" { | ||
description = "Specifies the name of the Front Door service." | ||
value = azurerm_frontdoor.frontdoor.name | ||
} | ||
|
||
output "front_door_url" { | ||
description = "Specifies the host name of the frontend_endpoint. Must be a domain name." | ||
value = azurerm_frontdoor.frontdoor.frontend_endpoint[0].host_name | ||
} | ||
|
||
output "front_door_endpoint_name" { | ||
description = "Specifies the friendly name of the frontend_endpoint" | ||
value = azurerm_frontdoor.frontdoor.frontend_endpoint[0].name | ||
} |
32 changes: 32 additions & 0 deletions
32
examples/azure/terraform-azure-frontdoor-example/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# ENVIRONMENT VARIABLES | ||
# Define these secrets as environment variables | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# ARM_CLIENT_ID | ||
# ARM_CLIENT_SECRET | ||
# ARM_SUBSCRIPTION_ID | ||
# ARM_TENANT_ID | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# OPTIONAL PARAMETERS | ||
# These parameters have reasonable defaults. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "location" { | ||
description = "The Azure location where to deploy your resources too" | ||
type = string | ||
default = "East US" | ||
} | ||
|
||
variable "postfix" { | ||
description = "A postfix string to centrally mitigate resource name collisions" | ||
type = string | ||
default = "resource" | ||
} | ||
|
||
variable "backend_host" { | ||
description = "The IP address or FQDN of the backend" | ||
type = string | ||
default = "www.bing.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.