-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathall-prod.hcl
176 lines (148 loc) · 5.22 KB
/
all-prod.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
locals {
# Automatically load environment-level variables from files in parent folders
global_vars = read_terragrunt_config(find_in_parent_folders("global.hcl"))
env_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
subscription_vars = read_terragrunt_config(find_in_parent_folders("sub.hcl"))
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
# Extract out common variables for reuse
org_prefix = local.global_vars.locals.org_prefix
subscription_id = local.global_vars.locals.subscription_id
tenant_id = local.global_vars.locals.tenant_id
client_id = local.global_vars.locals.client_id
client_secret = local.global_vars.locals.client_secret
spoke_nonprod_id = local.global_vars.locals.spoke_nonprod_id
spoke_prod_id = local.global_vars.locals.spoke_prod_id
hub_nonprod_id = local.global_vars.locals.hub_nonprod_id
hub_prod_id = local.global_vars.locals.hub_prod_id
environment = local.env_vars.locals.environment
env_stage = local.env_vars.locals.env_stage
env_stage_abbr = local.env_vars.locals.env_stage_abbr
sub_abbr = local.subscription_vars.locals.sub_abbr
region = local.region_vars.locals.region
region_abbr = local.region_vars.locals.region_abbr
resource_group_name = "${local.org_prefix}-${local.env_stage_abbr}-${local.region_abbr}-${local.sub_abbr}-rg-test"
}
# Global remote state
remote_state {
backend = "azurerm"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
resource_group_name = "tx-storage-rg"
storage_account_name = "automationadminstorage"
container_name = "terragrunt"
key = "${path_relative_to_include()}/terraform.tfstate"
#access_key = local.access_key
}
}
terraform {
source = "${find_in_parent_folders("infra")}//prod"
}
inputs = {
# required
tenant_id = local.tenant_id
subscription_id = local.subscription_id
client_id = local.client_id
client_secret = local.client_secret
spoke_nonprod_id = local.spoke_nonprod_id
spoke_prod_id = local.spoke_prod_id
hub_nonprod_id = local.hub_nonprod_id
hub_prod_id = local.hub_prod_id
# Optional
environment = local.env_stage
env_stage = local.env_stage
env_stage_abbr = local.env_stage_abbr
region = local.region
region_abbr = local.region_abbr
sub_abbr = local.sub_abbr
}
## Global terragrunt file placeholder
# Inject this provider configuration in all the modules that includes the root file without having to define them in the underlying modules
# This instructs Terragrunt to create the file provider.tf in the working directory (where Terragrunt calls terraform) before it calls any
# of the Terraform commands (e.g plan, apply, validate, etc)
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.30.0"
}
}
required_version = "1.2.0"
}
# default azurerm provider
provider "azurerm" {
client_id = var.client_id
client_secret = var.client_secret
subscription_id = var.subscription_id
tenant_id = var.tenant_id
skip_provider_registration = true
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
# hub-prod provider
provider "azurerm" {
client_id = trimspace(var.client_id)
client_secret = trimspace(var.client_secret)
tenant_id = trimspace(var.tenant_id)
alias = "hub-prod"
skip_provider_registration = true
subscription_id = trimspace(var.hub_prod_id)
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
# hub-nonprod provider
provider "azurerm" {
client_id = trimspace(var.client_id)
client_secret = trimspace(var.client_secret)
tenant_id = trimspace(var.tenant_id)
alias = "hub-nonprod"
skip_provider_registration = true
subscription_id = trimspace(var.hub_nonprod_id)
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
# spoke-prod provider
provider "azurerm" {
client_id = trimspace(var.client_id)
client_secret = trimspace(var.client_secret)
tenant_id = trimspace(var.tenant_id)
alias = "spoke-prod"
skip_provider_registration = true
subscription_id = trimspace(var.spoke_prod_id)
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
# spoke-nonprod provider
provider "azurerm" {
client_id = trimspace(var.client_id)
client_secret = trimspace(var.client_secret)
tenant_id = trimspace(var.tenant_id)
alias = "spoke-nonprod"
skip_provider_registration = true
subscription_id = trimspace(var.spoke_nonprod_id)
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
EOF
}