Skip to content

Commit 2bc57cf

Browse files
authored
Merge pull request #429 from ComputeCanada/remove-id
Remove id from terraform_data.yaml
2 parents 6474663 + 5a2af36 commit 2bc57cf

6 files changed

Lines changed: 58 additions & 57 deletions

File tree

aws/infrastructure.tf

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module "design" {
1919
module "configuration" {
2020
source = "../common/configuration"
2121
inventory = local.inventory
22-
post_inventory = local.post_inventory
2322
config_git_url = var.config_git_url
2423
config_version = var.config_version
2524
sudoer_username = var.sudoer_username
@@ -36,13 +35,14 @@ module "configuration" {
3635
}
3736

3837
module "provision" {
39-
source = "../common/provision"
40-
configuration = module.configuration
41-
hieradata = var.hieradata
42-
hieradata_dir = var.hieradata_dir
43-
eyaml_key = var.eyaml_key
44-
puppetfile = var.puppetfile
45-
depends_on = [aws_instance.instances, aws_eip.public_ip]
38+
source = "../common/provision"
39+
configuration = module.configuration
40+
hieradata = var.hieradata
41+
hieradata_dir = var.hieradata_dir
42+
eyaml_key = var.eyaml_key
43+
puppetfile = var.puppetfile
44+
puppetserver_ids = local.puppetserver_ids
45+
depends_on = [aws_instance.instances, aws_eip.public_ip]
4646
}
4747

4848
data "aws_availability_zones" "available" {
@@ -232,9 +232,5 @@ locals {
232232
}
233233
}
234234

235-
post_inventory = { for host, values in local.inventory :
236-
host => merge(values, {
237-
id = try(aws_instance.instances[host].id, "")
238-
})
239-
}
235+
puppetserver_ids = { for host, values in local.inventory : host => try(aws_instance.instances[host].id, "") if contains(values.tags, "puppet") }
240236
}

azure/infrastructure.tf

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module "design" {
1919
module "configuration" {
2020
source = "../common/configuration"
2121
inventory = local.inventory
22-
post_inventory = local.post_inventory
2322
config_git_url = var.config_git_url
2423
config_version = var.config_version
2524
sudoer_username = var.sudoer_username
@@ -36,13 +35,14 @@ module "configuration" {
3635
}
3736

3837
module "provision" {
39-
source = "../common/provision"
40-
configuration = module.configuration
41-
hieradata = var.hieradata
42-
hieradata_dir = var.hieradata_dir
43-
eyaml_key = var.eyaml_key
44-
puppetfile = var.puppetfile
45-
depends_on = [azurerm_linux_virtual_machine.instances]
38+
source = "../common/provision"
39+
configuration = module.configuration
40+
hieradata = var.hieradata
41+
hieradata_dir = var.hieradata_dir
42+
eyaml_key = var.eyaml_key
43+
puppetfile = var.puppetfile
44+
puppetserver_ids = local.puppetserver_ids
45+
depends_on = [azurerm_linux_virtual_machine.instances]
4646
}
4747

4848

@@ -189,9 +189,5 @@ locals {
189189
}
190190
}
191191

192-
post_inventory = { for host, values in local.inventory :
193-
host => merge(values, {
194-
id = try(azurerm_linux_virtual_machine.instances[host].id, "")
195-
})
196-
}
192+
puppetserver_ids = { for host, values in local.inventory : host => try(azurerm_linux_virtual_machine.instances[host].id, "") if contains(values.tags, "puppet") }
197193
}

common/provision/main.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ variable "hieradata" {}
88
variable "hieradata_dir" {}
99
variable "eyaml_key" {}
1010
variable "puppetfile" {}
11+
variable "puppetserver_ids" {}
1112

1213
locals {
1314
provision_folder = "etc_puppetlabs"
1415
}
1516

17+
# When adding archive_file sources, also add matching sha256 to
18+
# deploy_puppetserver_files' triggers_replace.
1619
data "archive_file" "puppetserver_files" {
1720
type = "zip"
1821
output_path = "${path.module}/files/${local.provision_folder}.zip"
@@ -78,10 +81,21 @@ resource "terraform_data" "deploy_puppetserver_files" {
7881
private_key = var.configuration.ssh_key.private
7982
}
8083

84+
# Use individual hashes instead of archive_file.output_sha256
85+
# because when using output_sha256 Terraform would trigger a deployment even when the sha256 was unchanged.
86+
# Make sure to mirror the content of archive file.
8187
triggers_replace = {
82-
archive = data.archive_file.puppetserver_files.output_sha256
88+
puppetserver_ids = var.puppetserver_ids
89+
terraform_data = sha256(var.configuration.terraform_data)
90+
terraform_facts = sha256(var.configuration.terraform_facts)
91+
hieradata = sha256(var.hieradata)
92+
eyaml_key = sha256(var.eyaml_key)
93+
puppetfile = sha256(var.puppetfile)
94+
hieradata_dir = var.hieradata_dir != "" ? sha256(yamlencode([for filename in fileset("${var.hieradata_dir}", "**/*.yaml") : { "key" = filename, "value" = file("${var.hieradata_dir}/${filename}") }])) : sha256("")
8395
}
8496

97+
depends_on = [data.archive_file.puppetserver_files]
98+
8599
provisioner "file" {
86100
source = "${path.module}/files/${local.provision_folder}.zip"
87101
destination = "${local.provision_folder}.zip"

gcp/infrastructure.tf

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ module "configuration" {
3535
}
3636

3737
module "provision" {
38-
source = "../common/provision"
39-
configuration = module.configuration
40-
hieradata = var.hieradata
41-
hieradata_dir = var.hieradata_dir
42-
eyaml_key = var.eyaml_key
43-
puppetfile = var.puppetfile
44-
depends_on = [google_compute_instance.instances]
38+
source = "../common/provision"
39+
configuration = module.configuration
40+
hieradata = var.hieradata
41+
hieradata_dir = var.hieradata_dir
42+
eyaml_key = var.eyaml_key
43+
puppetfile = var.puppetfile
44+
puppetserver_ids = local.puppetserver_ids
45+
depends_on = [google_compute_instance.instances]
4546
}
4647

4748

@@ -194,9 +195,5 @@ locals {
194195
}
195196
}
196197

197-
post_inventory = { for host, values in local.inventory :
198-
host => merge(values, {
199-
id = try(google_compute_instance.instances[host].id, "")
200-
})
201-
}
198+
puppetserver_ids = { for host, values in local.inventory : host => try(google_compute_instance.instances[host].id, "") if contains(values.tags, "puppet") }
202199
}

incus/infrastructure.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ module "configuration" {
3131
}
3232

3333
module "provision" {
34-
source = "../common/provision"
35-
configuration = module.configuration
36-
hieradata = var.hieradata
37-
hieradata_dir = var.hieradata_dir
38-
eyaml_key = var.eyaml_key
39-
puppetfile = var.puppetfile
34+
source = "../common/provision"
35+
configuration = module.configuration
36+
hieradata = var.hieradata
37+
hieradata_dir = var.hieradata_dir
38+
eyaml_key = var.eyaml_key
39+
puppetfile = var.puppetfile
40+
puppetserver_ids = local.puppetserver_ids
4041
}
4142

4243
resource "random_id" "project_name" {
@@ -162,6 +163,7 @@ locals {
162163
}
163164

164165
public_instances = { for host, values in module.configuration.inventory : host => values if contains(values.tags, "public") }
166+
puppetserver_ids = { for host, values in local.inventory : host => try(incus_instance.instances[host].id, "") if contains(values.tags, "puppet") }
165167
}
166168

167169
output "project" {

openstack/infrastructure.tf

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module "design" {
1414
module "configuration" {
1515
source = "../common/configuration"
1616
inventory = local.inventory
17-
post_inventory = local.post_inventory
1817
config_git_url = var.config_git_url
1918
config_version = var.config_version
2019
sudoer_username = var.sudoer_username
@@ -31,12 +30,13 @@ module "configuration" {
3130
}
3231

3332
module "provision" {
34-
source = "../common/provision"
35-
configuration = module.configuration
36-
hieradata = var.hieradata
37-
hieradata_dir = var.hieradata_dir
38-
eyaml_key = var.eyaml_key
39-
puppetfile = var.puppetfile
33+
source = "../common/provision"
34+
configuration = module.configuration
35+
hieradata = var.hieradata
36+
hieradata_dir = var.hieradata_dir
37+
eyaml_key = var.eyaml_key
38+
puppetfile = var.puppetfile
39+
puppetserver_ids = local.puppetserver_ids
4040
depends_on = [
4141
local.network_provision_dep,
4242
openstack_compute_instance_v2.instances,
@@ -156,9 +156,5 @@ locals {
156156
}
157157
}
158158

159-
post_inventory = { for host, values in local.inventory :
160-
host => merge(values, {
161-
id = try(openstack_compute_instance_v2.instances[host].id, "")
162-
})
163-
}
159+
puppetserver_ids = { for host, values in local.inventory : host => try(openstack_compute_instance_v2.instances[host].id, "") if contains(values.tags, "puppet") }
164160
}

0 commit comments

Comments
 (0)