terraform

Terraform decouple Security Group dependency

我是研究僧i 提交于 2020-01-25 06:49:47
问题 This is tested with Terraform v0.12.9 I generally manage security groups and security group rules as separate resources, as in the below example: resource "aws_security_group" "this" { count = var.create ? 1 : 0 name_prefix = "${var.security_group_name}_" vpc_id = var.vpc_id lifecycle { create_before_destroy = true } } resource "aws_security_group_rule" "ingress_rules" { count = var.create ? length(var.inbound_security_group_ids) : 0 security_group_id = aws_security_group.this[0].id type =

Terraform: How to conditionally assign an EBS volume to an ECS Cluster

我是研究僧i 提交于 2020-01-24 10:29:34
问题 I have an ecs_cluster module which defines an ECS cluster. I want the module to be re-usable so I can create various clusters with different configurations. Hence I want to be able to optionally specify whether to create and attach an EBS volume in the launch configuration of the ECS hosts. I initially tried using count in the ebs_block_device inside the launch configuration e.g. variable "ebs_volume_device_name" { type = "string", default = "" } variable "ebs_volume_type" { type = "string",

Commands in user_data are not executed in terraform

和自甴很熟 提交于 2020-01-23 06:55:47
问题 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 message, but no output is display in command prompt when i run terraform apply. How can i verify if the user-data is getting executed or not? I have installed Terraform in C drive and below script are present in same folder C:/Terraform/userdata.sh,

Terraform creating VM from managed disk image made in Packer

情到浓时终转凉″ 提交于 2020-01-21 18:39:49
问题 I have created a custom VM image using Packer, and now I am trying to create a new VM based on this image using Terraform, but I am confused on how I need to set up my .TF file . I can create the rest of the infrastructure okay. I think my packer json file created a managed disk image but I am unsure how to set this up and cannot find an example online. I am quite new to infraastructure as code and the Azure ecco system in general main.tf resource "azurerm_managed_disk" "managedDisk" { name =

how can I get the relative path of the current director up to an arbitrary parent dir?

不问归期 提交于 2020-01-16 08:58:32
问题 this is not a module just a workspace folder structure: workspace1 - workspace2 - workspace3 - workspace4 - workspace5 If I CD into workspace for the full path is: /Users/me/my-files/terraform/workspace1/workspace3/workspace4 How can I use terraform functions to be able to get just the path workspace1/workspace3/workspace4 Is there a way I can get the full path (https://www.terraform.io/docs/configuration/functions/abspath.html) and then trim out everything before workspace1? perhaps replace(

InvalidClientTokenID error when running Terraform Plan/Apply

假装没事ソ 提交于 2020-01-16 01:47:33
问题 I'm setting up a HA cluster in AWS using Terraform and user data. My main.tf looks like this: provider "aws" { access_key = "access_key" secret_key = "secret_key" } resource "aws_instance" "etcd" { ami = "${var.ami}" // coreOS 17508 instance_type = "${var.instance_type}" key_name = "${var.key_name}" key_path = "${var.key_path}" count = "${var.count}" region = "${var.aws_region}" user_data = "${file("cloud-config.yml")}" subnet_id = "${aws_subnet.k8s.id}" private_ip = "${cidrhost("10.43.0.0/16

Terraform provisioned IAM user created with IAM Console access disabled

时光毁灭记忆、已成空白 提交于 2020-01-15 11:36:27
问题 I'm generating credentials via keybase.io PGP in my Terraform config. I can confirm access via aws-cli is successful for the new user. However, Console access remains disabled. Is there a way to create a user with Terraform with the console access enabled? I appreciate that's a bit of an anti-pattern for Terraform, but I'd like my new user to be able to log in to the Console UI to validate/debug. UPDATE 1 Terraform module: https://registry.terraform.io/modules/terraform-aws-modules/iam/aws/0

Accept user Input os.stdin to container using Golang docker SDK - Interactive Container

亡梦爱人 提交于 2020-01-15 07:27:09
问题 My last resort is asking here. I'm new to Golang and I've made simple programs. I'm trying to do the following: Using golang: 1 - run a container 2 - accept input stdin to the container The example I want to use is the hashicorp/terraform docker image, I want to do a simple terraform apply but I need to wait for user input below is the code I have working so far...anyone trying the exact code below needs to update the AWS environment variables or change the terraform test file to another

declare a variable using `execute` Interpolation in Terraform

∥☆過路亽.° 提交于 2020-01-15 07:08:42
问题 I want to declare a a sub-string of a variable to another variable. I tested taking a sub-string using terraform console. > echo 'element(split (".", "10.250.3.0/24"), 2)' | terraform console > 3 my subnet is 10.250.3.0/24 and I want my virtual machine to get private IP address within this subnet mask 10.250.3.6. I want this to get automatically assign by looking at subnet address. What I've tried; test.tf variable subnet { type = "string" default = "10.250.3.0/24" description = "subnet mask

declare a variable using `execute` Interpolation in Terraform

江枫思渺然 提交于 2020-01-15 07:04:12
问题 I want to declare a a sub-string of a variable to another variable. I tested taking a sub-string using terraform console. > echo 'element(split (".", "10.250.3.0/24"), 2)' | terraform console > 3 my subnet is 10.250.3.0/24 and I want my virtual machine to get private IP address within this subnet mask 10.250.3.6. I want this to get automatically assign by looking at subnet address. What I've tried; test.tf variable subnet { type = "string" default = "10.250.3.0/24" description = "subnet mask