Fixes DNS Name Per Environment and Protocols Per Port Rules in Sec Grp
This commit is contained in:
7
.github/workflows/delete-staging.yml
vendored
7
.github/workflows/delete-staging.yml
vendored
@@ -31,6 +31,13 @@ jobs:
|
|||||||
- name: Terraform Init
|
- name: Terraform Init
|
||||||
run: terraform init
|
run: terraform init
|
||||||
|
|
||||||
|
- name: Terraform Ignore Buckets
|
||||||
|
run: |
|
||||||
|
terraform state rm \
|
||||||
|
module.bucket.aws_s3_bucket.default \
|
||||||
|
module.bucket.aws_s3_bucket_policy.default \
|
||||||
|
module.bucket.aws_s3_bucket_public_access_block.bucket_public_disabled
|
||||||
|
|
||||||
# Generates an execution plan for Terraform
|
# Generates an execution plan for Terraform
|
||||||
- name: Terraform Plan
|
- name: Terraform Plan
|
||||||
run: terraform plan -input=false -destroy
|
run: terraform plan -input=false -destroy
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
### SET VARIABLES
|
### SET VARIABLES
|
||||||
|
|
||||||
|
variable "environment_name" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
variable "project_name" {
|
variable "project_name" {
|
||||||
type = string
|
type = string
|
||||||
default = "hideyoshi-portifolio"
|
default = "hideyoshi-portifolio"
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ variable "public_ip" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "environment_name" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "godaddy_domain_record" "default" {
|
resource "godaddy_domain_record" "default" {
|
||||||
domain = "hideyoshi.com.br"
|
domain = "hideyoshi.com.br"
|
||||||
@@ -19,7 +23,7 @@ resource "godaddy_domain_record" "default" {
|
|||||||
overwrite = false
|
overwrite = false
|
||||||
|
|
||||||
record {
|
record {
|
||||||
name = "staging "
|
name = var.environment_name == "prod" ? "@" : "staging"
|
||||||
type = "A"
|
type = "A"
|
||||||
data = "${var.public_ip}"
|
data = "${var.public_ip}"
|
||||||
ttl = 600
|
ttl = 600
|
||||||
@@ -27,7 +31,7 @@ resource "godaddy_domain_record" "default" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record {
|
record {
|
||||||
name = "api.staging "
|
name = var.environment_name == "prod" ? "api" : "api.staging"
|
||||||
type = "A"
|
type = "A"
|
||||||
data = "${var.public_ip}"
|
data = "${var.public_ip}"
|
||||||
ttl = 600
|
ttl = 600
|
||||||
|
|||||||
@@ -34,12 +34,13 @@ resource "aws_key_pair" "ssh_key_ci_cd" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
ports_in = [
|
rules_in = [
|
||||||
22,
|
{ "port": 22, "protocol": "tcp" },
|
||||||
80,
|
{ "port": 80, "protocol": "tcp" },
|
||||||
443,
|
{ "port": 443, "protocol": "tcp" },
|
||||||
6443,
|
{ "port": 6080, "protocol": "tcp" },
|
||||||
10250
|
{ "port": 6443, "protocol": "tcp" },
|
||||||
|
{ "port": 10250, "protocol": "tcp" },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +49,11 @@ resource "aws_security_group" "project_pool" {
|
|||||||
description = "Security group for project pool"
|
description = "Security group for project pool"
|
||||||
|
|
||||||
dynamic "ingress" {
|
dynamic "ingress" {
|
||||||
for_each = toset(local.ports_in)
|
for_each = toset(local.rules_in)
|
||||||
content {
|
content {
|
||||||
from_port = ingress.value
|
from_port = ingress.value["port"]
|
||||||
to_port = ingress.value
|
to_port = ingress.value["port"]
|
||||||
protocol = "tcp"
|
protocol = ingress.value["protocol"]
|
||||||
cidr_blocks = ["0.0.0.0/0"]
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ resource "aws_security_group" "project_pool" {
|
|||||||
|
|
||||||
resource "aws_instance" "main" {
|
resource "aws_instance" "main" {
|
||||||
ami = "ami-0af6e9042ea5a4e3e"
|
ami = "ami-0af6e9042ea5a4e3e"
|
||||||
instance_type = "t3a.medium"
|
instance_type = "t3a.small"
|
||||||
vpc_security_group_ids = [ aws_security_group.project_pool.id ]
|
vpc_security_group_ids = [ aws_security_group.project_pool.id ]
|
||||||
|
|
||||||
key_name = aws_key_pair.ssh_key_main.key_name
|
key_name = aws_key_pair.ssh_key_main.key_name
|
||||||
@@ -89,14 +90,13 @@ resource "aws_instance" "main" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline = [
|
inline = [
|
||||||
"echo 'curl -sfL https://get.k3s.io | K3S_TOKEN=\"${var.k3s_token}\" sh -' >> /home/ubuntu/setup.sh",
|
"echo 'curl -sfL https://get.k3s.io | K3S_TOKEN=\"${var.k3s_token}\" K3S_KUBECONFIG_MODE=644 INSTALL_K3S_EXEC=\"server --disable=traefik\" sh -' >> /home/ubuntu/setup.sh",
|
||||||
|
"echo 'mkdir /home/ubuntu/.kube' >> /home/ubuntu/setup.sh",
|
||||||
|
"echo 'sudo chmod 644 /etc/rancher/k3s/k3s.yaml' >> /home/ubuntu/setup.sh",
|
||||||
|
"echo 'cp /etc/rancher/k3s/k3s.yaml /home/ubuntu/.kube/k3s.yaml' >> /home/ubuntu/setup.sh",
|
||||||
|
"echo 'export KUBECONFIG=/home/ubuntu/.kube/k3s.yaml' >> /home/ubuntu/.profile",
|
||||||
"chmod +x /home/ubuntu/setup.sh",
|
"chmod +x /home/ubuntu/setup.sh",
|
||||||
"exec /home/ubuntu/setup.sh | tee logs.txt",
|
"exec /home/ubuntu/setup.sh | tee logs.txt",
|
||||||
"mkdir /home/ubuntu/.kube",
|
|
||||||
"sudo chmod 644 /etc/rancher/k3s/k3s.yaml",
|
|
||||||
"cp /etc/rancher/k3s/k3s.yaml /home/ubuntu/.kube/k3s.yaml",
|
|
||||||
"echo 'export KUBECONFIG=/home/ubuntu/.kube/k3s.yaml' >> /home/ubuntu/profile",
|
|
||||||
"export KUBECONFIG=/home/ubuntu/.kube/k3s.yaml"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ resource "aws_instance" "worker" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline = [
|
inline = [
|
||||||
"echo 'curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC=\"agent\" K3S_TOKEN=\"${var.k3s_token}\" sh -s - --server ${var.project_domain}:6443' >> /home/ubuntu/setup.sh",
|
"echo 'curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC=\"agent\" K3S_TOKEN=\"${var.k3s_token}\" K3S_URL=\"${var.project_domain}:6443\" sh -s -' >> /home/ubuntu/setup.sh",
|
||||||
"chmod +x /home/ubuntu/setup.sh",
|
"chmod +x /home/ubuntu/setup.sh",
|
||||||
"while ! nc -z ${aws_instance.main.public_ip} 6443; do sleep 0.1; done",
|
"while ! nc -z ${aws_instance.main.public_ip} 6443; do sleep 0.1; done",
|
||||||
"exec /home/ubuntu/setup.sh | tee logs.txt",
|
"exec /home/ubuntu/setup.sh | tee logs.txt",
|
||||||
|
|||||||
Reference in New Issue
Block a user