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

Commit b98b93b

Browse files
Magicloudketzacoatl
authored andcommitted
Example single-node-asg-tester: Add Makefile/README
1 parent 1b5b03a commit b98b93b

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.PHONY: init ssh-key apply destroy clean
2+
3+
.DEFAULT_GOAL = help
4+
5+
## Runs terraform get and terraform init for env
6+
init:
7+
@terraform get
8+
@terraform init
9+
10+
## Create ssh key
11+
ssh-key:
12+
@ssh-keygen -q -N "" -C "SSH key for vpc-scenario-1 example" -f ./id_rsa
13+
14+
## use 'terraform apply' to apply the setup.
15+
apply:
16+
@terraform apply
17+
18+
## use 'terraform destroy' to remove all resources from AWS
19+
destroy:
20+
@terraform destroy
21+
22+
## rm -rf all files and state
23+
clean:
24+
@rm -f id_rsa
25+
@rm -f id_rsa.pub
26+
@rm -f terraform.*.backup
27+
@rm -f terraform.tfstate
28+
29+
## Show help screen.
30+
help:
31+
@echo "Please use \`make <target>' where <target> is one of\n\n"
32+
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
33+
helpMessage = match(lastLine, /^## (.*)/); \
34+
if (helpMessage) { \
35+
helpCommand = substr($$1, 0, index($$1, ":")-1); \
36+
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
37+
printf "%-30s %s\n", helpCommand, helpMessage; \
38+
} \
39+
} \
40+
{ lastLine = $$0 }' $(MAKEFILE_LIST)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# single node asg tester
2+
3+
This example shows the basic usage of `single-node-asg` module, especially the multiple EBS attachments.
4+
5+
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.
+18-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
provider "aws" {
2-
region = "ap-northeast-1"
3-
}
4-
51
locals {
62
cidr = "192.168.0.0/16"
73
private_subnet_cidrs = ["192.168.100.0/24", "192.168.101.0/24"]
84
public_subnet_cidrs = ["192.168.0.0/24", "192.168.1.0/24"]
5+
region = "ap-northeast-1"
96
}
107

11-
data "aws_vpc" "vpc" {
12-
cidr_block = local.cidr
13-
}
8+
data "aws_availability_zones" "azs" { }
149

15-
data "aws_subnet" "public" {
16-
count = length(local.public_subnet_cidrs)
17-
cidr_block = local.public_subnet_cidrs[count.index]
10+
module "vpc" {
11+
source = "fpco/foundation/aws//modules/vpc-scenario-2"
12+
cidr = local.cidr
13+
public_subnet_cidrs = local.public_subnet_cidrs
14+
private_subnet_cidrs = local.private_subnet_cidrs
15+
azs = data.aws_availability_zones.azs.names
16+
name_prefix = "test"
17+
region = local.region
1818
}
1919

2020
module "ubuntu" {
2121
source = "fpco/foundation/aws//modules/ami-ubuntu"
2222
}
2323

24+
resource "aws_key_pair" "main" {
25+
public_key = file("./id_rsa.pub")
26+
}
27+
2428
resource "aws_security_group" "ssh" {
25-
vpc_id = data.aws_vpc.vpc.id
29+
vpc_id = module.vpc.vpc_id
2630
ingress {
2731
from_port = 22
2832
to_port = 22
@@ -41,11 +45,11 @@ module "tester" {
4145
source = "../../modules/single-node-asg"
4246
name_prefix = "ebs"
4347
name_suffix = "test"
44-
key_name = "tokyo"
48+
key_name = aws_key_pair.main.key_name
4549
ami = module.ubuntu.id
4650
instance_type = "t2.micro"
47-
subnet_id = data.aws_subnet.public[0].id
51+
subnet_id = module.vpc.public_subnet_ids[0]
4852
security_group_ids = [aws_security_group.ssh.id]
49-
region = "ap-northeast-1"
53+
region = local.region
5054
data_volumes = [{ name = "a", device = "/dev/xvdm", size = 50 }, { name = "b", device = "/dev/xvdn" }]
5155
}

0 commit comments

Comments
 (0)