Questions tagged [terraform-template-file]

240 questions
33
votes
5 answers

How do I run terraform init from a different folder?

I want to script terraform for CI/CD purpose and I don't like CDing in scripts, I rather have specific paths. I tried terraform init c:\my\folder\containing\tf-file But running that puts the .terraform folder in my cwd.
red888
  • 27,709
  • 55
  • 204
  • 392
26
votes
6 answers

terraform copy/upload files to aws ec2 instance

We have cronjob and shell script which we want to copy or upload to aws ec2 instance while creating instance using terraform. we tried file provisioner : but its not wokring , and read this option does not work with all terraform version …
pratik
  • 733
  • 1
  • 8
  • 11
21
votes
3 answers

adding extra element to a list in terraform if condition is met

I have a list in terraform that looks something like: array = ["a","b","c"] Within this terraform file there are two variables called age and gender, and I want to make it so that the list called array has an extra element called "d" if age is…
Sabo Boz
  • 1,683
  • 4
  • 13
  • 29
15
votes
6 answers

terraform-kubernetes-provider how to create secret from file?

I'm using the terraform kubernetes-provider and I'd like to translate something like this kubectl command into TF: kubectl create secret generic my-secret --from-file mysecret.json It seems, however the secret resource's data field expects only a…
Davis Ford
  • 147
  • 1
  • 1
  • 4
15
votes
2 answers

How do you create an archive file in Terraform?

I have this code in terraform: data "archive_file" "lambdazip" { type = "zip" output_path = "lambda_launcher.zip" source_dir = "lambda/etc" source_dir = "lambda/node_modules" source { content =…
Know Nothing
  • 1,121
  • 2
  • 10
  • 21
14
votes
1 answer

using count.index in terraform?

I am trying to generate a bunch of files from templates. I need to replace the hardcoded 1 with the count.index, not sure what format terraform will allow me to use. resource "local_file" "foo" { count = "${length(var.files)}" content =…
user2062360
  • 1,323
  • 5
  • 16
  • 29
13
votes
2 answers

Check if variable exists - Terraform template syntax

I'm trying to check if a variable exists on a template file using terraform template syntax, but I get error that This object does not have an attribute named "proxy_set_header. $ cat nginx.conf.tmpl %{ for location in jsondecode(locations)…
Cae Vecchi
  • 868
  • 1
  • 10
  • 19
10
votes
2 answers

How to avoid cycle error when setting an S3 bucket policy with a template that depends on the bucket name?

I have a terraform file which fails when I run terraform plan and I get the error: Error: Cycle: module.hosting.data.template_file.bucket_policy, module.hosting.aws_s3_bucket.website It makes sense since the bucket refers to the policy and vice…
8
votes
2 answers

How to pass multiple template files to user_Data variable in terraform

assign multiple templates files to user_Data variable. we dont want to merge this template in single file due to some architectural pattern . I'm new to terraform so struggling on this. data "template_file" "userdata_lin1" { template =…
8
votes
3 answers

Is it possible to reuse Terraform templates for different resources providing different values for variables?

I am using Terraform to setup multiple droplets running Consul on DigitalOcean. Perhaps I am missing something basic, but it seems surprisingly difficult to provide right configuration for them. resource "digitalocean_droplet" "prime" { count =…
Tad Lispy
  • 2,806
  • 3
  • 30
  • 31
7
votes
2 answers

Want to deploy a storage bucket with public readable storage object permission in GCP using terraform

I created a terraform file to create a Google Storage bucket with public readable Storage object permission. I am able to deploy the Storage bucket but can't assign the proper ACL against my template, I found some errors for ACL part. provider…
7
votes
3 answers

Commands in user_data are not executed in terraform

Hi EC2 instance is created, but commands as part of userdata.sh are not gettingexecuted. When I manually connect to EC2 via putty, i found that nginx is not installed in EC2 instance. To verify if the script is getting executed or not I added echo…
Smi
  • 183
  • 1
  • 4
  • 12
6
votes
2 answers

Layered deployments with Terraform

I am new to Terraform so not even sure something like this is possible. As an example, lets say I have a template that deploys an Azure resource group and a key vault in it. And then lets say I have another template that deploys a virtual machine…
5
votes
3 answers

Properly using Terraform External Data Source

I am using Terraform from the bash cloud shell in Azure. I am trying to add an external data source to my Terraform configuration file that will use az cli to query for the virtualip object on a Microsoft.Web/hostingEnvironment the template…
4
votes
1 answer

How can i set a count in for_each in terraform

I'm learning terraform by building a template to create my infrastructure in the hetzner cloud. For this purpose I'm using the hcloud provider. I create a map variable hosts to create >1 server with different configuration. variable "hosts" { …
sokolata
  • 491
  • 3
  • 7
  • 21
1
2 3
15 16