New sample (converted from Bicep via OpenAI)

This commit is contained in:
Tom Archer 2023-03-18 12:49:54 -07:00
parent 35b3afaf63
commit bb54b1f836
5 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,90 @@
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" "aazurerm_cdn_profile_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_cdn_profile" "profile" {
name = "profile-${random_string.azurerm_cdn_endpoint_name.result}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = var.cdn_sku
}
resource "random_string" "azurerm_cdn_endpoint_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_cdn_endpoint" "endpoint" {
name = "endpoint-${random_string.azurerm_cdn_endpoint_name.result}"
profile_name = azurerm_cdn_profile.profile.name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
is_http_allowed = true
is_https_allowed = true
querystring_caching_behaviour = "IgnoreQueryString"
is_compression_enabled = true
content_types_to_compress = [
"application/eot",
"application/font",
"application/font-sfnt",
"application/javascript",
"application/json",
"application/opentype",
"application/otf",
"application/pkcs7-mime",
"application/truetype",
"application/ttf",
"application/vnd.ms-fontobject",
"application/xhtml+xml",
"application/xml",
"application/xml+rss",
"application/x-font-opentype",
"application/x-font-truetype",
"application/x-font-ttf",
"application/x-httpd-cgi",
"application/x-javascript",
"application/x-mpegurl",
"application/x-opentype",
"application/x-otf",
"application/x-perl",
"application/x-ttf",
"font/eot",
"font/ttf",
"font/otf",
"font/opentype",
"image/svg+xml",
"text/css",
"text/csv",
"text/html",
"text/javascript",
"text/js",
"text/plain",
"text/richtext",
"text/tab-separated-values",
"text/xml",
"text/x-script",
"text/x-component",
"text/x-java-source",
]
origin {
name = "origin1"
host_name = var.origin_url
}
}

View File

@ -0,0 +1,7 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "cdn_endpoint_endpoint_name" {
value = azurerm_cdn_endpoint.endpoint.name
}

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,24 @@
# Azure CDN profile and endpoint
This template creates an Azure CDN profile and endpoint.
## 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_cdn_profile](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cdn_profile)
- [azurerm_cdn_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cdn_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 |
| `origin_url` | Url of the origin. | null |
| `cdn_sku` | CDN SKU names. | "Standard_Microsoft" |
## Example
To see how to run this example, see [Create an Azure CDN profile and endpoint using Terraform](https://learn.microsoft.com/azure/cdn/create-profile-endpoint-bicep).

View File

@ -0,0 +1,27 @@
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"
}
variable "origin_url" {
type = string
description = "Url of the origin."
default = "www.contoso.com"
}
variable "cdn_sku" {
type = string
description = "CDN SKU names."
default = "Standard_Microsoft"
validation {
condition = contains(["Standard_Akamai", "Standard_Microsoft", "Standard_Verizon", "Premium_Verizon"], var.cdn_sku)
error_message = "The cdn_sku must be one of the following: Standard_Akamai, Standard_Microsoft, Standard_Verizon, Premium_Verizon."
}
}