From 4d3fc568adb0d8c0bb8ef267b41733dbe2094298 Mon Sep 17 00:00:00 2001 From: Sathiya Shunmugasundaram Date: Tue, 9 Jun 2015 15:57:17 -0400 Subject: [PATCH 1/3] Initial commit aws-eip sample --- examples/aws-eip/README.md | 11 ++++++ examples/aws-eip/main.tf | 68 +++++++++++++++++++++++++++++++++++ examples/aws-eip/outputs.tf | 6 ++++ examples/aws-eip/userdata.sh | 3 ++ examples/aws-eip/variables.tf | 17 +++++++++ 5 files changed, 105 insertions(+) create mode 100644 examples/aws-eip/README.md create mode 100644 examples/aws-eip/main.tf create mode 100644 examples/aws-eip/outputs.tf create mode 100644 examples/aws-eip/userdata.sh create mode 100644 examples/aws-eip/variables.tf diff --git a/examples/aws-eip/README.md b/examples/aws-eip/README.md new file mode 100644 index 000000000..363c7f513 --- /dev/null +++ b/examples/aws-eip/README.md @@ -0,0 +1,11 @@ +# Elastic IP Example + +The eip example launches a web server, installs nginx. It also creates security group + +To run, configure your AWS provider as described in https://www.terraform.io/docs/providers/aws/index.html + +Running the example + +run `terraform apply -var 'key_name={your_key_name}}'` + +Give couple of mins for userdata to insatll nginx, and then type the Elastic IP from outputs in your browser and see tegh nginx welcome page diff --git a/examples/aws-eip/main.tf b/examples/aws-eip/main.tf new file mode 100644 index 000000000..7c4538670 --- /dev/null +++ b/examples/aws-eip/main.tf @@ -0,0 +1,68 @@ +# Specify the provider and access details +provider "aws" { + region = "${var.aws_region}" +} + +resource "aws_eip" "default" { + instance = "${aws_instance.web.id}" + vpc = true +} + +# Our default security group to access +# the instances over SSH and HTTP +resource "aws_security_group" "default" { + name = "eip_example" + description = "Used in the terraform" + + # SSH access from anywhere + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # HTTP access from anywhere + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # outbound internet access + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + + +resource "aws_instance" "web" { + instance_type = "t2.micro" + + # Lookup the correct AMI based on the region + # we specified + ami = "${lookup(var.aws_amis, var.aws_region)}" + + # The name of our SSH keypair you've created and downloaded + # from the AWS console. + # + # https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs: + # + key_name = "${var.key_name}" + + # Our Security group to allow HTTP and SSH access + security_groups = ["${aws_security_group.default.name}"] + + # We run a remote provisioner on the instance after creating it. + # In this case, we just install nginx and start it. By default, + # this should be on port 80 + user_data = "${file("userdata.sh")}" + #Instance tags + tags { + Name = "eip-example" + } +} \ No newline at end of file diff --git a/examples/aws-eip/outputs.tf b/examples/aws-eip/outputs.tf new file mode 100644 index 000000000..1660431b6 --- /dev/null +++ b/examples/aws-eip/outputs.tf @@ -0,0 +1,6 @@ +output "address" { + value = "${aws_instance.web.private_ip}" +} +output "elastic ip" { + value = "${aws_eip.default.public_ip}" +} diff --git a/examples/aws-eip/userdata.sh b/examples/aws-eip/userdata.sh new file mode 100644 index 000000000..1ec5a0027 --- /dev/null +++ b/examples/aws-eip/userdata.sh @@ -0,0 +1,3 @@ +#!/bin/bash -v +apt-get update -y +apt-get install -y nginx > /tmp/nginx.log \ No newline at end of file diff --git a/examples/aws-eip/variables.tf b/examples/aws-eip/variables.tf new file mode 100644 index 000000000..d1f0d0d6c --- /dev/null +++ b/examples/aws-eip/variables.tf @@ -0,0 +1,17 @@ +variable "aws_region" { + description = "The AWS region to create things in." + default = "us-east-1" +} + +# ubuntu-trusty-14.04 (x64) +variable "aws_amis" { + default = { + "us-east-1" = "ami-5f709f34" + "us-west-2" = "ami-7f675e4f" + } +} + +variable "key_name" { + description = "Name of the SSH keypair to use in AWS." +} + From 507c252b15833f9255278d09fbf26c95380289fd Mon Sep 17 00:00:00 2001 From: Sathiya Shunmugasundaram Date: Tue, 9 Jun 2015 16:17:59 -0400 Subject: [PATCH 2/3] Typo correction --- examples/aws-eip/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aws-eip/README.md b/examples/aws-eip/README.md index 363c7f513..7839f019c 100644 --- a/examples/aws-eip/README.md +++ b/examples/aws-eip/README.md @@ -8,4 +8,4 @@ Running the example run `terraform apply -var 'key_name={your_key_name}}'` -Give couple of mins for userdata to insatll nginx, and then type the Elastic IP from outputs in your browser and see tegh nginx welcome page +Give couple of mins for userdata to insatll nginx, and then type the Elastic IP from outputs in your browser and see the nginx welcome page From 6ec6d19add04b6f8f0aa67089a6594c850c11a34 Mon Sep 17 00:00:00 2001 From: Sathiya Shunmugasundaram Date: Tue, 9 Jun 2015 16:24:05 -0400 Subject: [PATCH 3/3] New line --- examples/aws-eip/main.tf | 3 ++- examples/aws-eip/userdata.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/aws-eip/main.tf b/examples/aws-eip/main.tf index 7c4538670..62757a6fe 100644 --- a/examples/aws-eip/main.tf +++ b/examples/aws-eip/main.tf @@ -65,4 +65,5 @@ resource "aws_instance" "web" { tags { Name = "eip-example" } -} \ No newline at end of file +} + diff --git a/examples/aws-eip/userdata.sh b/examples/aws-eip/userdata.sh index 1ec5a0027..8a058c786 100644 --- a/examples/aws-eip/userdata.sh +++ b/examples/aws-eip/userdata.sh @@ -1,3 +1,4 @@ #!/bin/bash -v apt-get update -y -apt-get install -y nginx > /tmp/nginx.log \ No newline at end of file +apt-get install -y nginx > /tmp/nginx.log +