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
@@ -30,6 +30,13 @@ jobs:
|
||||
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
|
||||
- name: 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
|
||||
- name: Terraform Plan
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
### SET VARIABLES
|
||||
|
||||
variable "environment_name" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "project_name" {
|
||||
type = string
|
||||
default = "hideyoshi-portifolio"
|
||||
|
||||
@@ -12,6 +12,10 @@ variable "public_ip" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "environment_name" {
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
resource "godaddy_domain_record" "default" {
|
||||
domain = "hideyoshi.com.br"
|
||||
@@ -19,7 +23,7 @@ resource "godaddy_domain_record" "default" {
|
||||
overwrite = false
|
||||
|
||||
record {
|
||||
name = "staging "
|
||||
name = var.environment_name == "prod" ? "@" : "staging"
|
||||
type = "A"
|
||||
data = "${var.public_ip}"
|
||||
ttl = 600
|
||||
@@ -27,7 +31,7 @@ resource "godaddy_domain_record" "default" {
|
||||
}
|
||||
|
||||
record {
|
||||
name = "api.staging "
|
||||
name = var.environment_name == "prod" ? "api" : "api.staging"
|
||||
type = "A"
|
||||
data = "${var.public_ip}"
|
||||
ttl = 600
|
||||
|
||||
@@ -34,12 +34,13 @@ resource "aws_key_pair" "ssh_key_ci_cd" {
|
||||
}
|
||||
|
||||
locals {
|
||||
ports_in = [
|
||||
22,
|
||||
80,
|
||||
443,
|
||||
6443,
|
||||
10250
|
||||
rules_in = [
|
||||
{ "port": 22, "protocol": "tcp" },
|
||||
{ "port": 80, "protocol": "tcp" },
|
||||
{ "port": 443, "protocol": "tcp" },
|
||||
{ "port": 6080, "protocol": "tcp" },
|
||||
{ "port": 6443, "protocol": "tcp" },
|
||||
{ "port": 10250, "protocol": "tcp" },
|
||||
]
|
||||
}
|
||||
|
||||
@@ -48,11 +49,11 @@ resource "aws_security_group" "project_pool" {
|
||||
description = "Security group for project pool"
|
||||
|
||||
dynamic "ingress" {
|
||||
for_each = toset(local.ports_in)
|
||||
for_each = toset(local.rules_in)
|
||||
content {
|
||||
from_port = ingress.value
|
||||
to_port = ingress.value
|
||||
protocol = "tcp"
|
||||
from_port = ingress.value["port"]
|
||||
to_port = ingress.value["port"]
|
||||
protocol = ingress.value["protocol"]
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
}
|
||||
@@ -69,7 +70,7 @@ resource "aws_security_group" "project_pool" {
|
||||
|
||||
resource "aws_instance" "main" {
|
||||
ami = "ami-0af6e9042ea5a4e3e"
|
||||
instance_type = "t3a.medium"
|
||||
instance_type = "t3a.small"
|
||||
vpc_security_group_ids = [ aws_security_group.project_pool.id ]
|
||||
|
||||
key_name = aws_key_pair.ssh_key_main.key_name
|
||||
@@ -89,14 +90,13 @@ resource "aws_instance" "main" {
|
||||
}
|
||||
|
||||
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",
|
||||
"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 = [
|
||||
"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",
|
||||
"while ! nc -z ${aws_instance.main.public_ip} 6443; do sleep 0.1; done",
|
||||
"exec /home/ubuntu/setup.sh | tee logs.txt",
|
||||
|
||||
Reference in New Issue
Block a user