Last active
October 13, 2024 17:33
-
-
Save deepbrook/af942192c6be3c2619920083bd51ab6b to your computer and use it in GitHub Desktop.
Terraform Variable for Packer Manifest post-processor output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"builders": [ | |
{ | |
"type": "digitalocean", | |
... | |
} | |
], | |
"post-processors":[ | |
{ | |
"type": "manifest", | |
"output": "packer.auto.tfvars.json" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"builds": [ | |
{ | |
"name": "digitalocean", | |
"builder_type": "digitalocean", | |
"build_time": 1589911059, | |
"files": null, | |
"artifact_id": "ams3:63876948", | |
"packer_run_uuid": "41577b9e-4c85-ddef-a692-deaf6145783b", | |
"custom_data": null | |
}, | |
{ | |
"name": "digitalocean", | |
"builder_type": "digitalocean", | |
"build_time": 1589912902, | |
"files": null, | |
"artifact_id": "nyc1,nyc3,sgp1,lon1,fra1,tor1,sfo2,blr1,ams3:63877376", | |
"packer_run_uuid": "94e2e639-4e9b-e806-5248-7a8d7dc7eca4", | |
"custom_data": null | |
} | |
], | |
"last_run_uuid": "94e2e639-4e9b-e806-5248-7a8d7dc7eca4" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define Terraform input variables for packer variables to allow their usage | |
variable "builds" { | |
type = list( | |
object( | |
{ | |
name=string, | |
builder_type=string, | |
build_time=number, | |
files=list(object({name=string, size=number})), | |
artifact_id=string, | |
packer_run_uuid=string | |
} | |
) | |
) | |
description = "List of images, as generated by Packer's 'Manifest' post-processor." | |
} | |
variable "last_run_uuid" { | |
type = string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Accessing the artifact_id's image ID in a digitalocean_droplet resource | |
resource "digitalocean_droplet" "my-droplet" { | |
image = split(":", var.builds[length(var.builds)-1].artifact_id)[1] | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this does not read the
custom_data
field, as we do not use it.Additonally, it makes sense to specify the post-processor's output file as
<some-name>.auto.tfvars.json
in the directory you want to execute terraform in, as that automatically loads the variables for you (no need for-var-file
)