terraform-provider-ignition
terraform-provider-ignition copied to clipboard
Saved plan fails to apply when datasource depends on resource
This issue was originally opened by @alkar as hashicorp/terraform#15830. It was migrated here as a result of the provider split. The original body of the issue is below.
Terraform Version
v0.9.11
Terraform Configuration Files
resource "random_id" "x" {
byte_length = 1
}
data "ignition_file" "x" {
filesystem = "root"
path = "/x"
content {
content = "${random_id.x.hex}"
}
}
data "ignition_systemd_unit" "x" {
name = "x.service"
content = ""
}
data "ignition_config" "x" {
files = ["${data.ignition_file.x.id}"]
systemd = ["${data.ignition_systemd_unit.x.id}"]
}
Expected Behavior
It should be able to apply from a saved plan.
Steps to Reproduce
Applying directly works:
$ terraform apply
data.ignition_systemd_unit.x: Refreshing state...
random_id.x: Creating...
b64: "" => "<computed>"
b64_std: "" => "<computed>"
b64_url: "" => "<computed>"
byte_length: "" => "1"
dec: "" => "<computed>"
hex: "" => "<computed>"
random_id.x: Creation complete (ID: dg)
data.ignition_file.x: Refreshing state...
data.ignition_config.x: Refreshing state...
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path:
However, applying from a saved plan file:
$ terraform plan -out sp && terraform apply sp
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
data.ignition_systemd_unit.x: Refreshing state...
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.
Your plan was also saved to the path below. Call the "apply" subcommand
with this plan file and Terraform will exactly execute this execution
plan.
Path: sp
<= data.ignition_config.x
files.#: "<computed>"
rendered: "<computed>"
systemd.#: "1"
systemd.0: "c3582dce636f921cdc80f72fd27057f1fd14bd0b2a656383e2da0de1b09d3d2c"
<= data.ignition_file.x
content.#: "1"
content.0.content: "${random_id.x.hex}"
content.0.mime: "text/plain"
filesystem: "root"
path: "/x"
+ random_id.x
b64: "<computed>"
b64_std: "<computed>"
b64_url: "<computed>"
byte_length: "1"
dec: "<computed>"
hex: "<computed>"
Plan: 1 to add, 0 to change, 0 to destroy.
random_id.x: Creating...
b64: "" => "<computed>"
b64_std: "" => "<computed>"
b64_url: "" => "<computed>"
byte_length: "" => "1"
dec: "" => "<computed>"
hex: "" => "<computed>"
random_id.x: Creation complete (ID: Qg)
data.ignition_file.x: Refreshing state...
data.ignition_config.x: Refreshing state...
Error applying plan:
1 error(s) occurred:
* data.ignition_config.x: data.ignition_config.x: invalid systemd unit "c3582dce636f921cdc80f72fd27057f1fd14bd0b2a656383e2da0de1b09d3d2c", unknown systemd unit id
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
$ terraform apply sp
Failed to load backend: This plan was created against an older state than is current. Please create
a new plan file against the latest state and try again.
Terraform doesn't allow you to run plans that were created from older
states since it doesn't properly represent the latest changes Terraform
may have made, and can result in unsafe behavior.
Plan Serial: 0
Current Serial: 1
$ terraform plan -out sp && terraform apply sp
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
random_id.x: Refreshing state... (ID: Qg)
data.ignition_systemd_unit.x: Refreshing state...
data.ignition_file.x: Refreshing state...
data.ignition_config.x: Refreshing state...
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, Terraform
doesn't need to do anything.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
References
Possibly hashicorp/terraform#11518