Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

Cannot print variable in local for terraform after apply project. Terraform print known after apply

I try print variable in local for terraform after apply project. Terraform print known after apply. Terraform version is v0.14.5

Main code https://github.com/patsevanton/terraform-yandex-cloud-examples/blob/main/terraform-count/inventory.tf

locals {
  name_attribute = "fqdn"
  group_tag = "labels"
  instances = concat(
    yandex_compute_instance.vm_1, yandex_compute_instance.vm_2
  )
 .........
}

I run terraform apply, terraform created resource.

yandex_vpc_network.network-1: Creating...
yandex_vpc_network.network-1: Creation complete after 2s [id=enp6dunid3n9lritpr4j]
yandex_vpc_subnet.subnet-1: Creating...
yandex_vpc_subnet.subnet-1: Creation complete after 0s [id=e9ba67sdgqfkni8n9ks5]
yandex_compute_instance.vm_1[0]: Creating...
yandex_compute_instance.vm_1[0]: Still creating... [10s elapsed]
yandex_compute_instance.vm_1[0]: Still creating... [20s elapsed]
yandex_compute_instance.vm_1[0]: Creation complete after 26s [id=fhmncj5leton3br3nch9]
local_file.inventory: Creating...
local_file.inventory: Creation complete after 0s [id=c7377ed426dbf44a250a9293afd2dc55e6c279c5]

Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

Outputs:

inventory_file = "./inventory.yaml"

I run terraform console

terraform console
> local.instances
(known after apply)

How print variable in local for terraform after apply project ?

question from:https://stackoverflow.com/questions/65879070/cannot-print-variable-in-local-for-terraform-after-apply-project-terraform-prin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on the comments.

The issue was caused by missing vm_2 instance. Once the instance was added, local.instances worked as expected in the terraform console.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...