Questions tagged [terraform]

For questions about Terraform, an open source tool to maintain infrastructure.

Filter by
Sorted by
Tagged with
63 votes
7 answers
27k views

How can I manage secrets in .tf and .tfstate?

I would like to use the Terraform MySQL Provider to keep a list of mysql users and grants handy for creating new test environments. The .tf and .tfstate files both seem to want to store the MySQL ...
Anthony Neace's user avatar
62 votes
5 answers
100k views

Terraform: apply only one tf file

I have my security groups in a securitygroup.tf file. In the same dir there are plenty of other resource descriptions (rds, ec2 etc). Is there a way to perform a terraform apply --auto-approve only ...
pkaramol's user avatar
  • 987
51 votes
6 answers
23k views

How to test a Terraform Configuration?

If you had a Terraform configuration that had a moderate degree of complexity, how would you write tests around the configuration that could be executed as part of a Continuous Integration / ...
Richard Slater's user avatar
31 votes
3 answers
63k views

How to use terraform import with module

Terraform v0.11.11 We have a quite big AWS setup created with Terraform. Different regions are applied separately, and that is why we have most of the things in modules which are imported like this: ...
Bysmyyr's user avatar
  • 411
29 votes
2 answers
31k views

How to use cloud-init with Terraform?

I am working with Digital Ocean and Terraform and I already can automate the domain, subdomain, network preferences and the host but there is a section called User data that looks like this: The ...
Gepser Hoil's user avatar
  • 1,312
17 votes
5 answers
19k views

Terraform: Is there a concise syntax for specifying multiple tags for a resource?

To attach multiple tags to a resource, I currently use multiple tag blocks: resource "aws_autoscaling_group" "instance" { ... tag { key = "Name" value = "${...
Philipp Claßen's user avatar
16 votes
2 answers
15k views

Terraform apply output only

I'm trying to apply only the output variable definition. Here is the "output" I want to apply. output "environment_information" { value = { foo = "value1" ...
Turkdogan Tasdelen's user avatar
14 votes
2 answers
167 views

How can I keep track of my Cloud Resource use?

I am trying to automate my AWS application deployment with Jenkins. Right now if we want to update the application in any of the environments, say UAT, we build our docker images, find the current ...
Chris's user avatar
  • 305
13 votes
1 answer
2k views

How to support releasing new versions of the code, running in parallel with the last stable release?

I have one service in production (on AWS), which follows the immutable server pattern. Its deployment looks like this: Create a new AMI with Packer. Create a new CloudFormation stack, starting with ...
Philipp Claßen's user avatar
13 votes
3 answers
52k views

How to make Terraform Modules wait for resources to be created in place of using computed values

Today I am working on building out several custom Terraform Modules. The issue that I am trying to figure out how to work around dependencies within modules. Until TF 0.12 is released we cannot ...
Steven K7FAQ's user avatar
11 votes
1 answer
3k views

Provisioning times for Redis in cloud taking too long, how can we shorten it?

Provisioning a 1 GB Redis cache service on AWS takes around 8 minutes. Doing the same on Azure takes around 16 minutes. Ours Terraform scripts need the call back from the Redis systems. Why is this ...
Rıfat Erdem Sahin's user avatar
10 votes
4 answers
17k views

Is there a way to lint Terraform?

I'm hoping there is something to pick up when I have misspelled variables and comments to save me some time when I'm checking my code and reduce the potential for any errors. I normally use IntelliJ ...
doug's user avatar
  • 521
10 votes
3 answers
475 views

How should we automatically rebuild immutable infrastructure when new packages are available?

We're going to be using Terraform to automate our infrastructure deployment and Packer to create the machine images deployed by Terraform. By following immutable infrastructure design principles, we ...
Thuy Guevarra's user avatar
10 votes
2 answers
417 views

How to create a host on a DigitalOcean team with Terraform?

Teams on Digital Ocean are very recent and there is no documentation about using them with Terraform. All information I can found is how to work with them manually. I was hoping that I could say ...
Gepser Hoil's user avatar
  • 1,312
9 votes
1 answer
5k views

How do I detach an existing volume and attach a new volume with Terraform?

Is there a way to detach EBS volume from existing EC2 instance and attach a new EBS volume using Terraform v0.9.2 ? I prefer to replace the volume rather than trying to destroy the instance and ...
Berlin's user avatar
  • 780
9 votes
1 answer
739 views

How can I manage changes in desired capacity due to scaling policies in AutoScaling Group state?

How can I manage changes in desired capacity due to scaling policies in AutoScaling Group state in terraform? Specifically, suppose I provision an aws_autoscaling_group resource with terraform with a ...
Anthony Neace's user avatar
8 votes
5 answers
13k views

How do I run Terraform with AWS MFA?

I'm using Terraform with the terraform-provider-aws provider to manage my AWS infrastructure. I'm trying to enable mfa_delete on an S3 bucket, but when I try to apply the change I get this error: 1 ...
Nic's user avatar
  • 351
8 votes
1 answer
2k views

How to organize infrastructure as code projects?

I have completed an Infrastructure-as-Code project using Terraform and Ansible. Currently, I organize my project as follows: Project1 Terraform ec2.tf rds.tf … variables....
user389955's user avatar
7 votes
2 answers
4k views

Does terraform support blue green deployments and roll backs out of the box

I have been trying use terraform for a while . any suggestions/tips on how I can handle blue green deployments . I see how terraform enables it with auto scale groups on aws . But I’d like run some ...
Zak's user avatar
  • 81
7 votes
2 answers
2k views

How to add shards to a Redis cluster managed by Terraform without loosing all state?

I have set up a Redis cluster with Terraform. The setup looks like this: resource "aws_elasticache_replication_group" "instance" { replication_group_id = "test" node_type = "...
Philipp Claßen's user avatar
6 votes
3 answers
7k views

Get private key from terraform state?

I used the terraform resource tls_private_key to generate a key and push that into AWS, but it didn't give me the private key to use to access the related resources. How can I recover that key?
Josiah's user avatar
  • 363
6 votes
6 answers
1k views

In the HashiCorp stack, where's the appropriate place to add users?

I'm in the process of building some custom Linux images using HashiCorp's Packer, which will later be deployed to Azure using HashiCorp's Terraform. The VMs created from these images will need to have ...
cori's user avatar
  • 161
6 votes
3 answers
729 views

Baking Immutable Images

I am working on a project and we are trying to bake immutable images on containers as IaC. These images can have J2EE, .NET or Python apps on it. All OS patches should be applied to this image ...
user3499779's user avatar
6 votes
2 answers
4k views

What is the difference between modules and workspaces in Terraform

I currently use Terraform workspaces to configure different environments like dev, test, prod, and my code works fine. And I believe I can use workspaces to configure different regions as well. ...
user389955's user avatar
6 votes
3 answers
6k views

Terragrunt Linter

I'm having troubles using HCL files at VSCode. When I open the HCL file the indentations are messy. So I fix it and close the file, when I open again...messy again... Someone know a add-ons to works ...
Vader's user avatar
  • 466
6 votes
2 answers
252 views

How to reconcile Infrastructure as Code and not storing env config in code?

When developing a Web App, and trying to adhere to what is generally considered best practice, e.g. The 12 factor app methodology etc. One key concept is to keep configuration and sensitive data out ...
George Edwards's user avatar
6 votes
1 answer
3k views

Terraform: how do you inspect sensitive data?

In a resource of type aws_ecs_task_definition my plan has an line that looks like this: ~ container_definitions = (sensitive) # forces replacement Now in principle this could be doing anything - ...
Carl Patenaude Poulin's user avatar
6 votes
3 answers
2k views

Terraform AWS AZ error - manually specify AZ?

I'm fairly new to terraform and when creating AWS infrastructure I use the following to fetch the 'available' availability zones for my region (us-east-1) where I'm trying to create an EKS cluster. ...
Caledonia91's user avatar
5 votes
4 answers
3k views

How can I get terraforms extern to execute `ssh-keygen -y -f ~/.ssh/id_rsa`?

I seem to be confused about how external works. I tried: data "external" "local_key" { program = [ "ssh-keygen", "-y", "-f ~/.ssh/id_rsa" ] } This gives me: failed to execute "ssh-keygen":...
Kit Sunde's user avatar
  • 153
5 votes
1 answer
5k views

Getting "(sensitive value)" from `terraform state show`, how can I uncensor the value?

When I run I try to use terraform state show on variables flagged sensitive on some addresses I get private_data = (sensitive value) How can I get around this problem?
Evan Carroll's user avatar
  • 2,089
5 votes
1 answer
7k views

How to apply using Terraform to launch multiple EC2 Resource with different configs (VPC not maintained by TF)

We are planning to use Terraform for provisioning EC2 instance which will host Oracle DB. While we are able to achieve this, there are some questions for which I am searching for suggestions / ...
Dvusrgme's user avatar
  • 153
5 votes
2 answers
2k views

How to `terraform destroy` an `aws_instance` without also destroying its `aws_ebs_volume` (separate resource)

$ terraform -version Terraform v0.12.21 + provider.aws v2.34.0 Given a terraform configuration for one set of single aws_instance, aws_ebs_volume and aws_volume_attachment resources, each named, say,...
cueedee's user avatar
  • 151
5 votes
1 answer
12k views

How do I enter a multi line variable in Terraform?

It's for the public key variable for testing lab enviroments in my variables.tf file I tried <<EOF the string EOF but terraform dosn't seem to like that
doug's user avatar
  • 521
5 votes
1 answer
746 views

Terraform: Delay the MySQL Provider

I have a Terraform project which uses the MySQL provider. Because of the way Terraform works, the MySQL provider will fail to load correctly because the AWS_RDS instance doesn't exist. Is there a ...
Black Dynamite's user avatar
5 votes
0 answers
282 views

How Can I create layers for a lambda using Terraform? [closed]

The docs only seem to give me the option to reference existing layers. I want to make the layer for my lambda in my terraform code rather than through the console but can't see any option to do this ...
doug's user avatar
  • 521
4 votes
3 answers
18k views

Terraform get list index on for_each

Terraform newbie here. I'd like to iterate a list using for_each, but it seems like the key and value are the same: provider "aws" { profile = "default" region = "us-east-1" } variable "...
Moshe's user avatar
  • 173
4 votes
1 answer
267 views

difference between packer and matchbox

I have this setup to standup a baremetal machine: Terraform-> Matchbox \-> Chef-> Docker My colleague has a setup to standup VMs in AWS: Terraform-> Packer-> Chef-> ...
scott's user avatar
  • 466
4 votes
1 answer
1k views

Terraform variable Validation

is it possible to use validation of a variable type equals list(string)? My example: main.tf name = "tf-prd-sg-foo" image_id = "ami-00e788542ee66c64f" ...
Vader's user avatar
  • 466
4 votes
1 answer
2k views

create resource name based on terraform.workspace

I want to have different s3 names based on different environments using terraform. If I define the name in terraform.tfvar, it won't work: s3_bucket_name = "tf-${terraform.workspace}" If I ...
user389955's user avatar
4 votes
2 answers
858 views

What is the best way to install ArgoCD as code?

Working on getting a full deployment pipeline set up using GitOps and Everything as Code. I, therefore, need to be able to spin everything up and down with a single click (or pretty close to it!). My ...
James Geddes's user avatar
4 votes
3 answers
12k views

Skip terraform resource if it exists

I'm Getting an error creating a secret because it was created manually. Error: error creating Secrets Manager Secret: ResourceExistsException: The operation failed because the secret <SECRET> ...
DorAmar's user avatar
  • 43
4 votes
1 answer
5k views

The provider hashicorp/aws does not support resource type "aws_internet_gateway_attachment"

Why do I get this error with Terraform, The provider hashicorp/aws does not support resource type "aws_internet_gateway_attachment". You can see the resource ...
Evan Carroll's user avatar
  • 2,089
4 votes
2 answers
1k views

Cloud-Init Script Won't Run?

I am working through this Terraform tutorial, which boots up a Go web app on an EC2 instance, using Terraform and cloud-init. This is my Terraform config file: terraform { required_version = "&...
Huzi 's user avatar
  • 41
4 votes
1 answer
1k views

Gitlab CI: change pipeline definition dynamically

I need to pass info from stage A to stage B so I can change stage B dynamically. Details: I have a stage (A) where I validate a terraform plan and check if it's going to destroy resources. I have ...
Pablo's user avatar
  • 143
4 votes
3 answers
13k views

How do I use the remote-exec provisioner with Terraform?

I am using Terraform 0.14 and AWS. I am trying to write a .tf file that will invoke a remote-exec command via Terraform's provisioner. This code does not work: resource "aws_instance" "...
Kamal S.'s user avatar
4 votes
2 answers
101 views

Are there automated quality checking tools for Ops code

In the dev world, we have several tools available to us for automated quality checks. We have unit tests that run on each build, Sonar to check for code quality, metrics being sent to Grafana and ...
Jolleyboy's user avatar
  • 143
4 votes
3 answers
3k views

How to enable Google Maps and generate an API key using Terraform?

I've been trying to spin up a project from scratch over the Christmas break to automate the creation of my home network, one of those components is the Ubiquiti Controller which requires a Google Maps ...
Richard Slater's user avatar
4 votes
2 answers
434 views

How to add ECS attributes to an instance using terraform

I heavily use ECS Attributes on our containerized infrastructure. I couldn't find terraform docs to achieve this. Do I need to execute aws cli commands manually to apply those attributes after ...
sithumc's user avatar
  • 272
4 votes
1 answer
4k views

Terraform apply exit code on error [closed]

I'm using Terraform as part of a Jenkins Pipeline. When terraform apply encounters an error, it does not return a non-zero exit code. When running into a problem on Jenkins, it does not stop the ...
Dan Mandle's user avatar
4 votes
1 answer
4k views

Mount Azure FileShare using terraform

What is a good way to mount an Azure File Storage automatically during provisioning on VMs? There is a Microsoft doc describing how a file share can be mounted in general. This requires that Azure ...
kap's user avatar
  • 141

1
2 3 4 5
7