Validating yaml to json conversion

When using yaml to json conversion as it happens when using Terraform’s helm provider with a helm chart’s values.yaml file, it won’t be possible to check and get any useful validation errors, even when your terraform plan is run.

In order to check before running your plan or if you have any errors you can use yq passing as below using the values.yaml file

yq -p yaml -o json values.yaml

Error: Invalid provider configuration (terraform plan locally with TerraformCloud)

Problem

You are trying to run locally the terraform plan, while using the Terraform’s Cloud remote backend, before commiting your changes to your repo and running it through Terraform’s Cloud UI, and you are getting the previous error message:

Error: Invalid provider configuration

Solution

Remember to add the environment variables needed for your provider (AWS, Google, Exoscale etc) in the Variables section of your Terraform Cloud setup.

Even you have added them before, using a new Workspace means you will need to add them to each new workspace.

asdf and terraform (or vault or packer)

Using the asdf version manager to manage versions of various binaries like terraform, vault or packer is easily done by following the instructions below:

  1. Download and install asdf if you haven’t got it already (https://asdf-vm.com/#/core-manage-asdf)
  2. If you want to install the latest version of terraform for example do the following:
asdf plugin add terraform
asdf install terraform latest
asdf global terraform 0.14.9
asdf list
terraform
  0.14.9
terraform --version
Terraform v0.14.9

Using port number in Terraform output

Problem

You would like to output some additional information (ie port number) in addition to the variable provided by Terraform.

Solution

Use interpolation of the Terraform variable using ${var} together with the rest of the string you would like to output, like:

output "kibana_endpoint" {
  value       = "http://${aws_instance.elasticsearch.public_ip}:5601"
  description = "The Kibana endpoint"
}

More information about the language https://learn.hashicorp.com/tutorials/terraform/outputs?in=terraform/configuration-language