Skip to content

Commit d65684c

Browse files
committed
eks infra, pipeline changes
1 parent a3c1013 commit d65684c

File tree

9 files changed

+286
-5
lines changed

9 files changed

+286
-5
lines changed

.github/workflows/build-and-deploy.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,21 @@ jobs:
6666
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ steps.meta.outputs.IMAGE_TAG }}
6767
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest
6868
cache-from: type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:buildcache,image-manifest=true
69-
cache-to: type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:buildcache,mode=max,image-manifest=true
69+
cache-to: type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:buildcache,mode=max,image-manifest=true
70+
71+
# after ECR push
72+
- name: ⬇️ Configure AWS creds & kubeconfig
73+
uses: aws-actions/configure-aws-credentials@v4
74+
with:
75+
role-to-assume: ${{ secrets.OIDC_ROLE_ARN }} # rimworld_hay_calc_github_oidc
76+
aws-region: ${{ vars.AWS_REGION }}
77+
78+
- run: aws eks update-kubeconfig \
79+
--name rimworld-hay-calc-dev-eks \
80+
--region ${{ vars.AWS_REGION }}
81+
82+
- name: 🚀 Deploy
83+
run: |
84+
IMAGE=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ steps.meta.outputs.IMAGE_TAG }}
85+
kubectl set image deployment/rimworld-hay-calc web=$IMAGE --record || \
86+
kubectl apply -f infra/k8s/dev-deployment.yaml

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ dist-ssr
2323
*.sln
2424
*.sw?
2525

26-
.terraform/*
26+
**/.terraform/
2727
.terraform.tfstate*

infra/eks.tf

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
###############################################################################
2+
# 1. Tiny VPC (skip if you already have one)
3+
###############################################################################
4+
data "aws_availability_zones" "available" { state = "available" }
5+
6+
locals {
7+
azs = slice(data.aws_availability_zones.available.names, 0, 2)
8+
}
9+
10+
11+
module "vpc" {
12+
source = "terraform-aws-modules/vpc/aws"
13+
version = "~> 5.0"
14+
15+
name = "${var.project_name}-${var.environment}-vpc"
16+
cidr = "10.10.0.0/24"
17+
azs = local.azs
18+
19+
public_subnets = ["10.10.0.0/26", "10.10.0.64/26"] # /26 = 64 IPs
20+
private_subnets = ["10.10.0.128/26","10.10.0.192/26"]
21+
22+
enable_nat_gateway = true # keep it ultra-minimal
23+
single_nat_gateway = true
24+
25+
tags = var.global_tags
26+
}
27+
28+
###############################################################################
29+
# 2. EKS cluster (minimal)
30+
###############################################################################
31+
module "eks" {
32+
source = "terraform-aws-modules/eks/aws"
33+
version = "~> 20.0"
34+
35+
cluster_name = "${var.project_name}-${var.environment}-eks"
36+
cluster_version = "1.28"
37+
subnet_ids = module.vpc.private_subnets
38+
vpc_id = module.vpc.vpc_id
39+
40+
#access
41+
cluster_endpoint_public_access = true
42+
cluster_endpoint_public_access_cidrs = [
43+
"136.57.60.172/32",
44+
"0.0.0.0/0"
45+
]
46+
47+
48+
# One small managed node group
49+
eks_managed_node_groups = {}
50+
fargate_profiles = {
51+
all = {
52+
selectors = [{ namespace = "default" }]
53+
}
54+
}
55+
56+
# map the GitHub OIDC deploy role so CI can kubectl
57+
access_entries = {
58+
github-ci = {
59+
principal_arn = aws_iam_role.github_deploy.arn
60+
kubernetes_groups = ["cluster-admin"]
61+
}
62+
}
63+
64+
cluster_enabled_log_types = [
65+
"api", "audit", "authenticator", "controllerManager", "scheduler"
66+
]
67+
68+
cloudwatch_log_group_retention_in_days = 30
69+
70+
tags = var.global_tags
71+
}
72+
73+
# aws-for-fluent-bit add-on (EKS add-ons support add-ons/v1 API)
74+
# resource "aws_eks_addon" "fluentbit" {
75+
# cluster_name = module.eks.cluster_name
76+
# addon_name = "aws-for-fluent-bit"
77+
# addon_version = "v2.31.0-eksbuild.1" # latest as of 2025-07
78+
# resolve_conflicts_on_create = "OVERWRITE"
79+
80+
# tags = var.global_tags
81+
# }
82+
83+
# resource "aws_cloudwatch_log_group" "app_logs" {
84+
# name = "/aws/containerinsights/${module.eks.cluster_name}/application"
85+
# retention_in_days = 30
86+
# }
87+
88+
output "cluster_name" { value = module.eks.cluster_name }
89+
output "cluster_endpoint" { value = module.eks.cluster_endpoint }
90+
output "cluster_ca" { value = module.eks.cluster_certificate_authority_data }
91+

infra/envs/dev/.terraform.lock.hcl

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/envs/dev/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module "rimworld_hay_calc" {
55
aws_region = var.aws_region
66
github_repo = var.github_repo
77
project_name = var.project_name
8+
global_tags = var.global_tags
9+
environment = var.environment
810
}
911

1012
# Re-expose useful outputs

infra/envs/dev/terraform.tfvars

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
github_repo = "vonschtirlitz/rimworld-hay-calc"
22
aws_region = "us-east-1"
3-
project_name = "rimworld-hay-calc"
3+
project_name = "rimworld-hay-calc"
4+
environment = "dev"
5+
global_tags = {
6+
Project = "RimworldHayCalc"
7+
Application = "rimworld-hay-calc"
8+
}

infra/envs/dev/variables.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
variable "aws_region" { type = string }
22
variable "github_repo" { type = string }
3-
variable "project_name" { type = string }
3+
variable "project_name" { type = string }
4+
variable "global_tags" { type = map(string) }
5+
variable "environment" { type = string }

infra/main.tf

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data "aws_iam_policy_document" "github_trust" {
2020
effect = "Allow"
2121
principals {
2222
type = "Federated"
23-
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/token.actions.githubusercontent.com"]
23+
identifiers = [aws_iam_openid_connect_provider.github.arn]
2424
}
2525
actions = ["sts:AssumeRoleWithWebIdentity"]
2626

@@ -47,3 +47,56 @@ resource "aws_iam_role_policy_attachment" "ecr_power" {
4747
role = aws_iam_role.github_deploy.name
4848
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser"
4949
}
50+
51+
resource "aws_iam_openid_connect_provider" "github" {
52+
url = "https://token.actions.githubusercontent.com"
53+
54+
# GitHub always sends this client_id
55+
client_id_list = ["sts.amazonaws.com"]
56+
57+
# Thumbprint for DigiCert Global Root G2 (valid as of 2025-07)
58+
thumbprint_list = ["6938fd4d98bab03faadb97b34396831e3780aea1"]
59+
60+
tags = {
61+
Name = "github-oidc"
62+
Project = var.global_tags["Project"]
63+
}
64+
}
65+
66+
output "github_oidc_provider_arn" {
67+
value = aws_iam_openid_connect_provider.github.arn
68+
}
69+
70+
########################
71+
# AWS COST TRACKING #
72+
########################
73+
# resource "aws_ce_cost_allocation_tag" "project" {
74+
# tag_key = "Project"
75+
# status = "Active" # must be Active to show up in Cost Explorer
76+
# }
77+
78+
# resource "aws_ce_cost_allocation_tag" "environment" {
79+
# tag_key = "Environment"
80+
# status = "Active"
81+
# }
82+
83+
# resource "aws_ce_cost_allocation_tag" "application" {
84+
# tag_key = "Application"
85+
# status = "Active"
86+
# }
87+
88+
resource "aws_resourcegroups_group" "my_app" {
89+
name = "${var.global_tags["Application"]}-${var.environment}"
90+
91+
resource_query {
92+
query = jsonencode({
93+
ResourceTypeFilters = ["AWS::AllSupported"]
94+
TagFilters = [
95+
{ Key = "Application", Values = [var.global_tags["Application"]] },
96+
{ Key = "Environment", Values = [var.environment] }
97+
]
98+
})
99+
}
100+
101+
tags = var.global_tags
102+
}

infra/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ variable "global_tags" {
1414
type = map(string)
1515
default = {
1616
Project = "RimworldHayCalc"
17+
Application = "rimworld-hay-calc"
1718
}
1819
}
1920

2021
variable "github_repo" {
2122
description = "owner/repo used in the GitHub OIDC subject"
2223
type = string
24+
}
25+
26+
variable "environment" {
27+
type = string
28+
description = "Environment name, e.g. dev, staging, prod"
2329
}

0 commit comments

Comments
 (0)