added vars for command line
parent
409ad19b4f
commit
24f1d015ea
|
|
@ -4,10 +4,7 @@ Launches EC2 instance, creates private key, and saves it on the machine.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
wait for it
|
terraform apply -var="instance_type=t2.nano" -var="instance_name=k3s-box" -var="instance_ami=ami-0889a44b331db0194" -var="availability_zone=us-east-1a" -var="create_ebs_block_device=false" - var="enable_ingress_http=false" -auto-approve
|
||||||
```
|
```
|
||||||
|
|
||||||
Help:
|
Defaults of vars are set to the ones provided in "Usage"
|
||||||
```
|
|
||||||
wait for it
|
|
||||||
```
|
|
||||||
74
ec2.tf
74
ec2.tf
|
|
@ -1,21 +1,51 @@
|
||||||
|
variable "instance_type" {
|
||||||
|
type = string
|
||||||
|
default = "t2.nano"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_name" {
|
||||||
|
type = string
|
||||||
|
default = "k3s-box"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_ami" {
|
||||||
|
type = string
|
||||||
|
default = "ami-0889a44b331db0194" # amazon linux us-east-1
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "availability_zone" {
|
||||||
|
type = string
|
||||||
|
default = "us-east-1a"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "create_ebs_block_device" {
|
||||||
|
type = bool
|
||||||
|
default = false
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "enable_ingress_http" {
|
||||||
|
type = bool
|
||||||
|
default = false
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_instance" "k3s_box" {
|
resource "aws_instance" "k3s_box" {
|
||||||
ami = "ami-0889a44b331db0194" # amazon linux us-east-1
|
ami = var.instance_ami
|
||||||
instance_type = "t3.small"
|
instance_type = var.instance_type
|
||||||
associate_public_ip_address = true
|
associate_public_ip_address = true
|
||||||
key_name = aws_key_pair.k3s_box_kp.key_name
|
key_name = aws_key_pair.k3s_box_kp.key_name
|
||||||
|
|
||||||
ebs_block_device {
|
ebs_block_device {
|
||||||
device_name = "/dev/sdx"
|
device_name = "/dev/sdx"
|
||||||
|
|
||||||
volume_size = 10
|
volume_size = 10
|
||||||
volume_type = "gp2"
|
volume_type = "gp2"
|
||||||
delete_on_termination = true
|
delete_on_termination = true
|
||||||
|
count = var.create_ebs_block_device ? 1 : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
user_data = "${file("./script.sh")}"
|
user_data = "${file("./script.sh")}"
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Name = "k3s-box"
|
Name = var.instance_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +60,7 @@ resource "aws_vpc" "k3s_box_vpc" {
|
||||||
resource "aws_subnet" "k3s_box_public_subnet" {
|
resource "aws_subnet" "k3s_box_public_subnet" {
|
||||||
vpc_id = aws_vpc.k3s_box_vpc.id
|
vpc_id = aws_vpc.k3s_box_vpc.id
|
||||||
cidr_block = "10.0.1.0/24"
|
cidr_block = "10.0.1.0/24"
|
||||||
availability_zone = "us-east-1a"
|
availability_zone = var.availability_zone
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Name = "k3s-box-public-subnet"
|
Name = "k3s-box-public-subnet"
|
||||||
|
|
@ -40,7 +70,7 @@ resource "aws_subnet" "k3s_box_public_subnet" {
|
||||||
resource "aws_subnet" "k3s_box_private_subnet" {
|
resource "aws_subnet" "k3s_box_private_subnet" {
|
||||||
vpc_id = aws_vpc.k3s_box_vpc.id
|
vpc_id = aws_vpc.k3s_box_vpc.id
|
||||||
cidr_block = "10.0.2.0/24"
|
cidr_block = "10.0.2.0/24"
|
||||||
availability_zone = "us-east-1a"
|
availability_zone = var.availability_zone
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Name = "k3s-box-private-subnet"
|
Name = "k3s-box-private-subnet"
|
||||||
|
|
@ -93,23 +123,23 @@ resource "aws_security_group" "k3s_box_sg" {
|
||||||
}
|
}
|
||||||
|
|
||||||
# ALLOWS HTTPS and HTTP from anywhere
|
# ALLOWS HTTPS and HTTP from anywhere
|
||||||
# ingress {
|
ingress {
|
||||||
# description = "HTTPS"
|
description = "HTTPS"
|
||||||
# from_port = 443
|
from_port = 443
|
||||||
# to_port = 443
|
to_port = 443
|
||||||
# protocol = "tcp"
|
protocol = "tcp"
|
||||||
# cidr_blocks = ["0.0.0.0/0"]
|
cidr_blocks = var.enable_ingress_http ? ["0.0.0.0/0"] : []
|
||||||
# ipv6_cidr_blocks = ["::/0"]
|
ipv6_cidr_blocks = var.enable_ingress_http ? ["::/0"] : []
|
||||||
# }
|
}
|
||||||
|
|
||||||
# ingress {
|
ingress {
|
||||||
# description = "HTTP"
|
description = "HTTP"
|
||||||
# from_port = 80
|
from_port = 80
|
||||||
# to_port = 80
|
to_port = 80
|
||||||
# protocol = "tcp"
|
protocol = "tcp"
|
||||||
# cidr_blocks = ["0.0.0.0/0"]
|
cidr_blocks = var.enable_ingress_http ? ["0.0.0.0/0"] : []
|
||||||
# ipv6_cidr_blocks = ["::/0"]
|
ipv6_cidr_blocks = var.enable_ingress_http ? ["::/0"] : []
|
||||||
# }
|
}
|
||||||
|
|
||||||
egress {
|
egress {
|
||||||
from_port = 0
|
from_port = 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue