terraform-provider-aws

Run simple web server with Terraform remote-exec

拜拜、爱过 提交于 2019-12-23 18:54:37
问题 # example.tf provider "aws" { region = "us-east-1" } resource "aws_instance" "example" { ami = "ami-0d44833027c1a3297" instance_type = "t2.micro" security_groups = ["${aws_security_group.example.name}"] key_name = "${aws_key_pair.generated_key.key_name}" provisioner "remote-exec" { inline = [ "cd /home/ubuntu/", "nohup python3 -m http.server 8080 &", ] connection { type = "ssh" private_key = "${tls_private_key.example.private_key_pem}" user = "ubuntu" timeout = "1m" } } } resource "tls

Terraform - Upload file to S3 on every apply

ぃ、小莉子 提交于 2019-12-23 13:58:13
问题 I need to upload a folder to S3 Bucket. But when I apply for the first time. It just uploads. But I have two problems here: uploaded version outputs as null. I would expect some version_id like 1, 2, 3 When running terraform apply again, it says Apply complete! Resources: 0 added, 0 changed, 0 destroyed . I would expect to upload all the times when I run terraform apply and create a new version. What am I doing wrong? Here is my Terraform config: resource "aws_s3_bucket" "my_bucket" { bucket

Getting EC2 Windows Password from instances when using Terraform

与世无争的帅哥 提交于 2019-12-23 04:19:52
问题 I'm struggling to get the password from a couple of new ec2 instances when using terraform. Been reading up through a couple of posts and thought i had it but not getting anywhere. Here's my config: resource "aws_instance" "example" { ami = "ami-06f9d25508c9681c3" count = "2" instance_type = "t2.small" key_name = "mykey" vpc_security_group_ids =["sg-98d190fc","sg-0399f246d12812edb"] get_password_data = "true" } output "public_ip" { value = "${aws_instance.example.*.public_ip}" } output

Rename instead of delete resource?

隐身守侯 提交于 2019-12-21 08:46:53
问题 Is there any way to avoid resource deletion when reorganizing/renaming resources? Example: when I first implemented CloudFront Terraform it was an independent sub directory in my project, later I switched to using it as a module in. my root Terraform config but this caused Terraform to want to delete the old CloudFront distribution and create a new one: Terraform will perform the following actions: - aws_cloudfront_distribution.main_site_distribution + module.cloudfront.aws_cloudfront

Rename instead of delete resource?

旧时模样 提交于 2019-12-21 08:45:15
问题 Is there any way to avoid resource deletion when reorganizing/renaming resources? Example: when I first implemented CloudFront Terraform it was an independent sub directory in my project, later I switched to using it as a module in. my root Terraform config but this caused Terraform to want to delete the old CloudFront distribution and create a new one: Terraform will perform the following actions: - aws_cloudfront_distribution.main_site_distribution + module.cloudfront.aws_cloudfront

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

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 plan wants to destroy imported RDS resource

我们两清 提交于 2019-12-12 16:34:42
问题 I used the following commands to replace a previously deployed RDS instance with a manually configured RDS instance: ./terraform destroy -target aws_db_instance.my_db ./terraform import aws_db_instance.my_db my-rds-instance (Had to destroy the old instance before I could use import .) When I now run ./terraform plan , terraform wants to destroy and re-create the RDS db: -/+ aws_db_instance.my_db (new resource required) id: "my-rds-instance" => <computed> (forces new resource) address: "my-rds

Sharing resources between Terraform workspaces

只愿长相守 提交于 2019-12-12 08:27:03
问题 I have an infrastructure I'm deploying using Terraform in AWS. This infrastructure can be deployed to different environments, for which I'm using workspaces. Most of the components in the deployment should be created separately for each workspace, but I have several key components that I wish to be shared between them, primarily: IAM roles and permissions They should use the same API Gateway, but each workspace should deploy to different paths and methods For example: resource "aws_iam_role"

Using terraform modules for multiple regional api gateway

蹲街弑〆低调 提交于 2019-12-11 18:56:23
问题 I am using terraform to create aws infrastructure with 4 regional api gateways with corresponding dynamodb in that region. I want to create one module consisting of ( API + dynamo ) with configurable region specific values. Is it possible with terraform? Or I would have to create 4 separate API + 4 separate dynamodb resources. Any links or documentation would be helpful as well. Currently working for regional API gateway and corresponding dynamodb. variable "access_key" {} variable "secret