Skip to content

Commit afb3b0b

Browse files
committed
Reconciling azure terraform state with what is actually deployed in the sub
Signed-off-by: Mark Rossetti <[email protected]>
1 parent 21f2e6c commit afb3b0b

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

infra/azure/terraform/capz/capz-monitoring/main.tf

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ variable "subscription_id" {
2626
type = string
2727
}
2828

29+
locals {
30+
# reproduce the previous pattern seen in state:
31+
# "<first-10-of-rg>-<rg>-<first-6-of-subscription>"
32+
computed_dns_prefix = format("%s-%s-%s",
33+
substr(var.resource_group_name, 0, 10),
34+
var.resource_group_name,
35+
substr(var.subscription_id, 0, 6)
36+
)
37+
}
38+
2939
# Create the "capz-monitoring" resource group
3040
resource "azurerm_resource_group" "capz-monitoring" {
3141
location = var.location
3242
name = var.resource_group_name
3343
tags = {
3444
DO-NOT-DELETE = "contact capz"
35-
creationTimestamp = timestamp()
3645
}
3746
}
3847

@@ -50,7 +59,7 @@ resource "azurerm_role_assignment" "monitoring_reader" {
5059
}
5160

5261
resource "azurerm_kubernetes_cluster" "capz-monitoring" {
53-
dns_prefix = var.resource_group_name
62+
dns_prefix = local.computed_dns_prefix
5463
location = var.location
5564
name = var.resource_group_name
5665
resource_group_name = var.resource_group_name
@@ -64,6 +73,8 @@ resource "azurerm_kubernetes_cluster" "capz-monitoring" {
6473
]
6574
kubelet_identity {
6675
user_assigned_identity_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.id
76+
client_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.client_id
77+
object_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.principal_id
6778
}
6879
identity {
6980
type = "UserAssigned"
@@ -72,8 +83,14 @@ resource "azurerm_kubernetes_cluster" "capz-monitoring" {
7283
]
7384
}
7485
default_node_pool {
75-
name = "default"
86+
name = "nodepool1"
7687
node_count = 1
77-
vm_size = "Standard_Ds2_v2"
88+
vm_size = "Standard_DS2_v2"
89+
}
90+
91+
lifecycle {
92+
ignore_changes = [
93+
"linux_profile",
94+
]
7895
}
7996
}

infra/azure/terraform/capz/cluster-api-gallery/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ resource "azurerm_user_assigned_identity" "pipelines_user_identity" {
6262
name = "ado-pipeline-mi"
6363
resource_group_name = var.resource_group_name
6464
tags = {
65+
DO-NOT-DELETE = "UpstreamInfra"
6566
creationTimestamp = "2024-10-24T00:00:00Z"
6667
}
6768
depends_on = [

infra/azure/terraform/capz/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ module "role_assignments" {
140140
# Import Cluster API gallery module
141141
module "cluster_api_gallery" {
142142
source = "./cluster-api-gallery"
143-
resource_group_name = var.resource_group_name
144-
location = var.location
143+
resource_group_name = "cluster-api-gallery"
144+
location = "northcentralus"
145145
depends_on = [
146146
module.role_assignments
147147
]
@@ -150,7 +150,7 @@ module "cluster_api_gallery" {
150150
# Import CAPZ monitoring module
151151
module "capz_monitoring" {
152152
source = "./capz-monitoring"
153-
resource_group_name = var.resource_group_name
153+
resource_group_name = "capz-monitoring"
154154
location = var.location
155155
subscription_id = data.azurerm_client_config.current.subscription_id
156156
}

infra/azure/terraform/capz/role-assignments/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ data "azuread_service_principal" "az_service_principal" {
3737
}
3838

3939
resource "azurerm_role_assignment" "rg_contributor" {
40-
principal_id = data.azuread_service_principal.az_service_principal.id
40+
principal_id = data.azuread_service_principal.az_service_principal.object_id
4141
role_definition_name = "Contributor"
4242
scope = "/subscriptions/${var.subscription_id}"
4343
}
4444

4545
resource "azurerm_role_assignment" "storage_blob_data_contributor" {
46-
principal_id = data.azuread_service_principal.az_service_principal.id
46+
principal_id = data.azuread_service_principal.az_service_principal.object_id
4747
role_definition_name = "Storage Blob Data Contributor"
4848
scope = "/subscriptions/${var.subscription_id}"
4949
}
5050

5151
resource "azurerm_role_assignment" "acr_pull" {
52-
principal_id = data.azuread_service_principal.az_service_principal.id
52+
principal_id = data.azuread_service_principal.az_service_principal.object_id
5353
role_definition_name = "AcrPull"
5454
scope = var.container_registry_scope
5555
}
@@ -71,15 +71,15 @@ resource "azurerm_role_definition" "custom_role" {
7171
}
7272

7373
resource "azurerm_role_assignment" "sp_custom_role_assignment" {
74-
principal_id = data.azuread_service_principal.az_service_principal.id
74+
principal_id = data.azuread_service_principal.az_service_principal.object_id
7575
role_definition_name = azurerm_role_definition.custom_role.name
7676
scope = "/subscriptions/${var.subscription_id}"
7777
}
7878

7979
resource "azurerm_key_vault_access_policy" "access_policy_gmsa_sp" {
8080
key_vault_id = var.key_vault_id
8181
tenant_id = data.azuread_service_principal.az_service_principal.application_tenant_id
82-
object_id = data.azuread_service_principal.az_service_principal.id
82+
object_id = data.azuread_service_principal.az_service_principal.object_id
8383
secret_permissions = [
8484
"Get",
8585
"Delete",

0 commit comments

Comments
 (0)