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
170
votes
3 answers

Should .terraform.lock.hcl be included in the .gitignore file?

From my current knowledge, there is no reason .terraform.lock.hcl should be included in the .gitignore. Nothing about this file is private, or is there?
engineer-x
  • 2,173
  • 2
  • 12
  • 25
23
votes
2 answers

Is for_each the only way to retrieve values from a Terraform set?

Terraform recently introduced the set datatype, described on this page as: set(...): a collection of unique values that do not have any secondary identifiers or ordering. It is difficult to find documentation on how to retrieve values from…
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
19
votes
3 answers

Terraform timestamp() to numbers only string

The timestamp() function in the interpolation syntax will return an ISO 8601 formatted string, which looks like this 2019-02-06T23:22:28Z. However, I want to have a string which looks like this 20190206232240706500000001. A string with only numbers…
Jeeppler
  • 473
  • 1
  • 5
  • 9
17
votes
3 answers

Escaping dollar sign in Terraform

In an attempt to create a route key named $disconnect for an API Gateway, I'm running the snippet below, while var.route_name should receive the string "disconnect": resource "aws_apigatewayv2_route" "route" { api_id = var.apigw_api.id …
Tar
  • 8,529
  • 9
  • 56
  • 127
16
votes
2 answers

Conditionally create a single module in Terraform

I have been trying to conditionally use a module from the root module, so that for certain environments this module is not created. Many people claim that by setting the count in the module to either 0 or 1 using a conditional does the trick. module…
ccoutinho
  • 3,308
  • 5
  • 39
  • 47
12
votes
1 answer

terraform resource creation - this keyword

I came across a pattern in couple of terraform code in Github. resource "aws_vpc" "this" I wanted to know how keyword this provides a particular advantage over a named resource. I can't find a Hashicorp documentation on this…
cs1193
  • 1,090
  • 1
  • 16
  • 28
12
votes
2 answers

Edit Terraform configuration files programmatically with Python

I am trying to edit Terraform configuration files with Python. I am parsing Terraform files (.tf) using python hcl2 library which returns a python dictionary. I want to add new key/value pairs or change some values in the dictionary. Directly…
arjnklc
  • 135
  • 1
  • 7
10
votes
1 answer

Can you pass blocks as variables in Terraform, referencing the type of a resource's nested block contents?

I am trying to build in Terraform a Web ACL resource https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl This resource has the nested blocks rule->action->block and rule-> action->count I would like to have a…
Patricio Marrone
  • 1,287
  • 15
  • 20
9
votes
5 answers

terraform: filter list of maps based on key

I'm implementing a security group modules such that it will create security group rules by taking & filtering cidr & source_security_group_id to create a security group rule. The current module configuration. securty_group_module.tf resource…
Arvin
  • 315
  • 1
  • 3
  • 15
9
votes
2 answers

Convert list to map with index in Terraform

I would like to convert a simple list of string in terraform to a map with the keys as indexes. I want to go from something like this: locals { keycloak_secret = [ "account-console", "admin-cli", "broker", "internal", …
severin.julien
  • 1,314
  • 15
  • 27
8
votes
3 answers

Root policy in hcl for hashicorp vault

Is this a hashicorp vault policy so that it allows access to any resource and path within vault? I'm looking to enable an admin policy without granting root token access to anyone for obvious security reasons. path "*" { capabilities = ["create",…
Wunderbread
  • 898
  • 2
  • 14
  • 34
8
votes
4 answers

Terraform - Resource not found for variable despite having it declared in the same file

Terraform can't find a resource which is declared in the same file where the reference is. It seems that this line is causing trouble: role_arn = "${aws_iam_role.newsapi_lambda_codepipeline.arn}". It can't find newsapi_lambda_codepipeline which is…
7
votes
1 answer

Spread operator at terraform files

I want simplify such construction variable "google" { type = object({ project = string region = string zone = string }) } provider "google" { project = var.google.project region = var.google.region zone …
galkin
  • 5,264
  • 3
  • 34
  • 51
7
votes
1 answer

Terraform: Set optional resource attribute if condition is met, otherwise don't declare it

Some resources on Terraform support optional attributes. I'm interested in declaring and setting a value for the optional attribute only if a condition is met. Otherwise, don't declare it at all. All of the suggestions I found was based on declaring…
7
votes
2 answers

How can I grant roleAssignement/write permission to azure devops service connection

I am setting a staging environment for my Continuous Deployment. I am using the Azure devops service for repositories and pipelines. I need to add Azure Active Directory login to my Linux VMs. So far I followed this guide. It works on my machine,…
Vas Sim
  • 95
  • 1
  • 1
  • 7
1
2 3
19 20