Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Example single-node-asg-tester: Add Makefile/README
Browse files Browse the repository at this point in the history
  • Loading branch information
Magicloud authored and ketzacoatl committed Jul 8, 2020
1 parent 1b5b03a commit b98b93b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
40 changes: 40 additions & 0 deletions examples/single-node-asg-tester/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.PHONY: init ssh-key apply destroy clean

.DEFAULT_GOAL = help

## Runs terraform get and terraform init for env
init:
@terraform get
@terraform init

## Create ssh key
ssh-key:
@ssh-keygen -q -N "" -C "SSH key for vpc-scenario-1 example" -f ./id_rsa

## use 'terraform apply' to apply the setup.
apply:
@terraform apply

## use 'terraform destroy' to remove all resources from AWS
destroy:
@terraform destroy

## rm -rf all files and state
clean:
@rm -f id_rsa
@rm -f id_rsa.pub
@rm -f terraform.*.backup
@rm -f terraform.tfstate

## Show help screen.
help:
@echo "Please use \`make <target>' where <target> is one of\n\n"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-30s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
5 changes: 5 additions & 0 deletions examples/single-node-asg-tester/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# single node asg tester

This example shows the basic usage of `single-node-asg` module, especially the multiple EBS attachments.

The module keeps one and only one instance up at all time. And the EBS volumes are reattached when a new instance is up. Hence they are always accessible.
32 changes: 18 additions & 14 deletions examples/single-node-asg-tester/main.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
provider "aws" {
region = "ap-northeast-1"
}

locals {
cidr = "192.168.0.0/16"
private_subnet_cidrs = ["192.168.100.0/24", "192.168.101.0/24"]
public_subnet_cidrs = ["192.168.0.0/24", "192.168.1.0/24"]
region = "ap-northeast-1"
}

data "aws_vpc" "vpc" {
cidr_block = local.cidr
}
data "aws_availability_zones" "azs" { }

data "aws_subnet" "public" {
count = length(local.public_subnet_cidrs)
cidr_block = local.public_subnet_cidrs[count.index]
module "vpc" {
source = "fpco/foundation/aws//modules/vpc-scenario-2"
cidr = local.cidr
public_subnet_cidrs = local.public_subnet_cidrs
private_subnet_cidrs = local.private_subnet_cidrs
azs = data.aws_availability_zones.azs.names
name_prefix = "test"
region = local.region
}

module "ubuntu" {
source = "fpco/foundation/aws//modules/ami-ubuntu"
}

resource "aws_key_pair" "main" {
public_key = file("./id_rsa.pub")
}

resource "aws_security_group" "ssh" {
vpc_id = data.aws_vpc.vpc.id
vpc_id = module.vpc.vpc_id
ingress {
from_port = 22
to_port = 22
Expand All @@ -41,11 +45,11 @@ module "tester" {
source = "../../modules/single-node-asg"
name_prefix = "ebs"
name_suffix = "test"
key_name = "tokyo"
key_name = aws_key_pair.main.key_name
ami = module.ubuntu.id
instance_type = "t2.micro"
subnet_id = data.aws_subnet.public[0].id
subnet_id = module.vpc.public_subnet_ids[0]
security_group_ids = [aws_security_group.ssh.id]
region = "ap-northeast-1"
region = local.region
data_volumes = [{ name = "a", device = "/dev/xvdm", size = 50 }, { name = "b", device = "/dev/xvdn" }]
}

0 comments on commit b98b93b

Please sign in to comment.