terraform

Marshal dynamic JSON field tags in Go

南楼画角 提交于 2019-12-14 02:37:00
问题 I'm trying to generate JSON for a Terraform file. Because I (think I) want to use marshalling instead of rolling my own JSON, I'm using Terraforms JSON format instead of the 'native' TF format. { "resource": [ { "aws_instance": { "web1": { "some": "data" } }] } resource and aws_instance are static identifiers while web1 in this case is the random name. Also it wouldn't be unthinkable to also have web2 and web3 . type Resource struct { AwsResource AwsResource `json:"aws_instance,omitempty"` }

terraform use count index in module [duplicate]

别来无恙 提交于 2019-12-13 23:37:51
问题 This question already has answers here : Variance in attributes based on count.index in terraform (2 answers) Closed 7 months ago . I want to use the count.index in the terraform module for my aws ec2 instance to name the instance in increment order file: ec2/main.tf resource "aws_instance" "instance"{ ami = "ami-xxx" tags { Name = "var.instance" } count = "var.count" } file: ec2instance.tf module "ec2"{ source = "./ec2" count = 3 instance_name = "firsttypeinstance-${count.index+1}" } module

Creating Filebeat configuration with Terraform

☆樱花仙子☆ 提交于 2019-12-13 17:25:26
问题 I am trying to create a Filebeat configuration file after creating a instance with Terraform: resource "local_file" "greylogIP" { content = <<EOF filebeat.inputs: - type: log enabled: false paths: - /var/log/*.log filebeat.config.modules: path: '$'{path.config}/modules.d/*.yml reload.enabled: false setup.template.settings: index.number_of_shards: 3 output.logstash: hosts: ["${aws_instance.web.public_ip}:5014"] EOF filename = "filebeat.conf" } where I need to pass the ${aws_instance.web.public

Create AWS Athena view programmatically

强颜欢笑 提交于 2019-12-13 11:46:37
问题 Can you create views in Amazon Athena? outlines how to create a view using the User Interface. I'd like to create an AWS Athena View programatically, ideally using Terraform (which calls CloudFormation). I followed the steps outlined here: https://ujjwalbhardwaj.me/post/create-virtual-views-with-aws-glue-and-query-them-using-athena, however I run into an issue with this in that the view goes stale quickly. ...._view' is stale; it must be re-created. The terraform code looks like this:

Terraform | Retrieve the (client-key) certificate from Cloud SQL

大城市里の小女人 提交于 2019-12-13 08:29:51
问题 I would like to retrieve the client-key SSL key of cloudsql via Terraform, I was able to retrieve the server-ca and the client-cert via terraform but have no idea how to get the client-key file. TO retrieve the client-cert I have used the below mentioned point: Please look. resource "google_sql_ssl_cert" "client_cert" { depends_on = ["google_sql_database_instance.new_instance_sql_master", "google_sql_user.users"] common_name = "terraform1" project = "${var.project_id}" instance ="${google_sql

How to fix “rsadecrypt: argument 1 should be type string, got type list in:”

心已入冬 提交于 2019-12-13 03:45:15
问题 At the beginning I want to build just one windows machine, so this code works fine at the beginning: output "Administrator_Password" { value = "${rsadecrypt(aws_instance.new_instance.password_data, file("${module.ssh_key_pair.private_key_filename}"))}" } But once I introduce count to resource "aws_instance" "new_instance" { , I have to add * to the expression aws_instance.new_instance.*.password_data . But then I start to get this error: Error: Error running plan: 1 error(s) occurred: *

How to Rollback to Previous State in terraform

天大地大妈咪最大 提交于 2019-12-13 03:07:37
问题 I am working on terraform tasks and trying to understand how state files work. I have created main.tf file which has vpc,firewall,subnet,compute_instance which has to be create in GCP. So i have applied this to GCP environment and a file name terraform.tfstate file got created and i did backup of this file into folder called 1st-run. Now i have updated my main.tf with 2vpc,2firewalls,2subnets,compute_instance as i need to add another nic for my vm.Did terraform apply and environment got

Does terraform support math rounding?

China☆狼群 提交于 2019-12-13 00:42:04
问题 Is it possible to round an integer value in terraform string interpolations? 回答1: It's a bit of a hack and doesn't use terraform string interpolations but.. You can do this with the external data source (https://www.terraform.io/docs/providers/external/data_source.html) by delegating it to another program. The example I've included uses bash and jq. However you could probably achieve this without jq. Terraform: data external "rounder" { program = ["bash", "${path.module}/round.sh"] query {

Error Importing existing resources into Terraform State File

白昼怎懂夜的黑 提交于 2019-12-12 23:59:54
问题 I am attempting to refactor some of my modules, which requires me to move existing resources into a different state file. Normally importing resources is monotonous but straightforward. I do not know how to interpret the following "The number of path segments is not divisible by 2" error when attempting to import any of these resources. This is happening on all resources I am attempting to import (which I have successfully done many times in the past) CLI> terraform import azurerm_virtual

Terraform: How to create named_port after google_container_cluster resource?

二次信任 提交于 2019-12-12 20:33:31
问题 I created a google_container_cluster ... resource "google_container_cluster" "primary" { name = "primary" # rest of the config ... } ... and now want to add a named_port to the managed instance group that is created on the fly by the google cloud platform. The google_container_cluster resource returns instance_group_urls. But I don't know how to use this output in order to create a named port. 回答1: This is not clear from your question, but I'm presuming you're using Google Container Engine