Reputation: 40884
This is a snippet of my terraform TF file
// main "parent" module
// a list of email addresses for alert emails
variable "alertees" {
type = list(string)
}
I want to expose this attribute to other module via data "terraform_remote_state"
For example, in a subfolder I want to be able to reuse the above attribute like this
// module in subfolder
data "terraform_remote_state" "parent" {
backend = "local"
config = {
path = "../parent.tfstate"
}
}
module "custom_resource" {
source = "../../../custom_resource"
...
alertees = parent.parent
}
However I think because there is no resource to create, the terraform plan
or terraform apply
simply quitted after reporting "No changes. Infrastructure is up-to-date."
Is there anyway I can get these values committed into the state files?
Upvotes: 1
Views: 3298
Reputation: 74779
In Terraform 0.12 and earlier, terraform plan
doesn't consider changes to outputs to be a side-effect needing to be applied, as you saw.
You can use terraform refresh
to populate new outputs, but that may also cause other things in your state to be updated because it will resynchronize the state values with the remote objects.
Terraform 0.13 (which is in beta at the time I'm writing this) changes this behavior so that changes to output values are considered changes that can be planned and applied. Once using Terraform 0.13 you can use a more conventional workflow: add or update the output
blocks in the configuration, and then run terraform apply
to preview the effect of the change and choose whether to accept it.
Upvotes: 3
Reputation: 40884
I can use terraform refresh
to populate the outputs into the state file.
Upvotes: 0