Questions tagged [hcl]

HashiCorp Configuration Language. The structured configuration syntax that serves as the basis for Terraform's configuration language.

HCL establishes the syntax Terraform uses for things like arguments, blocks, literal values, and expressions. But what most people think of as the Terraform language extends beyond just the syntax; the built-in functions, Terraform-specific block types (like resource and variable), and Terraform-specific named values available in expressions are all implementation details of Terraform itself.

Source: https://www.terraform.io/docs/glossary.html#hcl

291 questions
7
votes
2 answers

How can I get the Terraform module name programmatically?

I have defined the following Terraform module: module "lambda" { source = "../lambda" region = "us-west-1" account = "${var.account}" } How can I take advantage from the module name to set the…
Arcones
  • 3,954
  • 4
  • 26
  • 46
6
votes
1 answer

How to use the the newly introduced aws_cloudfront_cache_policy resource in terraform

terraform recently implemented the aws_cloudfront_cache_policy resource and data source (beginning from aws provider verion 0.3.28 IIRC). It finally enables Brotli compression, and this is why I need to use it, but I am unsure about how to integrate…
6
votes
3 answers

Efficient variable validation with Terraform

Is there an efficient way to apply validation logic to variables used in a terraform run? Specifically I want to check the length and casing of some variables. The variables are a combination of ones declared in tfvars files, in variables.tf files,…
Bob
  • 1,484
  • 5
  • 22
  • 44
6
votes
1 answer

Q: Can I insert integer/number in parameter code for Azure's JSON template code in Terraform?

We want to deploy our infrastructure through Terraform on Azure cloud. The code I want to apply uses JSON template code made by Azure itself. Code (scrubbed and removed unimportant JSON code): resource "azurerm_resource_group" "docker" { name …
U.Durk
  • 73
  • 1
  • 6
5
votes
1 answer

Create Terraform resources out of JSON values

I am looking for a way to generate Terraform code based on JSON values. Imagine I have a JSON file with the following structure: { "settings": [ { "conf": [ { "setting": "DeploymentPolicy", "namespace":…
Stefan
  • 1,253
  • 2
  • 12
  • 36
5
votes
1 answer

Difference between local values and null_data_source for intermediate values on Terraform

I have a situation where I need to store some intermediate values so I can reuse them in other parts of the root module. I know about local values and I know about null_data_source except I do not know which one is the recommended option for holding…
Mark
  • 53
  • 1
  • 4
5
votes
1 answer

Terraform: dynamic attribute from variable (in splat syntax)

In terraform HCL, is it possible to reference an object's attribute dynamically from a variable? I.e.: variable "attribute" { type = "string" } data "terraform_remote_state" "thing" { not_really_important } output "chosen" { value =…
ThisGuy
  • 2,661
  • 2
  • 18
  • 18
4
votes
1 answer

Terraform HCL - Convert List to Map of Objects?

I have a list of strings, that I need to transform to a map so that when I do jsonencode on it later, it doesn't create an Array. This is because in json-schema the properties: { ... } is not a list of properties but actually a map. So each property…
GoldFlsh
  • 1,095
  • 2
  • 11
  • 26
4
votes
1 answer

Is there a way to iterate over provider?

I have setted up two providers (2 aws accounts), I want to launch an ec2 instance on each of the accounts without having to repeat code. I tried using loops with count and for_each but no luck. variable "providers" { default = [ "aws.dev", …
ducleaux
  • 53
  • 1
  • 3
4
votes
2 answers

Split a multiline file into Terraform variable to access the values by their keys

I have a third-party maintained file with a lot of lines and it looks like: # a comment lines aaa.bbb.cc 423 ddd.ee.fff 452 ... tons.like.them 111 Is there any way to load the file to a local map and access its keys in Terraform using the syntax…
kivagant
  • 1,849
  • 2
  • 24
  • 33
4
votes
2 answers

Interpreting aws secrets in Terraform

I have the following code.. data "aws_secretsmanager_secret" "db_password" { name = "${var.db_secret}" } data "aws_secretsmanager_secret_version" "db_password" { secret_id = "${data.aws_secretsmanager_secret.db_password.id}" } master_password…
Simon E
  • 41
  • 2
4
votes
2 answers

How to get specific tag value from Terraform data.aws_instance

I'm trying to obtain the instance name from Terraform, data.aws_instance.foo.tags gives me a list of maps containing the name as one of the tags but I haven't been successful in getting the value for key Name from it.
Jakub Kania
  • 15,665
  • 2
  • 37
  • 47
3
votes
2 answers

Terraform Lifecycle Ignore changes

I am trying to apply lifecycle ignore_changes rule against parameter in resource resource "aws_servicecatalog_provisioned_product" as shown below. resource "aws_servicecatalog_provisioned_product" "example" { name =…
Mahi
  • 343
  • 1
  • 6
  • 19
3
votes
1 answer

HCL Decoding: Blocks with multiple labels

My goal is to parse a HCL configuration (Terraform Configuration) and then write the collected data about variables, outputs, resources blocks and data blocks into a Markdown file. Variables and outputs are no problem, however, as soon as I trying…
YoungGova
  • 43
  • 8
3
votes
1 answer

Add resource argument in loop from list of strings

I'm trying to set up a Digital Ocean Database Firewall, which uses the below syntax: resource "digitalocean_database_firewall" "example-fw" { cluster_id = digitalocean_database_cluster.app.id rule { type = "ip_addr" value =…
Benedict Lewis
  • 2,733
  • 7
  • 37
  • 78
1
2
3
19 20