Questions tagged [terraform]

A tool from Hashicorp is used for defining infrastructure as code. On-topic questions are concerned with the use of the tool itself or how to use the 'code' (HCL) to define specific structures. This tag is often used with public-cloud tags, such as "amazon-web-services", "google-cloud-platform", or "azure", to explain further the question being asked.

Terraform is an infrastructure-as-code (IaC) tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers and custom in-house solutions.

If you're asking about a Terraform issue, please ensure you are using the latest version of Terraform and the associated provider.

Configuration files describe the components needed to run a single application or your entire data centre to Terraform. Terraform generates an execution plan telling what it will do to reach the desired state and then executes it to build the described infrastructure. As the configuration changes, Terraform can determine what changed and create incremental execution plans which can be applied.

The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.

Resources

Books

Related Tags

18121 questions
173
votes
12 answers

The provided execution role does not have permissions to call DescribeNetworkInterfaces on EC2

When I input any code in this function (e.g. console.log();) and click "Save", an error occurs: The provided execution role does not have permissions to call DescribeNetworkInterfaces on EC2 exports.handler = (event, context, callback) => { …
fish
  • 2,173
  • 2
  • 13
  • 18
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
167
votes
14 answers

Terraform: Error acquiring the state lock: ConditionalCheckFailedException

I got the following error during a terraform plan which occured in my pipeline: Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: …
veben
  • 19,637
  • 14
  • 60
  • 80
158
votes
4 answers

Terraform: Conditional creation of a resource based on a variable in .tfvars

I have resources defined in .tf files that are generic to several applications. I populate many of the fields via a .tfvars file. I need to omit some of the resources entirely based on variables in the .tfvars. For example if I have a resource…
Joel Guerra
  • 4,760
  • 4
  • 12
  • 26
150
votes
9 answers

Upgrade terraform to specific version

Use case I have installed Terraform v0.11.13 via homebrew and as recommended by terraform I want to ugprade to version v0.11.14 before doing the major upgrade to v0.12.0. The problem When I run brew upgrade terraform or download the Mac package from…
kentor
  • 16,553
  • 20
  • 86
  • 144
138
votes
8 answers

How to for_each through a list(objects) in Terraform 0.12

I need to deploy a list of GCP compute instances. How do I loop for_each through the "vms" in a list of objects like this: "gcp_zone": "us-central1-a", "image_name": "centos-cloud/centos-7", "vms": [ { "hostname":…
TheShadow2707
  • 2,441
  • 3
  • 8
  • 8
137
votes
3 answers

Terraform: correct way to attach AWS managed policies to a role?

I want to attach one of the pre-existing AWS managed roles to a policy, here's my current code: resource "aws_iam_role_policy_attachment" "sto-readonly-role-policy-attach" { role = "${aws_iam_role.sto-test-role.name}" policy_arn =…
Shorn
  • 19,077
  • 15
  • 90
  • 168
136
votes
6 answers

I would like to run terraform only for a specific resource

It takes a long time to run terraform and wait. So I would like to run it to exclude rds that takes the longest time to excute or I would like to run only ec2 resource. Is there a way to do such things in terraform?
negabaro
  • 3,127
  • 7
  • 21
  • 33
134
votes
12 answers

Best practices when using Terraform

I'm in the process of swapping over our infrastructure into terraform. What's the best practice for actually managing the terraform files and state? I realize it's infrastructure as code, and i'll commit my .tf files into git, but do I commit…
Marc Young
  • 3,854
  • 3
  • 18
  • 22
129
votes
5 answers

How to create an SSH key in Terraform?

I need to spin up a bunch of EC2 boxes for different users. Each user should be sandboxed from all the others, so each EC2 box needs its own SSH key. What's the best way to accomplish this in Terraform? Almost all of the instructions I've found want…
Abe
  • 22,738
  • 26
  • 82
  • 111
125
votes
3 answers

Use terraform to set up a lambda function triggered by a scheduled event source

I would like to run an AWS lambda function every five minutes. In the AWS Management Console this is easy to set up, under the lambda function's "Event Sources" tab, but how do I set it up with Terraform? I tried to use an…
Vebjorn Ljosa
  • 17,438
  • 13
  • 70
  • 88
120
votes
4 answers

Should I commit .tfstate files to Git?

I am a little bit puzzled on the question whether to commit .tfstate files to Git or not. The Terraform documentation states: Terraform also put some state into the terraform.tfstate file by default. This state file is extremely important; it maps…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
118
votes
6 answers

How do you do simple string concatenation in Terraform?

I must be being incredibly stupid but I can't figure out how to do simple string concatenation in Terraform. I have the following data null_data_source: data "null_data_source" "api_gw_url" { inputs = { main_api_gw =…
Force Hero
  • 2,674
  • 3
  • 19
  • 35
107
votes
17 answers

Initial setup of terraform backend using terraform

I'm just getting started with terraform and I'd like to be able to use AWS S3 as my backend for storing the state of my projects. terraform { backend "s3" { bucket = "tfstate" key = "app-state" region = "us-east-1" } } I…
Jed Schneider
  • 14,085
  • 4
  • 35
  • 46
97
votes
4 answers

How are data sources used in Terraform?

The Terraform Data Sources documentation tells me what a data source is, but I do not quite understand it. Can somebody give me a use case of data source? What is the difference between it and configuring something using variables?
user389955
  • 9,605
  • 14
  • 56
  • 98
1
2 3
99 100