Questions tagged [terraform]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
377 views

Terraform conditionally create VPC

I am in the process of creating a terraform template, part of which can create a VPC. The user has the option to specify the parameter create-vpc. This will be passed to the module https://github.com/...
3
votes
2answers
3k 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 "...
4
votes
3answers
3k 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 ...
6
votes
3answers
4k 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: ...
2
votes
1answer
45 views

Referencing locally built Docker images in Terraform

Is it possible to use docker images in Terraform that are not hosted in a registry but in the local Docker storage? I'd like to have a resource like the following where no pull is performed on the ...
1
vote
1answer
91 views

Terraform and Kubernetes' StorageClass with node affinity

Im able to make a number of kubernetes constructs in terraform and even have done so for my ephemeral stateful data that requires low latency disk performance. I can terraform up a ...
2
votes
2answers
2k views

How to get VPC id in Terraform module?

I have a module structure like module "vpc" { source = "./modules/vpc" } module "prod_subnets" { source = "./modules/vpc/modules/subnets/production" } when running am getting an error like [0m on ...
3
votes
1answer
127 views

Creating ec2 instances and installing mongoDB using automation

I am trying to create a 3 node MongoDB replica set using automation (ansible or terraform) in AWS. I am able to do this in the management console of AWS, but I'm not sure how to approach it. ...
2
votes
1answer
25 views

Is it possible to create a module that either creates a resource or sources a data source, based on a boolean value?

Basically, what I'd like to do is create a module that does this pseudocode: if <boolean> then resource "<resource type>" "name" { # ... set variables ... } else { data "<...
1
vote
1answer
1k views

Terraform error Reference to “count” in non-counted context for resources not necessarily data

here's my part of my code that I am having issues with. Unfortunately I could not understand the relationship between the last answer, despite being almost what I need, and my situation. data "...
2
votes
2answers
247 views

Terraform - how to modify a existing S3 bucket that was created from module?

I already have my S3 bucket called foo-name created and existing with terraform. I want to modify the existing s3 bucket and a policy. But when I do this it seems to want to add a new s3 bucket ...
1
vote
1answer
752 views

Correct way to handle 'optional' array of resources in Terraform

In one of our our Terraform modules we have a variable to optionally create a load balancer. As part of this we create some subnets thusly: resource "aws_subnet" "subnet_loadbalancer" { count = var....
1
vote
1answer
340 views

Error when creating new recource using backend AWS s3 [closed]

When I try create a new resource using terraform apply (Terraform init was success) received an error: data.terraform_remote_state.environment_data: Refreshing state... Error: Unable to find remote ...
2
votes
2answers
40 views

Terraform's local state (the 2 tfstate files) contain very sensitive info

Part of my IaC that describes my systems for Azure is CosmosDB, and Keyvaults. Terraform happily created everything and I was able to use an output from CosmosDB (db keys) as an input to the Keyvault ...
2
votes
1answer
519 views

Terraform: can't connect to AWS provider using shared config file or static variable

I'm trying to use terraform to manage AWS resources and trying to set up the credentials configuration. I'm following the official documentation: https://www.terraform.io/docs/providers/aws/index.html ...
0
votes
1answer
60 views

validation block iteratively

This validation block works for a single input variable. variable "mytestname" { validation { condition = length(regexall("test$", var.mytestname)) > 0 error_message = "...
4
votes
2answers
752 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,...
1
vote
1answer
255 views

AWS launch template create-before-destory?

In terraform, to reduce downtime when creating a new auto-scaling-group behind an existing load balancer, you can use a launch configuration and set create-before-destroy. Launch templates are the ...
2
votes
1answer
109 views

Cloud agnostic infrastructure automation better than terraform?

Are there any infrastructure automation technologies which do a better job at being portable than terraform? We heavily leverage terraform as it is a cloud-agnostic technology (vs, say, ARM templates ...
3
votes
1answer
964 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 ...
2
votes
1answer
732 views

Terraform 0.12 - For each subnet-id in array, get cidr_block

I have a list of subnets IDs and I want to get an array of the cidr_blocks associated to each subnet. variable "aws_subnet_ids" { type = list(string) default = ["subnet-aaaaaaaa","subnet-bbbbbbbb"...
0
votes
3answers
732 views

How to send local files using Terraform Cloud as remote backend?

I am creating AWS EC2 instance and I am using Terraform Cloud as backend. in ./main.tf: terraform { required_version = "~> 0.12" backend "remote" { hostname = "app.terraform.io" ...
1
vote
1answer
2k views

How to create dependency between modules in terraform

I have 2 modules A and B. I want a particular resource in module B to be created only after a particular resource in module A is completed completely. I was trying to achieve just that with this as ...
1
vote
1answer
52 views

Calling a Terraform object in seperate folder

I need to reference my VNET Gateway residing in an infrastructure folder, in a VPN folder in order to connect a VPN utilising a Local Network Gateway, but these could be any object in Azure for the ...
3
votes
2answers
154 views

What is the most used tool for Cloud Infrastructure deployment Ansible vs Puppet vs Terraform?

I have some time for research at work right now, and I was thinking on expanding my knowledge on my favorite subject, which is DevOps (love you all). I have some advanced experience with Ansible, as ...
1
vote
1answer
29 views

Importing non-default workspaces in Terraform

I'm having a bit of trouble with Terraform. I have a Terraform project which is shared by a few developers and uses non-default workspaces (i.e. named workspaces, not the default one). I would like ...
0
votes
1answer
199 views

Why does my Terraform config require variables in multiple places?

My folder hierarchy looks like this: / -> live/ : main.tf : variables.tf -> modules/ -> logs/ : logs.tf : variables.tf In my main.tf I have: module "logs" { ...
0
votes
2answers
104 views

How can I find out when Terraform will support newly released AWS services?

For example, AWS announced their new "RDS Proxy" service at re:Invent 2019 and it is now in preview. How can I find out when/if Terraform will support this (for planning purposes)? https://aws.amazon....
2
votes
2answers
1k views

How to create databases, users and grants with terraform mysql and output the created credentials?

For a new deployment I want to create databases, users and grants on a previous created MySQL database on azure. The following code used inside a module creates the environment as expected and I ...
2
votes
1answer
37 views

Having some trouble getting service running with Docker and Terraform

I'm very new to DevOps but I'm trying to learn some of it a bit. I'm working with Terraform, trying to get a service to run on AWS using Fargate and Docker. I've successfully set up my ECR ...
1
vote
1answer
1k views

How to set Terraform Cloud environment variables from the command line?

Terraform Cloud is a SaaS platform for managing Terraform runs, state and variables. Once you have created a project you can set environment variables via the following page: https://app.terraform....
0
votes
1answer
114 views

Unable to understand the logic behind this terraform function

So i was going through a code of some one else and just could not make sense of it,, if may be some can of this, "${replace(jsonencode(list(local.cadvisor_container_definition)), "/\"(\\d{2,5}|true|...
0
votes
1answer
308 views

Use Terraform to manage ssh-keys in GCE

I use Terrafrom and manage access to VMs in GCE by changing VM metadata. Before I put it to string, but it not good, so I try to put them to variable and use it. But I faced problem. This is my code: ...
1
vote
2answers
96 views

how long does it take to deploy a serverless function?

using any method - cli, serverless.com, terraform, roughly: how much time can i expect to pass between these two steps: submitting a new function to AWS (or azure or GCF), and having that function ...
0
votes
1answer
62 views

Where do I use Ansible and where is Terraform used? ( Strengths & Weaknesses) [closed]

What is Ansible mainly used for? Where do I use Terraform? This question focusses on where the tools have relative strengths or weaknesses. For example: Ansible for VM build and Software ...
2
votes
1answer
5k 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
1
vote
1answer
1k views

Terraform creating single SG but multiple CIDR blocks

I am trying to use Terraform to create a single security group that will allow traffic for mongo on port 27017 from all my private subnets that are stored in a variable. My issue is I am unsure how ...
1
vote
2answers
122 views

Given a blank slate, tool recommendations? [closed]

so I have 8 months of DevOps experience previously working as a desktop engineer for two and a half years.Starting a new role in the education sector, recently they brought their IT department which ...
3
votes
1answer
2k views

How to specify specific subnet in Terraform when using for each

I am trying to create an ec2 instance that will hold my Jenkins server. I want this to be in a private subnet which I created using a for each loop. Below is my subnet for each loop and my ec2 ...
1
vote
1answer
1k views

Module directory modules/queues.tf does not exist or cannot be read

I am trying to setup terraform with modules and when doing terraform init after creating a module I have ran into an issue where I am told it does not exist or can't be read. I've checked many times ...
1
vote
1answer
314 views

How can I enable active tracing by default for an AWS Lambda function using Terraform?

On the console, there’s the option to enable active tracking for X-ray tracking but I can see this in the Terraform aws_lambda_function resource the aws_xray_sampling_rule resources? I'm currently ...
3
votes
1answer
24 views

Provisioning a server on behalf of a user on GCP/AWS/Azure and probably relinquish access

I'd like to build a service where I run a custom setup script on behalf of a user on an t2.micro equivalent instance but be able to probably relinquish access to the server. Any advice on the tech ...
1
vote
1answer
739 views

How do I create multiple versions of a lambda function in terraform

I have it creating one version. It has latest and version 2 but can’t getting it to create more than one version of the same lambda? resource "aws_lambda_function" "lambda" { function_name = "test-...
5
votes
0answers
82 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 ...
0
votes
1answer
26 views

Can Terraform pull down the newest state file by itself?

We started using Terraform to create VMs in some Cloud Providers. But we are a team with several people. Terraform has a state file. Whenever someone changes something via Terraform, ex.: ...
1
vote
1answer
42 views

can't access my instances by public IP in a VPC (aka: what is wrong with my terraform)?

As stated in the title of the question, I have a Terraform file (attached below), but the infrastructure it builds doesn't allow me to connect by SSH (I get "Connection timed out"). So either the ...
1
vote
1answer
281 views

How do I use only an encrypted version of my AWS RDS password in my terraform code?

Is there a way to only have an encrypted version of my RDS password in my Terraform code and for AWS to decrypt it for RDS so you use the decrypted password to login to the RDS? So set my rds ...
0
votes
1answer
1k views

Terraform | Error “transport is closing” when “terraform apply” after upgrading to 0.12

Terraform v0.12.7 + provider.aws v2.25.0 + provider.null v2.1.2 + provider.template v2.1.2 Hello, when I try run terraform apply after upgrading to 0.12 I get error: module.elasticsearch.module.ec2....
1
vote
1answer
845 views

Create multiple S3 buckets at once

I am trying to create a static website using S3 buckets. I want to create a bucket for www and non-www versions. I can't work out how to create two buckets at once. I read that you can chain two ...
2
votes
1answer
3k views

Terraform | After upgrading to 0.12 receive a lots of error “unsupported value for ”%s“ at 0: string required.”

After upgrading to 0.12 I receive a lots of error like: Error: Error in function call on main.tf line 136, in data "template_file" "inventory": 136: formatlist( 137: 138: 139: 140: |...