From 001486667402a4bd903679cf9a643dec80de80dd Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 25 May 2017 09:31:56 -0600 Subject: [PATCH] Clean up simple EC2 environment Remove hard-coded variables and move to `terraform.tfvars` for better portability. Rename variables file for greater consistency across environments. Add output to display IP address of spawned EC2 instance. Signed-off-by: Scott Lowe --- terraform/aws/simple-ec2/output.tf | 3 +++ terraform/aws/simple-ec2/provider.tf | 2 +- terraform/aws/simple-ec2/{vars.tf => variables.tf} | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 terraform/aws/simple-ec2/output.tf rename terraform/aws/simple-ec2/{vars.tf => variables.tf} (74%) diff --git a/terraform/aws/simple-ec2/output.tf b/terraform/aws/simple-ec2/output.tf new file mode 100644 index 0000000..68eca57 --- /dev/null +++ b/terraform/aws/simple-ec2/output.tf @@ -0,0 +1,3 @@ +output "instance_ip_address" { + value = "${aws_instance.test-01.public_ip}" +} diff --git a/terraform/aws/simple-ec2/provider.tf b/terraform/aws/simple-ec2/provider.tf index 0c28776..d7c130e 100644 --- a/terraform/aws/simple-ec2/provider.tf +++ b/terraform/aws/simple-ec2/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "us-west-2" + region = "${var.user_region}" } diff --git a/terraform/aws/simple-ec2/vars.tf b/terraform/aws/simple-ec2/variables.tf similarity index 74% rename from terraform/aws/simple-ec2/vars.tf rename to terraform/aws/simple-ec2/variables.tf index c5aa2ec..128b929 100644 --- a/terraform/aws/simple-ec2/vars.tf +++ b/terraform/aws/simple-ec2/variables.tf @@ -1,17 +1,19 @@ +variable "user_region" { + type = "string" + description = "AWS region in which to create all resources" +} + variable "keypair" { type = "string" description = "AWS SSH keypair to use to connect to instances" - default = "aws_rsa" } variable "flavor" { type = "string" description = "AWS type to use when creating instances" - default = "t2.micro" } variable "sec-group" { type = "string" description = "AWS security group to apply to instances" - default = "sg-7099b514" }