-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit - Application servers
- Loading branch information
0 parents
commit 4870dbe
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
|
||
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most | ||
# .tfvars files are managed as part of configuration and so should be included in | ||
# version control. | ||
# | ||
# example.tfvars | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Learn Terraform Cloud Run Triggers | ||
|
||
Learn what Terraform Cloud Run Triggers are and when to use them. | ||
|
||
Follow along with the [Learn guide](https://learn.hashicorp.com/terraform/cloud/run-triggers) at HashiCorp Learn. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<body> | ||
<main> | ||
<p>Hello, world!</p> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
data "terraform_remote_state" "vpc" { | ||
backend = "remote" | ||
|
||
config = { | ||
organization = var.tfc_org_name | ||
workspaces = { | ||
name = var.tfc_vpc_workspace_name | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
version = "~> 2.7" | ||
region = data.terraform_remote_state.vpc.outputs.aws_region | ||
} | ||
|
||
data "aws_ami" "amazon_linux" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "name" | ||
values = ["amzn2-ami-hvm-*-x86_64-gp2"] | ||
} | ||
|
||
owners = ["amazon"] | ||
} | ||
|
||
resource "aws_instance" "app" { | ||
count = var.instances_per_subnet * length(data.terraform_remote_state.vpc.outputs.private_subnet_ids) | ||
|
||
ami = aws_ami.amazon_linux.id | ||
instance_type = var.instance_type | ||
|
||
subnet_id = data.terraform_remote_state.vpc.outputs.private_subnet_ids[count.index % length(data.terraform_remote_state.vpc.outputs.private_subnet_ids)] | ||
|
||
user_data = <<EOF | ||
sudo yum update -y | ||
sudo yum install httpd -y | ||
sudo systemctl enable httpd | ||
sudo systemctl start httpd | ||
echo "<html><body><div>Hello, world!</div></body></html>" > /var/www/html/index.html | ||
EOF | ||
|
||
tags = { | ||
Project = data.terraform_remote_state.vpc.outputs.project_tag | ||
} | ||
} | ||
|
||
resource "aws_lb_target_group_attachment" "http" { | ||
count = length(aws_instance.app) | ||
|
||
target_group_arn = data.terraform_remote_state.vpc.outputs.lb_target_group_http_arn | ||
target_id = aws_instance.app[count.index].id | ||
port = 80 | ||
|
||
tags = { | ||
Project = data.terraform_remote_state.vpc.outputs.project_tag | ||
} | ||
} | ||
|
||
## HTTPS support requires an SSL certificate, which is out of scope for this | ||
## example. | ||
# | ||
# resource "aws_lb_target_group_attachment" "https" { | ||
# count = length(aws_instance.app) | ||
# | ||
# target_group_arn = data.terraform_remote_state.vpc.outputs.lb_target_group_https_arn | ||
# target_id = aws_instance.app[count.index].id | ||
# port = 443 | ||
# | ||
# tags = { | ||
# Project = data.terraform_remote_state.vpc.outputs.project_tag | ||
# } | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
output web_instance_count { | ||
value = len(aws_instance.app) | ||
} | ||
|
||
output public_dns_name { | ||
value = data.terraform_remote_state.vpc.outputs.public_dns_name | ||
} | ||
|
||
output aws_region { | ||
value = data.terraform_remote_state.vpc.outputs.aws_region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
variable tfc_org_name { | ||
description = "Name of the Terraform Cloud Organization" | ||
type = string | ||
default = "RunTriggersExampleOrg" | ||
} | ||
|
||
variable tfc_vpc_workspace_name { | ||
description = "Name of the Workspace" | ||
type = string | ||
default = "LearnTerraformRunTriggersVPC" | ||
} | ||
|
||
variable instances_per_subnet { | ||
description = "Number of EC2 instances in each private subnet" | ||
type = number | ||
default = 2 | ||
} | ||
|
||
variable instance_type { | ||
description = "Type of EC2 instance to use" | ||
type = string | ||
default = "t2.micro" | ||
} |