Skip to content

Commit

Permalink
Naming, Autoscaling, Module Release Process (#13)
Browse files Browse the repository at this point in the history
* revert replicas change

* autoscaling

* try tempo-distributed

* would require config update

* update values

* set limits to recommended and requests a bit higher

* update s3 naming

* update irsa role name

* fix dupe data item

* fix dupe

* fix refs to tempo_s3

* add module release process

* update module source
  • Loading branch information
morga471 committed Apr 4, 2025
1 parent 0aef5cb commit 97889c3
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 178 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/terraform-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Terraform CI/CD
on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
- main
jobs:
terraform-ci-cd:
runs-on: 229685449397
permissions:
contents: write

steps:
- name: Checkout code
uses: CSVD/gh-actions-checkout@v4

- name: Setup Terraform
uses: CSVD/gh-actions-setup-terraform@v3
with:
terraform_version: "1.9.1"

- name: Setup GITHUB Credentials
id: github_credentials
uses: CSVD/gh-auth@main
with:
github_app_pem_file: ${{ secrets.GH_APP_PEM_FILE }}
github_app_installation_id: ${{ vars.GH_APP_INSTALLATION_ID }}
github_app_id: ${{ vars.GH_APP_ID }}


- name: Debug Authentication
run: |
# Print the GitHub server URL
echo "GitHub Server URL: ${{ github.server_url }}"
# Extract the host from the URL
HOST="${{ github.server_url }}"
HOST="${HOST#*//}"
HOST="${HOST%%/*}"
echo "GitHub Host: $HOST"
# Check if token exists
if [[ -n "${{ steps.github_credentials.outputs.github_token }}" ]]; then
echo "Token generated successfully"
# Test the token with a simple GitHub API call (without exposing the token)
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ steps.github_credentials.outputs.github_token }}" "${{ github.server_url }}/api/v3/user")
echo "API Test Status Code: $STATUS"
else
echo "No token was generated!"
fi
- name: Setup GitHub CLI
run: |
# Force manual authentication since setup-git might not work with GitHub Enterprise
echo "${{ steps.github_credentials.outputs.github_token }}" > /tmp/token.txt
gh auth login --with-token --hostname "github.e.it.census.gov" < /tmp/token.txt
rm /tmp/token.txt
# Test GitHub CLI auth status
gh auth status || echo "GitHub CLI authentication failed"
- name: AWS Auth
id: aws_auth
uses: CSVD/aws-auth@main
with:
ecs: true

- name: Run Terraform Module Release Action
uses: CSVD/terraform-module-release@main
with:
github-token: ${{ steps.github_credentials.outputs.github_token }}
working-directory: '.'
42 changes: 42 additions & 0 deletions .github/workflows/terraform-validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Terraform Validate
on:
pull_request:
workflow_dispatch:

jobs:

terraform-validate:
runs-on: "229685449397"
permissions:
contents: write
steps:
- name: Checkout code
uses: CSVD/gh-actions-checkout@v4

- name: Setup Terraform
uses: CSVD/gh-actions-setup-terraform@v2
with:
terraform_version: '1.7.3'

- name: Validate Terraform Configuration
id: validate
uses: CSVD/terraform-validate@main

- name: Check Validation/Test Results
if: always()
run: |
# Set default values if outputs are empty
IS_VALID="${{ steps.validate.outputs.is_valid }}"
TESTS_PASSED="${{ steps.validate.outputs.tests_passed }}"
# If outputs are empty, set them to false
[ -z "$IS_VALID" ] && IS_VALID="false"
[ -z "$TESTS_PASSED" ] && TESTS_PASSED="false"
if [[ "$IS_VALID" != "true" || "$TESTS_PASSED" != "true" ]]; then
echo "Validation or test errors found:"
echo "${{ steps.validate.outputs.stderr }}"
exit 1
else
echo "All validations and tests passed successfully!"
fi
101 changes: 0 additions & 101 deletions .github/workflows/terragrunt-cicd.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:

# Terraform Hooks
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.97.3 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
rev: v1.98.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
args:
Expand Down Expand Up @@ -94,6 +94,6 @@ repos:
# - --hook-config=--parallelism-ci-cpu-cores=2

- repo: https://github.com/ljnsn/cz-conventional-gitmoji
rev: v0.6.1
rev: v0.7.0
hooks:
- id: conventional-gitmoji
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,29 @@ Developer NOTE: We should automate this configuration.
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.14.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | >= 2.11.0 |
| <a name="provider_terraform"></a> [terraform](#provider\_terraform) | n/a |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_images"></a> [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade |
| <a name="module_tempo-irsa-role"></a> [tempo-irsa-role](#module\_tempo-irsa-role) | git@github.e.it.census.gov:SCT-Engineering/tfmod-custom-iam-role-for-service-account-eks.git/ | base |
| <a name="module_tempo-s3"></a> [tempo-s3](#module\_tempo-s3) | git@github.e.it.census.gov:terraform-modules/aws-s3.git//standard | tf-upgrade |
| <a name="module_images"></a> [images](#module\_images) | git::https://github.e.it.census.gov/terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade |
| <a name="module_tempo-irsa-role"></a> [tempo-irsa-role](#module\_tempo-irsa-role) | git::https://github.e.it.census.gov/SCT-Engineering/tfmod-custom-iam-role-for-service-account-eks.git/ | base |
| <a name="module_tempo_s3"></a> [tempo\_s3](#module\_tempo\_s3) | git::https://github.e.it.census.gov/terraform-modules/aws-s3.git//standard | tf-upgrade |

## Resources

| Name | Type |
|------|------|
| [helm_release.tempo](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [terraform_data.bucket_name_validator](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_s3_bucket.s3_server_access_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | The account\_id holding these resources (for the s3 bucket.) | `string` | n/a | yes |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | EKS cluster name name component used through out the EKS cluster describing its purpose (ex: dice-dev) | `string` | n/a | yes |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | The namespace into which tempo will be deployed | `string` | `"tempo"` | no |
| <a name="input_oidc_provider_arn"></a> [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN in the EKS cluster for the OpenID Connect identity provider. | `string` | n/a | yes |
Expand Down
1 change: 1 addition & 0 deletions aws_data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_caller_identity" "current" {}
2 changes: 1 addition & 1 deletion copy_images.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ locals {
}

module "images" {
source = "git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/?ref=tf-upgrade"
source = "git::https://github.e.it.census.gov/terraform-modules/aws-ecr-copy-images.git/?ref=tf-upgrade"

profile = var.profile
application_name = var.cluster_name
Expand Down
17 changes: 8 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
locals {
oidc_arn = var.oidc_provider_arn
tags = var.tags
account_id = var.account_id
oidc_arn = var.oidc_provider_arn
tags = var.tags

tempo_internal_hostname = format("tempo.%v.svc.cluster.local", var.namespace)
tempo_internal_port_number = 3100
Expand All @@ -15,18 +14,18 @@ locals {
# IRSA Role for Tempo
################################################################################
module "tempo-irsa-role" {
source = "git@github.e.it.census.gov:SCT-Engineering/tfmod-custom-iam-role-for-service-account-eks.git/?ref=base"
source = "git::https://github.e.it.census.gov/SCT-Engineering/tfmod-custom-iam-role-for-service-account-eks.git/?ref=base"

role_name = "${var.cluster_name}-tempo"
role_name = format("%v%v-%v", local.prefixes["eks-role"], var.cluster_name, "tempo")
attach_s3_bucket_owner_policy = true
attach_encrypted_object_manager_policy = true

s3_bucket_arns = [
module.tempo-s3.s3_bucket_arn,
"${module.tempo-s3.s3_bucket_arn}/*",
module.tempo_s3.s3_bucket_arn,
"${module.tempo_s3.s3_bucket_arn}/*",
]
kms_key_arns = [
module.tempo-s3.kms_key_arn
module.tempo_s3.kms_key_arn
]

oidc_providers = {
Expand Down Expand Up @@ -69,7 +68,7 @@ resource "helm_release" "tempo" {
}
set {
name = "tempo.storage.trace.s3.bucket"
value = module.tempo-s3.s3_bucket_id
value = module.tempo_s3.s3_bucket_id
}
set {
name = "tempo.storage.trace.s3.endpoint"
Expand Down
35 changes: 35 additions & 0 deletions prefixes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
locals {
prefixes = {
"efs" = "v-efs-"
"s3" = "v-s3-"
"ebs" = "v-ebs-"
"kms" = "k-kms-"
"role" = "r-"
"policy" = "p-"
"group" = "g-"
"security-group" = "" # "sg-"
# VPC
"vpc" = ""
"dhcp-options" = ""
"vpc-peer" = "vpcp-"
"route-table" = "route-"
"subnet" = ""
"vpc-endpoint" = "vpce-"
"elastic-ip" = "eip-"
"nat-gateway" = "nat-"
"internet-gateway" = "igw-"
"network-acl" = "nacl-"
"customer-gateway" = "cgw-"
"vpn-gateway" = "vpcg-"
"vpn-connection" = "vpn_"
"log-group" = "lg-"
"log-stream" = "lgs-"
# EKS
"eks" = "eks-"
"eks-s3" = "v-s3-eks-"
"eks-user" = "s-eks-"
"eks-role" = "r-eks-"
"eks-policy" = "p-eks-"
"eks-security-group" = "eks-sg-" # "sg-eks-"
}
}
28 changes: 23 additions & 5 deletions s3.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
## create bucket
locals {
account_id = data.aws_caller_identity.current.account_id
bucket_name = format("%v%v-tempo-%v-%v", local.prefixes["eks-s3"], var.cluster_name, local.account_id, local.region_short)
region_short = join("", [for c in split("-", var.region) : substr(c, 0, 1)])
}

data "aws_s3_bucket" "s3_server_access_logs" {
bucket = format("inf-logs-%v-%v", local.account_id, var.region)
}

module "tempo-s3" {
source = "git@github.e.it.census.gov:terraform-modules/aws-s3.git//standard?ref=tf-upgrade"
# Validate S3 bucket name length
resource "terraform_data" "bucket_name_validator" {
input = local.bucket_name

lifecycle {
precondition {
condition = length(local.bucket_name) >= 3 && length(local.bucket_name) <= 63
error_message = "S3 bucket name must be between 3 and 63 characters. Current name '${local.bucket_name}' is ${length(local.bucket_name)} characters."
}
}
}

module "tempo_s3" {
depends_on = [terraform_data.bucket_name_validator]
source = "git::https://github.e.it.census.gov/terraform-modules/aws-s3.git//standard?ref=tf-upgrade"

bucket_name = format("%v-tempo", var.cluster_name)
bucket_name = local.bucket_name
access_log_bucket = data.aws_s3_bucket.s3_server_access_logs.id
force_destroy = true

tags = local.tags
tags = var.tags
}
Loading

0 comments on commit 97889c3

Please sign in to comment.