-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a data source for "latest" disk images #128
Comments
fyi @paddycarver because you were saying this might not actually be necessary, we might just be able to fix the shorthand. |
So I talked with @catsby about this yesterday and think I've found the bottom of this particular issue. The long and short of it is I need to read more closely. Instance templates can use family names, and that's an important feature. Instances and disks cannot. The API doesn't accept it. So the solution is to make sure only instance template use the family specification. That's a small modification to resolveImage. There are actually a few features at play here:
This issue just addresses that third point, and I think is useful. The first two points I'll address in a quick update to resolveImage and the documentation. Sorry for all the confusion on this one, was entirely caused by me not looking closely enough. |
Coming back around to this- do you have documentation for that? I've definitely created disks on instances with just a family name lately and it created just fine. I think the problem isn't that the API doesn't accept it, but that when it's returned from the API it has a full name, not just the family name we specified. |
What's the status on this? How can Terraform ( |
Anything new ? We have this exact problem here, i.e. we would like to use terraform to detect new images in a family and use them. |
For anyone who needs this feature and can't wait for it to be added, I hacked together this:
variable "family" {}
data "external" "image_name" {
program = ["sh", "${path.module}/script.sh"]
query = {
family = "${var.family}"
}
}
output "latest" {
value = "${data.external.image_name.result.name}"
}
# Exit if any steps fail
set -e
# Parse out the "family" variable from the JSON input
eval "$(jq -r '@sh "FAMILY=\(.family)"')"
# Execute the gcloud command needed to pull the latest family image
NAME=$(gcloud compute images describe-from-family $FAMILY | grep name | sed -e 's/name: //')
# Output JSON
jq -n --arg name "$NAME" '{"name":$name}'
module "nginx" {
source = "./modules/describe_image_family"
family = "nginx"
}
resource "google_compute_instance" "test-instance" {
...
boot_disk {
initialize_params {
image = "${module.nginx.latest}"
}
}
...
} This uses the echo '{"family":"nginx"}' | sh ./modules/describe_image_family/script.sh That should output JSON with the name of your latest image. |
…p#128) <!-- This change is generated by MagicModules. --> /cc @rileykarson
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Create a
data.disk_image
(naming is hard) data source so users can easily get the fullself_link
for a given disk image from a family:Should have similar features as
data.aws_ami
:Example proposed usage:
We've removed the shorthand support from
google_compute_disk
, so we should provide a data source to allow users to use it indirectly via a data source./cc @danawillow related to #1
The text was updated successfully, but these errors were encountered: