Multiple Block in Single Terraform File

In the previous blogs, we used single-output block in a file. in this blog, we will demonstrate that we can use multiple blocks in the same file.

let create the first.tf file in the present working directory with the below content. here we can see that we are using multiple blogs in the same file. make source that label must be different.

output "firstoutputblock" {
        value = " this is first hello world block"
}

output "secondoutputblock" {
        value = "this is second hello world block"
}

output "thirdoutputblock" {
        value = "this is third hello world block"
}

now run terraform plan and see the output.

Output:

┌──(gaurav㉿learning-ocean)-[~/youtube-course/hello-world-multi-block]
└─$ terraform plan

Changes to Outputs:
  + firstoutputblock  = " this is first hello world block"
  + secondoutputblock = "this is second hello world block"
  + thirdoutputblock  = "this is third hello world block"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

Demo Video