Part of POC to test generating sample code and articles using OpenAI. (#212)

This commit is contained in:
Tom Archer 2023-04-16 23:35:14 -07:00 committed by GitHub
parent cb11824f70
commit 84e02fea91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,55 @@
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "rg" {
name = random_pet.rg_name.id
location = var.resource_group_location
}
resource "random_string" "azurerm_traffic_manager_profile_name" {
length = 25
upper = false
numeric = false
special = false
}
resource "random_string" "azurerm_traffic_manager_profile_dns_config_relative_name" {
length = 10
upper = false
numeric = false
special = false
}
resource "azurerm_traffic_manager_profile" "profile" {
name = random_string.azurerm_traffic_manager_profile_name.result
resource_group_name = azurerm_resource_group.rg.name
traffic_routing_method = "Performance"
dns_config {
relative_name = random_string.azurerm_traffic_manager_profile_dns_config_relative_name.result
ttl = 30
}
monitor_config {
protocol = "HTTPS"
port = 443
path = "/"
expected_status_code_ranges = ["200-202", "301-302"]
}
}
resource "azurerm_traffic_manager_external_endpoint" "endpoint1" {
profile_id = azurerm_traffic_manager_profile.profile.id
name = "endpoint1"
target = "www.contoso.com"
endpoint_location = "eastus"
weight = 50
}
resource "azurerm_traffic_manager_external_endpoint" "endpoint2" {
profile_id = azurerm_traffic_manager_profile.profile.id
name = "endpoint2"
target = "www.fabrikam.com"
endpoint_location = "westus"
weight = 50
}

View File

@ -0,0 +1,11 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "azurerm_traffic_manager_profile_name" {
value = azurerm_traffic_manager_profile.profile.name
}
output "azurerm_traffic_manager_profile_fqdn" {
value = azurerm_traffic_manager_profile.profile.fqdn
}

View File

@ -0,0 +1,16 @@
terraform {
required_version = ">=1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}

View File

@ -0,0 +1,22 @@
# Azure Traffic Manager
This template deploys an Azure Traffic Manager profile with two external endpoints.
## Terraform resource types
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [azurerm_traffic_manager_profile](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/traffic_manager_profile)
- [azurerm_traffic_manager_external_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/traffic_manager_external_endpoint)
## Variables
| Name | Description | Default |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
## Example
To see how to run this example, see [Create a Traffic Manager profile using Terraform](https://learn.microsoft.com/azure/traffic-manager/quickstart-create-traffic-manager-profile-terraform).

View File

@ -0,0 +1,11 @@
variable "resource_group_location" {
type = string
description = "Location for all resources."
default = "eastus"
}
variable "resource_group_name_prefix" {
type = string
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
default = "rg"
}