-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterragrunt.hcl
59 lines (52 loc) · 1.49 KB
/
terragrunt.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
terraform {
extra_arguments "conditional_vars" {
commands = [
"apply",
"plan"
]
required_var_files = [
"${get_parent_terragrunt_dir()}/environments/test.tfvars"
]
}
}
# src https://www.nordhero.com/posts/mastering-deployments-with-terragrunt/
locals {
env_vars = read_terragrunt_config("./environments/env.hcl")
# Extract the variables we need with the backend configuration
group_name = local.env_vars.locals.group_name
proj_name = local.env_vars.locals.proj_name
region = local.env_vars.locals.region
gitlab_url = local.env_vars.locals.gitlab_url
gitlab_token = local.env_vars.locals.gitlab_token
aws_creds_file = local.env_vars.locals.aws_creds_file
}
# make backend.tf file
generate "backend" {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
terraform {
backend "s3" {
bucket = "tf-learn-second"
key = "tfstate/${local.group_name}_${local.proj_name}.tfstate" # tfstate is folder on bucket, tfmodule1 is object\file
region = "${local.region}"
}
}
EOF
}
# make provider.tf
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt" # Allow modules to override provider settings
contents = <<EOF
provider "aws" {
region = "${local.region}"
shared_credentials_files = "${local.aws_creds_file}"
profile = "default"
}
provider "gitlab" {
base_url = "${local.gitlab_url}"
token = "${local.gitlab_token}"
}
EOF
}