randomized resource group name for resources

This commit is contained in:
Tom Archer 2022-03-05 11:52:02 -08:00
parent 742e4c7a5d
commit e4a7a6e1f3
5 changed files with 40 additions and 31 deletions

View File

@ -1,3 +1,12 @@
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
}
# Locals block for hardcoded names
locals {
backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap"
@ -6,17 +15,13 @@ locals {
http_setting_name = "${azurerm_virtual_network.test.name}-be-htst"
listener_name = "${azurerm_virtual_network.test.name}-httplstn"
request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt"
app_gateway_subnet_name = "appgwsubnet"
}
data "azurerm_resource_group" "rg" {
name = var.resource_group_name
app_gateway_subnet_name = "appgwsubnet"
}
# User Assigned Identities
resource "azurerm_user_assigned_identity" "testIdentity" {
resource_group_name = data.azurerm_resource_group.rg.name
location = data.azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
name = "identity1"
@ -25,8 +30,8 @@ resource "azurerm_user_assigned_identity" "testIdentity" {
resource "azurerm_virtual_network" "test" {
name = var.virtual_network_name
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = [var.virtual_network_address_prefix]
subnet {
@ -45,22 +50,22 @@ resource "azurerm_virtual_network" "test" {
data "azurerm_subnet" "kubesubnet" {
name = var.aks_subnet_name
virtual_network_name = azurerm_virtual_network.test.name
resource_group_name = data.azurerm_resource_group.rg.name
resource_group_name = azurerm_resource_group.rg.name
depends_on = [azurerm_virtual_network.test]
}
data "azurerm_subnet" "appgwsubnet" {
name = "appgwsubnet"
virtual_network_name = azurerm_virtual_network.test.name
resource_group_name = data.azurerm_resource_group.rg.name
resource_group_name = azurerm_resource_group.rg.name
depends_on = [azurerm_virtual_network.test]
}
# Public Ip
resource "azurerm_public_ip" "test" {
name = "publicIp1"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Static"
sku = "Standard"
@ -69,8 +74,8 @@ resource "azurerm_public_ip" "test" {
resource "azurerm_application_gateway" "network" {
name = var.app_gateway_name
resource_group_name = data.azurerm_resource_group.rg.name
location = data.azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
sku {
name = var.app_gateway_sku
@ -153,7 +158,7 @@ resource "azurerm_role_assignment" "ra3" {
}
resource "azurerm_role_assignment" "ra4" {
scope = data.azurerm_resource_group.rg.id
scope = azurerm_resource_group.rg.id
role_definition_name = "Reader"
principal_id = azurerm_user_assigned_identity.testIdentity.principal_id
depends_on = [azurerm_user_assigned_identity.testIdentity, azurerm_application_gateway.network]
@ -161,10 +166,10 @@ resource "azurerm_role_assignment" "ra4" {
resource "azurerm_kubernetes_cluster" "k8s" {
name = var.aks_name
location = data.azurerm_resource_group.rg.location
location = azurerm_resource_group.rg.location
dns_prefix = var.aks_dns_prefix
resource_group_name = data.azurerm_resource_group.rg.name
resource_group_name = azurerm_resource_group.rg.name
http_application_routing_enabled = false

View File

@ -1,3 +1,7 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "client_key" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key
}

View File

@ -18,21 +18,23 @@ This template creates an Application Gateway Ingress Controller in Azure Kuberne
| Name | Description | Default value |
|-|-|-|
| `location` | (Optional) Azure Region in which to deploy these resources.| eastus |
| `resource_group_name_prefix` | (Optional) Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `location` | (Optional) Azure region in which to deploy demo resources.| eastus |
| `aks_service_principal_app_id` | Application ID/Client ID of the service principal. Used by AKS to manage AKS related resources on Azure like vms, subnets.| |
| `aks_service_principal_client_secret` | Secret of the service principal. Used by AKS to manage Azure. | |
| `aks_service_principal_object_id` | Object ID of the service principal. | |
| `virtual_network_name` | Virtual network name. | aksVirtualNetwork |
| `virtual_network_address_prefix` | VNET address prefix. | 192.168.0.0/16 |
| `aks_subnet_name` | Subnet name. | kubesubnet |
| `aks_subnet_address_prefix` | Subnet address prefix. | 192.168.0.0/16 |
| `app_gateway_subnet_address_prefix` | Subnet server IP address. | 192.168.0.0/16 |
| `aks_subnet_address_prefix` | Subnet address prefix. | 192.168.0.0/24 |
| `app_gateway_subnet_address_prefix` | Subnet server IP address. | 192.168.1.0/24 |
| `app_gateway_name` | Name of the Application Gateway. | ApplicationGateway1 |
| `app_gateway_sku` | Name of the Application Gateway SKU. | Standard_v2 |
| `app_gateway_tier` | Tier of the Application Gateway tier. | Standard_v2 |
| `aks_name` | AKS cluster name. | aks-cluster1 |
| `aks_dns_prefix` | (Optional) DNS prefix to use with hosted Kubernetes API server FQDN. | aks |
| `aks_agent_os_disk_size` | Disk size (in GB) to provision for each of the agent pool nodes. This value ranges from 0 to 1023. Specifying 0 applies the default disk size for that agentVMSize. | 40 |
| `aks_agent_os_disk_size` | Disk size (in GB) to provision for each of the agent pool nodes. This value ranges from 0 to 1023. Value of 0 applies the default disk size for that agentVMSize. | 40 |
| `aks_agent_count` | The number of agent nodes for the cluster. | 3 |
| `aks_agent_vm_size` | VM size. | Standard_D3_v2 |
| `kubernetes_version` | Kubernetes version | 1.11.5 |

View File

@ -1,8 +1,4 @@
resource_group_name = "<resource_group_location>"
location = "<resource_group_location>"
aks_service_principal_app_id = "<service_principal_appId>"
aks_service_principal_app_id = "<service_principal_app_id>"
aks_service_principal_client_secret = "<service_principal_password>"

View File

@ -1,9 +1,11 @@
variable "resource_group_name" {
description = "Name of the resource group."
variable "resource_group_name_prefix" {
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}
variable "location" {
description = "Location of the cluster."
variable "resource_group_location" {
default = "eastus"
description = "Location of the resource group."
}
variable "aks_service_principal_app_id" {