Skip to content

Commit e4a7a6e

Browse files
committed
randomized resource group name for resources
1 parent 742e4c7 commit e4a7a6e

5 files changed

Lines changed: 40 additions & 31 deletions

File tree

quickstart/201-k8s-cluster-with-aks-applicationgateway-ingress/main.tf

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
resource "random_pet" "rg-name" {
2+
prefix = var.resource_group_name_prefix
3+
}
4+
5+
resource "azurerm_resource_group" "rg" {
6+
name = random_pet.rg-name.id
7+
location = var.resource_group_location
8+
}
9+
110
# Locals block for hardcoded names
211
locals {
312
backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap"
@@ -6,17 +15,13 @@ locals {
615
http_setting_name = "${azurerm_virtual_network.test.name}-be-htst"
716
listener_name = "${azurerm_virtual_network.test.name}-httplstn"
817
request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt"
9-
app_gateway_subnet_name = "appgwsubnet"
10-
}
11-
12-
data "azurerm_resource_group" "rg" {
13-
name = var.resource_group_name
18+
app_gateway_subnet_name = "appgwsubnet"
1419
}
1520

1621
# User Assigned Identities
1722
resource "azurerm_user_assigned_identity" "testIdentity" {
18-
resource_group_name = data.azurerm_resource_group.rg.name
19-
location = data.azurerm_resource_group.rg.location
23+
resource_group_name = azurerm_resource_group.rg.name
24+
location = azurerm_resource_group.rg.location
2025

2126
name = "identity1"
2227

@@ -25,8 +30,8 @@ resource "azurerm_user_assigned_identity" "testIdentity" {
2530

2631
resource "azurerm_virtual_network" "test" {
2732
name = var.virtual_network_name
28-
location = data.azurerm_resource_group.rg.location
29-
resource_group_name = data.azurerm_resource_group.rg.name
33+
location = azurerm_resource_group.rg.location
34+
resource_group_name = azurerm_resource_group.rg.name
3035
address_space = [var.virtual_network_address_prefix]
3136

3237
subnet {
@@ -45,22 +50,22 @@ resource "azurerm_virtual_network" "test" {
4550
data "azurerm_subnet" "kubesubnet" {
4651
name = var.aks_subnet_name
4752
virtual_network_name = azurerm_virtual_network.test.name
48-
resource_group_name = data.azurerm_resource_group.rg.name
53+
resource_group_name = azurerm_resource_group.rg.name
4954
depends_on = [azurerm_virtual_network.test]
5055
}
5156

5257
data "azurerm_subnet" "appgwsubnet" {
5358
name = "appgwsubnet"
5459
virtual_network_name = azurerm_virtual_network.test.name
55-
resource_group_name = data.azurerm_resource_group.rg.name
60+
resource_group_name = azurerm_resource_group.rg.name
5661
depends_on = [azurerm_virtual_network.test]
5762
}
5863

5964
# Public Ip
6065
resource "azurerm_public_ip" "test" {
6166
name = "publicIp1"
62-
location = data.azurerm_resource_group.rg.location
63-
resource_group_name = data.azurerm_resource_group.rg.name
67+
location = azurerm_resource_group.rg.location
68+
resource_group_name = azurerm_resource_group.rg.name
6469
allocation_method = "Static"
6570
sku = "Standard"
6671

@@ -69,8 +74,8 @@ resource "azurerm_public_ip" "test" {
6974

7075
resource "azurerm_application_gateway" "network" {
7176
name = var.app_gateway_name
72-
resource_group_name = data.azurerm_resource_group.rg.name
73-
location = data.azurerm_resource_group.rg.location
77+
resource_group_name = azurerm_resource_group.rg.name
78+
location = azurerm_resource_group.rg.location
7479

7580
sku {
7681
name = var.app_gateway_sku
@@ -153,18 +158,18 @@ resource "azurerm_role_assignment" "ra3" {
153158
}
154159

155160
resource "azurerm_role_assignment" "ra4" {
156-
scope = data.azurerm_resource_group.rg.id
161+
scope = azurerm_resource_group.rg.id
157162
role_definition_name = "Reader"
158163
principal_id = azurerm_user_assigned_identity.testIdentity.principal_id
159164
depends_on = [azurerm_user_assigned_identity.testIdentity, azurerm_application_gateway.network]
160165
}
161166

162167
resource "azurerm_kubernetes_cluster" "k8s" {
163168
name = var.aks_name
164-
location = data.azurerm_resource_group.rg.location
169+
location = azurerm_resource_group.rg.location
165170
dns_prefix = var.aks_dns_prefix
166171

167-
resource_group_name = data.azurerm_resource_group.rg.name
172+
resource_group_name = azurerm_resource_group.rg.name
168173

169174
http_application_routing_enabled = false
170175

quickstart/201-k8s-cluster-with-aks-applicationgateway-ingress/output.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
output "resource_group_name" {
2+
value = azurerm_resource_group.rg.name
3+
}
4+
15
output "client_key" {
26
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key
37
}

quickstart/201-k8s-cluster-with-aks-applicationgateway-ingress/readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@ This template creates an Application Gateway Ingress Controller in Azure Kuberne
1818

1919
| Name | Description | Default value |
2020
|-|-|-|
21-
| `location` | (Optional) Azure Region in which to deploy these resources.| eastus |
21+
22+
| `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 |
23+
| `location` | (Optional) Azure region in which to deploy demo resources.| eastus |
2224
| `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.| |
2325
| `aks_service_principal_client_secret` | Secret of the service principal. Used by AKS to manage Azure. | |
2426
| `aks_service_principal_object_id` | Object ID of the service principal. | |
2527
| `virtual_network_name` | Virtual network name. | aksVirtualNetwork |
2628
| `virtual_network_address_prefix` | VNET address prefix. | 192.168.0.0/16 |
2729
| `aks_subnet_name` | Subnet name. | kubesubnet |
28-
| `aks_subnet_address_prefix` | Subnet address prefix. | 192.168.0.0/16 |
29-
| `app_gateway_subnet_address_prefix` | Subnet server IP address. | 192.168.0.0/16 |
30+
| `aks_subnet_address_prefix` | Subnet address prefix. | 192.168.0.0/24 |
31+
| `app_gateway_subnet_address_prefix` | Subnet server IP address. | 192.168.1.0/24 |
3032
| `app_gateway_name` | Name of the Application Gateway. | ApplicationGateway1 |
3133
| `app_gateway_sku` | Name of the Application Gateway SKU. | Standard_v2 |
3234
| `app_gateway_tier` | Tier of the Application Gateway tier. | Standard_v2 |
3335
| `aks_name` | AKS cluster name. | aks-cluster1 |
3436
| `aks_dns_prefix` | (Optional) DNS prefix to use with hosted Kubernetes API server FQDN. | aks |
35-
| `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 |
37+
| `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 |
3638
| `aks_agent_count` | The number of agent nodes for the cluster. | 3 |
3739
| `aks_agent_vm_size` | VM size. | Standard_D3_v2 |
3840
| `kubernetes_version` | Kubernetes version | 1.11.5 |

quickstart/201-k8s-cluster-with-aks-applicationgateway-ingress/terraform.tfvars

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
resource_group_name = "<resource_group_location>"
2-
3-
location = "<resource_group_location>"
4-
5-
aks_service_principal_app_id = "<service_principal_appId>"
1+
aks_service_principal_app_id = "<service_principal_app_id>"
62

73
aks_service_principal_client_secret = "<service_principal_password>"
84

quickstart/201-k8s-cluster-with-aks-applicationgateway-ingress/variables.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
variable "resource_group_name" {
2-
description = "Name of the resource group."
1+
variable "resource_group_name_prefix" {
2+
default = "rg"
3+
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
34
}
45

5-
variable "location" {
6-
description = "Location of the cluster."
6+
variable "resource_group_location" {
7+
default = "eastus"
8+
description = "Location of the resource group."
79
}
810

911
variable "aks_service_principal_app_id" {

0 commit comments

Comments
 (0)