terraform

How are data sources used in Terraform?

牧云@^-^@ 提交于 2019-12-21 07:12:12
问题 The Terraform Data Sources documentation tells me what a data source is, but I do not quite understand it. Can somebody give me a use case of data source? What is the difference between it and configuring something using variables? 回答1: Data sources can be used for a number of reasons; but their goal is to do something and then give you data . Let's take the example from their documentation: # Find the latest available AMI that is tagged with Component = web data "aws_ami" "web" { filter {

Terraform conditional block based on environment

冷暖自知 提交于 2019-12-20 16:54:23
问题 I'm looking at using the new conditionals in Terraform v0.11 to basically turn a config block on or off depending on the evnironment. Here's the block that I'd like to make into a conditional, if, for example I have a variable to turn on for production. access_logs { bucket = "my-bucket" prefix = "${var.environment_name}-alb" } I think I have the logic for checking the environment conditional, but I don't know how to stick the above configuration into the logic. "${var.environment_name ==

Use terraform to set up a lambda function triggered by a scheduled event source

浪子不回头ぞ 提交于 2019-12-20 08:34:21
问题 I would like to run an AWS lambda function every five minutes. In the AWS Management Console this is easy to set up, under the lambda function's "Event Sources" tab, but how do I set it up with Terraform? I tried to use an aws_lambda_event_source_mapping resource, but it turns out that the API it uses only supports events from Kinesis and DynamoDB. When I try to use it with a scheduled event source, creation times out. 回答1: You can use an aws_cloudwatch_event_target resource to tie the

Terraform: How to create multiple aws subnets from one resource block?

人盡茶涼 提交于 2019-12-19 12:00:32
问题 I'm trying to create multiple subnets from one resource block and I get the following error Error: aws_subnet.private: cidr_block must be a single value, not a list main.tf resource "aws_subnet" "private" { vpc_id = "${aws_vpc.vpcname.id}" cidr_block = "${var.private_subnet}" availability_zone = "${data.aws_availability_zones.available.names[count.index]}" map_public_ip_on_launch = false tags { Name = "${var.private}" Environment = "${terraform.workspace}" } } variable.tf variable "private

Terraform lambda source_code_hash update with same code

爷,独闯天下 提交于 2019-12-19 08:11:26
问题 I have an AWS Lambda deployed successfully with Terraform: resource "aws_lambda_function" "lambda" { filename = "dist/subscriber-lambda.zip" function_name = "test_get-code" role = <my_role> handler = "main.handler" timeout = 14 reserved_concurrent_executions = 50 memory_size = 128 runtime = "python3.6" tags = <my map of tags> source_code_hash = "${base64sha256(file("../modules/lambda/lambda-code/main.py"))}" kms_key_arn = <my_kms_arn> vpc_config { subnet_ids = <my_list_of_private_subnets>

Terraform combine 2 variables into a new variable

大兔子大兔子 提交于 2019-12-19 03:35:14
问题 I want to automate deployments of Vmware VM's in an landscape with lots of portgroups. To be able to select the correct portgroup it would be best to enter 2 variables tenant and environment. These 2 variables are used for CMDB registration and deployment purposes. For the deployment the variables need to be combined in to 1 new variable to pick the correct portgroup. Due to interpolation syntax it seems to be impossible to use 2 combined variables in the lookup. How can I combine 2 variables

Variance in attributes based on count.index in terraform

跟風遠走 提交于 2019-12-18 09:10:53
问题 I'm using Hashicorp terraform to create a MySQL cluster on AWS. I created a module named mysql and want to tag the first instance created as the master . However, per terraform documentation: Modules don't currently support the count parameter. How do I work around this problem? Currently, I have these in my files: $ cat project/main.tf module "mysql_cluster" { source = "./modules/mysql" cluster_role = "${count.index == "0" ? "master" : "slave"}" } $ cat project/modules/mysql/main.tf ..

Variance in attributes based on count.index in terraform

孤者浪人 提交于 2019-12-18 09:09:59
问题 I'm using Hashicorp terraform to create a MySQL cluster on AWS. I created a module named mysql and want to tag the first instance created as the master . However, per terraform documentation: Modules don't currently support the count parameter. How do I work around this problem? Currently, I have these in my files: $ cat project/main.tf module "mysql_cluster" { source = "./modules/mysql" cluster_role = "${count.index == "0" ? "master" : "slave"}" } $ cat project/modules/mysql/main.tf ..

Terraform ELB S3 Permissions Issue

我的未来我决定 提交于 2019-12-18 03:58:12
问题 I am having an issue using Terraform (v0.9.2) adding services to an ELB (I'm using: https://github.com/segmentio/stack/blob/master/s3-logs/main.tf). When I run terraform apply I get this error: * module.solr.module.elb.aws_elb.main: 1 error(s) occurred: * aws_elb.main: Failure configuring ELB attributes: InvalidConfigurationRequest: Access Denied for bucket: my-service- logs. Please check S3bucket permission status code: 409, request id: xxxxxxxxxx-xxxx-xxxx-xxxxxxxxx My service looks like

Connection timeout during file provision to azurerm vm

痞子三分冷 提交于 2019-12-14 03:09:30
问题 I am getting below timeout message once trying to provision file to an azure RM VM . unknown error Post http://terraform.eastus.cloudapp.azure.com:3389/wsman: read tcp 192.168.0.4:59745->52.224.162.240:3389: wsarecv: An existing connection was forcibly closed by the remote host. I am trying file provision and the VM already there and no need to create it. I only need to copy a text file to an existing VM using below config. provider "azurerm" { } resource "null_resource" "test" { provisioner