Reputation: 603
I am looking to use the google_os_config_guest_policies resource and am having issues with being able to pass in values to the nested block of code for package_repositories
.
Child module main.tf
package_repositories {
dynamic "apt" {
for_each = var.apt
content {
archive_type = lookup(apt.value, "archive_type", "abc")
uri = lookup(apt.value, "uri", "abc")
distribution = lookup(apt.value, "distribution", null)
components = lookup(apt.value, "components", null)
gpg_key = lookup(apt.value, "gpg_key", null)
}
}
}
Variables.tf
variable "apt" {
description = "Variable used for the APT block supported in the package_repositories variable. Pass in variables for apt_archive_type, apt_components, apt_distribution, apt_uri, apt_gpg_key."
type = any
default = []
}
terraform.tfvars
apt = [
{
archive_type = "DEB"
uri = "https://packages.cloud.google.com/apt"
distribution = "cloud-sdk-stretch"
components = ["main"]
}
]
Whenever I try to pass in values from my tfvars I only get a blank package_repositories
map passed in during my terraform plan
step.
+ package_repositories { }
I have tried to remove the dynamic block and statically define the values forpackage_repositories
which worked without any issues.
package_repositories {
apt {
archive_type = "DEB"
uri = "https://packages.cloud.google.com/apt"
distribution = "cloud-sdk-stretch"
components = ["main"]
}
}
If I try to rework my code to use the dynamic apt
block it would try to pass in null
values. Is there something wrong with syntax or is this due to being a beta resource where the dynamic block isn't working?
Upvotes: 1
Views: 1308
Reputation: 154
I tried running it, I got the desired output
+ package_repositories {
+ apt {
+ archive_type = "DEB"
+ components = [
+ "main",
]
+ distribution = "cloud-sdk-stretch"
+ uri = "https://packages.cloud.google.com/apt"
}
}
Can u please confirm are you using terraform.tfvars
or any other tfvars file. If other file , are u passing to your terraform plan using -var-file ?
Upvotes: 1