-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bastion host to access private eks cluster
- Loading branch information
amber
committed
Oct 3, 2024
1 parent
f554235
commit 04a4534
Showing
18 changed files
with
505 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: EKS Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-southeast-1 | ||
|
||
- name: Set up Kubectl | ||
uses: azure/setup-kubectl@v4 | ||
|
||
- name: Deploy to EKS using Kustomize | ||
run: | | ||
aws eks --region ap-southeast-1 update-kubeconfig --name nshm-eks | ||
kubectl apply -k overlays/prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Deploy Infrastructure | ||
|
||
on: | ||
push: | ||
branches: | ||
- setup-infra | ||
workflow_dispatch: | ||
inputs: | ||
provisioning: | ||
required: true | ||
default: 'false' | ||
type: boolean | ||
|
||
jobs: | ||
deploy: | ||
if: ${{ github.event.inputs.provisioning == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: '${{ secrets.AWS_ACCESS_KEY_ID }}' | ||
aws-secret-access-key: '${{ secrets.AWS_SECRET_ACCESS_KEY }}' | ||
aws-region: ap-southeast-1 | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_wrapper: false | ||
|
||
- name: Terraform Init and Apply | ||
run: | | ||
cd terraform/ | ||
terraform init | ||
terraform validate | ||
terraform plan | ||
terraform apply -auto-approve | ||
- name: Get Terraform Outputs and Save Artifact | ||
run: | | ||
cd terraform/ | ||
RDS_ENDPOINT=$(terraform output -raw db_instance_endpoint) | ||
RDS_PASSWORD=$(terraform output -raw db_instance_password) | ||
ALB_DNSNAME=$(terraform output -raw alb_dns_name) | ||
echo $ALB_DNSNAME | ||
echo $RDS_ENDPOINT > rds_endpoint.txt | ||
echo $RDS_PASSWORD > rds_password.txt | ||
- name: Upload Outputs as Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: terraform-outputs | ||
path: terraform/*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
terraform.tfstate* | ||
terraform/.terraform | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
resource "aws_security_group" "alb_sg" { | ||
name = "alb-security-group" | ||
vpc_id = var.vpc_id | ||
|
||
ingress { | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = 443 | ||
to_port = 443 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} | ||
|
||
resource "aws_lb" "nshm_alb" { | ||
name = "nshm-alb" | ||
internal = false | ||
load_balancer_type = "application" | ||
security_groups = [aws_security_group.alb_sg.id] | ||
subnets = var.public_subnet_ids | ||
|
||
tags = { | ||
Name = "nshm-alb" | ||
} | ||
} | ||
|
||
resource "aws_acm_certificate" "alb_cert" { | ||
domain_name = aws_lb.nshm_alb.dns_name | ||
validation_method = "DNS" | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
|
||
resource "aws_acm_certificate_validation" "alb_cert_validation" { | ||
certificate_arn = aws_acm_certificate.alb_cert.arn | ||
validation_record_fqdns = [ | ||
aws_lb.nshm_alb.dns_name | ||
] | ||
} | ||
|
||
resource "aws_lb_target_group" "nshm_target_group" { | ||
name = "nshm-target-group" | ||
port = 80 | ||
protocol = "HTTP" | ||
vpc_id = var.vpc_id | ||
|
||
health_check { | ||
healthy_threshold = 2 | ||
interval = 30 | ||
timeout = 5 | ||
path = "/" | ||
port = "traffic-port" | ||
protocol = "HTTP" | ||
unhealthy_threshold = 2 | ||
} | ||
} | ||
|
||
resource "aws_lb_listener" "http_listener" { | ||
load_balancer_arn = aws_lb.nshm_alb.arn | ||
port = 80 | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "redirect" | ||
redirect { | ||
protocol = "HTTPS" | ||
port = "443" | ||
status_code = "HTTP_301" | ||
} | ||
} | ||
} | ||
|
||
resource "aws_lb_listener" "https_listener" { | ||
load_balancer_arn = aws_lb.nshm_alb.arn | ||
port = 443 | ||
protocol = "HTTPS" | ||
ssl_policy = "ELBSecurityPolicy-2016-08" | ||
certificate_arn = aws_acm_certificate.alb_cert.arn | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.nshm_target_group.arn | ||
} | ||
} | ||
|
||
output "alb_dns_name" { | ||
value = aws_lb.nshm_alb.dns_name | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "vpc_id" { | ||
type = string | ||
} | ||
|
||
variable "security_group_id" { | ||
type = string | ||
} | ||
|
||
variable "public_subnet_ids" { | ||
type = list(string) | ||
} |
Oops, something went wrong.