From ac30d725c768f6a864bc71d704f6b60f44d23b69 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Wed, 26 Feb 2025 17:41:21 -0500 Subject: [PATCH 01/25] revert replicas change --- main.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 745a29c..5ec3b77 100644 --- a/main.tf +++ b/main.tf @@ -54,7 +54,11 @@ resource "helm_release" "tempo" { set { name = "replicas" - value = "1" + value = "3" + } + set { + name = "replicas" + value = "2" } set { name = "tempo.repository" From 3a294869b9d761b86c4391cdbf6aa3bf8b1b36da Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 28 Feb 2025 18:21:59 -0500 Subject: [PATCH 02/25] autoscaling --- main.tf | 4 ---- tempo_values.yaml | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/main.tf b/main.tf index 5ec3b77..f25d872 100644 --- a/main.tf +++ b/main.tf @@ -52,10 +52,6 @@ resource "helm_release" "tempo" { wait = true timeout = 300 - set { - name = "replicas" - value = "3" - } set { name = "replicas" value = "2" diff --git a/tempo_values.yaml b/tempo_values.yaml index 24a6bbd..70ebf27 100644 --- a/tempo_values.yaml +++ b/tempo_values.yaml @@ -27,8 +27,8 @@ ingester: enabled: true resources: requests: - cpu: "1m" - memory: "1Mi" + cpu: "100m" + memory: "128Mi" limits: cpu: "200m" memory: "256Mi" @@ -37,8 +37,8 @@ distributor: enabled: true resources: requests: - cpu: "1m" - memory: "1Mi" + cpu: "100m" + memory: "128Mi" limits: cpu: "200m" memory: "256Mi" @@ -47,8 +47,8 @@ compactor: enabled: true resources: requests: - cpu: "1m" - memory: "1Mi" + cpu: "100m" + memory: "128Mi" limits: cpu: "200m" memory: "256Mi" @@ -57,8 +57,8 @@ querier: enabled: true resources: requests: - cpu: "1m" - memory: "1Mi" + cpu: "100m" + memory: "128Mi" limits: cpu: "200m" memory: "256Mi" @@ -67,8 +67,8 @@ gateway: enabled: true resources: requests: - cpu: "1m" - memory: "1Mi" + cpu: "100m" + memory: "128Mi" limits: cpu: "200m" memory: "256Mi" From 574faa78fd3cc0074b1cbca7e030e6a010348ef3 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 3 Mar 2025 20:05:27 -0500 Subject: [PATCH 03/25] try tempo-distributed --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index f25d872..3fe160c 100644 --- a/main.tf +++ b/main.tf @@ -42,7 +42,7 @@ module "tempo-irsa-role" { # Helm Chart for Tempo ################################################################################ resource "helm_release" "tempo" { - chart = "tempo" + chart = "tempo-distributed" version = var.tempo_chart_version name = "tempo" namespace = var.namespace From 4a60944d893e2c405840b00765bfaecccf7a09e6 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 3 Mar 2025 20:10:20 -0500 Subject: [PATCH 04/25] would require config update --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 3fe160c..f25d872 100644 --- a/main.tf +++ b/main.tf @@ -42,7 +42,7 @@ module "tempo-irsa-role" { # Helm Chart for Tempo ################################################################################ resource "helm_release" "tempo" { - chart = "tempo-distributed" + chart = "tempo" version = var.tempo_chart_version name = "tempo" namespace = var.namespace From e06a542c432a257923fe5b7c9018528791190ad9 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 6 Mar 2025 19:53:53 -0500 Subject: [PATCH 05/25] update values --- main.tf | 2 +- tempo_values.yaml | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/main.tf b/main.tf index f25d872..745a29c 100644 --- a/main.tf +++ b/main.tf @@ -54,7 +54,7 @@ resource "helm_release" "tempo" { set { name = "replicas" - value = "2" + value = "1" } set { name = "tempo.repository" diff --git a/tempo_values.yaml b/tempo_values.yaml index 70ebf27..24a6bbd 100644 --- a/tempo_values.yaml +++ b/tempo_values.yaml @@ -27,8 +27,8 @@ ingester: enabled: true resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: "1m" + memory: "1Mi" limits: cpu: "200m" memory: "256Mi" @@ -37,8 +37,8 @@ distributor: enabled: true resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: "1m" + memory: "1Mi" limits: cpu: "200m" memory: "256Mi" @@ -47,8 +47,8 @@ compactor: enabled: true resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: "1m" + memory: "1Mi" limits: cpu: "200m" memory: "256Mi" @@ -57,8 +57,8 @@ querier: enabled: true resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: "1m" + memory: "1Mi" limits: cpu: "200m" memory: "256Mi" @@ -67,8 +67,8 @@ gateway: enabled: true resources: requests: - cpu: "100m" - memory: "128Mi" + cpu: "1m" + memory: "1Mi" limits: cpu: "200m" memory: "256Mi" From 5ed26ce805df5aed28b0388728db9f96c4d7e079 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 13 Mar 2025 21:08:28 -0400 Subject: [PATCH 06/25] set limits to recommended and requests a bit higher --- tempo_values.yaml | 59 +++++++---------------------------------------- 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/tempo_values.yaml b/tempo_values.yaml index 24a6bbd..5b2e47b 100644 --- a/tempo_values.yaml +++ b/tempo_values.yaml @@ -1,4 +1,11 @@ tempo: + resources: + requests: + cpu: 100m + memory: 512Mi + limits: + cpu: 2000m + memory: 6Gi storage: trace: backend: s3 @@ -18,62 +25,12 @@ serviceAccount: persistence: enabled: true + enableStatefulSetAutoDeletePVC: false accessModes: - ReadWriteOnce size: 10Gi -ingester: - autoscaling: - enabled: true - resources: - requests: - cpu: "1m" - memory: "1Mi" - limits: - cpu: "200m" - memory: "256Mi" -distributor: - autoscaling: - enabled: true - resources: - requests: - cpu: "1m" - memory: "1Mi" - limits: - cpu: "200m" - memory: "256Mi" -compactor: - autoscaling: - enabled: true - resources: - requests: - cpu: "1m" - memory: "1Mi" - limits: - cpu: "200m" - memory: "256Mi" -querier: - autoscaling: - enabled: true - resources: - requests: - cpu: "1m" - memory: "1Mi" - limits: - cpu: "200m" - memory: "256Mi" -gateway: - autoscaling: - enabled: true - resources: - requests: - cpu: "1m" - memory: "1Mi" - limits: - cpu: "200m" - memory: "256Mi" traces: jaeger: zipkin: - # -- Enable Tempo to ingest Zipkin traces enabled: true From 06eee652a4db89affe25403fa228e754dec985ca Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 21 Mar 2025 22:01:20 -0400 Subject: [PATCH 07/25] update s3 naming --- README.md | 5 ++++- s3.tf | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e587c7f..4f94173 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Developer NOTE: We should automate this configuration. |------|---------| | [aws](#provider\_aws) | >= 5.14.0 | | [helm](#provider\_helm) | >= 2.11.0 | +| [terraform](#provider\_terraform) | n/a | ## Modules @@ -39,13 +40,15 @@ Developer NOTE: We should automate this configuration. |------|--------|---------| | [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade | | [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 | -| [tempo-s3](#module\_tempo-s3) | git@github.e.it.census.gov:terraform-modules/aws-s3.git//standard | tf-upgrade | +| [tempo\_s3](#module\_tempo\_s3) | git@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 diff --git a/s3.tf b/s3.tf index 498fa70..b1ded19 100644 --- a/s3.tf +++ b/s3.tf @@ -1,14 +1,34 @@ -## create bucket +data "aws_caller_identity" "current" {} + +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@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 } From 8e681619d22b41412637dffafb93e6d705275db4 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 21 Mar 2025 22:03:48 -0400 Subject: [PATCH 08/25] update irsa role name --- main.tf | 2 +- prefixes.tf | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 prefixes.tf diff --git a/main.tf b/main.tf index 745a29c..22b74f5 100644 --- a/main.tf +++ b/main.tf @@ -17,7 +17,7 @@ locals { module "tempo-irsa-role" { source = "git@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 diff --git a/prefixes.tf b/prefixes.tf new file mode 100644 index 0000000..e9a6127 --- /dev/null +++ b/prefixes.tf @@ -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-" + } +} From cc909eec4bc403e87acaafb3e2cd13ddf7523ee5 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 24 Mar 2025 12:50:58 -0400 Subject: [PATCH 09/25] fix dupe data item --- aws_data.tf | 1 + s3.tf | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 aws_data.tf diff --git a/aws_data.tf b/aws_data.tf new file mode 100644 index 0000000..8fc4b38 --- /dev/null +++ b/aws_data.tf @@ -0,0 +1 @@ +data "aws_caller_identity" "current" {} diff --git a/s3.tf b/s3.tf index b1ded19..376e021 100644 --- a/s3.tf +++ b/s3.tf @@ -1,5 +1,3 @@ -data "aws_caller_identity" "current" {} - 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) From 68f7cc3a3370bc07ab713e2e6f56728e50e19285 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 24 Mar 2025 12:55:11 -0400 Subject: [PATCH 10/25] fix dupe --- README.md | 1 - main.tf | 5 ++--- variables.tf | 5 ----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4f94173..e717ee1 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,6 @@ Developer NOTE: We should automate this configuration. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [account\_id](#input\_account\_id) | The account\_id holding these resources (for the s3 bucket.) | `string` | n/a | yes | | [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 | | [namespace](#input\_namespace) | The namespace into which tempo will be deployed | `string` | `"tempo"` | no | | [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN in the EKS cluster for the OpenID Connect identity provider. | `string` | n/a | yes | diff --git a/main.tf b/main.tf index 22b74f5..7b5e7de 100644 --- a/main.tf +++ b/main.tf @@ -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 diff --git a/variables.tf b/variables.tf index e824a9d..ce7152f 100644 --- a/variables.tf +++ b/variables.tf @@ -9,11 +9,6 @@ variable "region" { type = string } -variable "account_id" { - description = "The account_id holding these resources (for the s3 bucket.)" - type = string -} - variable "cluster_name" { description = "EKS cluster name name component used through out the EKS cluster describing its purpose (ex: dice-dev)" type = string From a7f6b31d0cd0a97b004b293b3b4bbd4f007a76ad Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 24 Mar 2025 12:57:37 -0400 Subject: [PATCH 11/25] fix refs to tempo_s3 --- main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 7b5e7de..7a6de40 100644 --- a/main.tf +++ b/main.tf @@ -21,11 +21,11 @@ module "tempo-irsa-role" { 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 = { @@ -68,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" From d8f1b4371011ebc39435705c5e1081d822a9f2d1 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 1 Apr 2025 11:54:47 -0400 Subject: [PATCH 12/25] add module release process --- .github/workflows/terraform-release.yaml | 73 ++++++++++++++++ .github/workflows/terraform-validate.yaml | 42 +++++++++ .github/workflows/terragrunt-cicd.yml | 101 ---------------------- 3 files changed, 115 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/terraform-release.yaml create mode 100644 .github/workflows/terraform-validate.yaml delete mode 100644 .github/workflows/terragrunt-cicd.yml diff --git a/.github/workflows/terraform-release.yaml b/.github/workflows/terraform-release.yaml new file mode 100644 index 0000000..90910bc --- /dev/null +++ b/.github/workflows/terraform-release.yaml @@ -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: '.' diff --git a/.github/workflows/terraform-validate.yaml b/.github/workflows/terraform-validate.yaml new file mode 100644 index 0000000..72829d8 --- /dev/null +++ b/.github/workflows/terraform-validate.yaml @@ -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 diff --git a/.github/workflows/terragrunt-cicd.yml b/.github/workflows/terragrunt-cicd.yml deleted file mode 100644 index a78523e..0000000 --- a/.github/workflows/terragrunt-cicd.yml +++ /dev/null @@ -1,101 +0,0 @@ -name: 'Terraform Module CI' - -on: - push: - branches: - - main - paths: - - '**/*.hcl' - - '**/*.tf' - pull_request: - branches: - - main - paths: - - '**/*.hcl' - - '**/*.tf' - -permissions: - contents: read - pull-requests: write - -jobs: - validate: - name: 'Validate Module' - runs-on: self-hosted - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v2 - with: - terraform_version: 1.5.0 - - - name: Terraform Init - run: | - terraform init -backend=false - - - name: Terraform Format - run: | - terraform fmt -check - - - name: Terraform Validate - run: | - terraform validate - - - name: Run tflint - uses: terraform-linters/setup-tflint@v3 - if: github.event_name == 'pull_request' - - - name: Lint Terraform - if: github.event_name == 'pull_request' - run: | - tflint --format compact - - release: - name: 'Create Release' - needs: validate - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - runs-on: self-hosted - permissions: - contents: write - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - - name: Install Commitizen - run: | - pip install commitizen - - - name: Configure Git - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - - - name: Bump Version and Generate Changelog - id: cz - run: | - cz bump --yes - echo "new_version=$(cz version --project)" >> $GITHUB_OUTPUT - echo "changelog=$(cz changelog --dry-run)" >> $GITHUB_OUTPUT - - - name: Create Release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ steps.cz.outputs.new_version }} - release_name: Release v${{ steps.cz.outputs.new_version }} - draft: false - prerelease: false - body: ${{ steps.cz.outputs.changelog }} From 82172da523771e1de4e3e4178e71eac6c3cb64a0 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 1 Apr 2025 20:49:18 -0400 Subject: [PATCH 13/25] update module source --- .pre-commit-config.yaml | 4 ++-- README.md | 6 +++--- copy_images.tf | 2 +- main.tf | 2 +- s3.tf | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef52d70..8244dbb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: @@ -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 diff --git a/README.md b/README.md index e717ee1..824072e 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,9 @@ Developer NOTE: We should automate this configuration. | Name | Source | Version | |------|--------|---------| -| [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade | -| [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 | -| [tempo\_s3](#module\_tempo\_s3) | git@github.e.it.census.gov:terraform-modules/aws-s3.git//standard | tf-upgrade | +| [images](#module\_images) | git::https://github.e.it.census.gov/terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade | +| [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 | +| [tempo\_s3](#module\_tempo\_s3) | git::https://github.e.it.census.gov/terraform-modules/aws-s3.git//standard | tf-upgrade | ## Resources diff --git a/copy_images.tf b/copy_images.tf index 7d14060..fbb90ef 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -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 diff --git a/main.tf b/main.tf index 7a6de40..4515b8f 100644 --- a/main.tf +++ b/main.tf @@ -14,7 +14,7 @@ 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 = format("%v%v-%v", local.prefixes["eks-role"], var.cluster_name, "tempo") attach_s3_bucket_owner_policy = true diff --git a/s3.tf b/s3.tf index 376e021..4a70192 100644 --- a/s3.tf +++ b/s3.tf @@ -22,7 +22,7 @@ resource "terraform_data" "bucket_name_validator" { module "tempo_s3" { depends_on = [terraform_data.bucket_name_validator] - source = "git@github.e.it.census.gov:terraform-modules/aws-s3.git//standard?ref=tf-upgrade" + source = "git::https://github.e.it.census.gov/terraform-modules/aws-s3.git//standard?ref=tf-upgrade" bucket_name = local.bucket_name access_log_bucket = data.aws_s3_bucket.s3_server_access_logs.id From bf7248f6fc6084305a16ca0282dd99734784f9af Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 14 Apr 2025 18:37:14 -0400 Subject: [PATCH 14/25] pull from ent-ecr --- .github/workflows/terraform-validate.yaml | 54 +++++++++---------- README.md | 3 ++ copy_images.tf | 21 ++++++-- variables.tf | 64 +++++++++++++---------- 4 files changed, 82 insertions(+), 60 deletions(-) diff --git a/.github/workflows/terraform-validate.yaml b/.github/workflows/terraform-validate.yaml index 72829d8..04b96db 100644 --- a/.github/workflows/terraform-validate.yaml +++ b/.github/workflows/terraform-validate.yaml @@ -1,42 +1,40 @@ -name: Terraform Validate +name: Terraform CI/CD on: - pull_request: workflow_dispatch: - + pull_request: + types: [closed] + branches: + - main jobs: - - terraform-validate: - runs-on: "229685449397" + 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@v2 + - name: Setup GITHUB Credentials + id: github_credentials + uses: CSVD/gh-auth@main with: - terraform_version: '1.7.3' - - - name: Validate Terraform Configuration - id: validate - uses: CSVD/terraform-validate@main + 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: Check Validation/Test Results - if: always() + - name: Setup GitHub CLI run: | - # Set default values if outputs are empty - IS_VALID="${{ steps.validate.outputs.is_valid }}" - TESTS_PASSED="${{ steps.validate.outputs.tests_passed }}" + # 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 - # If outputs are empty, set them to false - [ -z "$IS_VALID" ] && IS_VALID="false" - [ -z "$TESTS_PASSED" ] && TESTS_PASSED="false" + # Test GitHub CLI auth status + gh auth status || echo "GitHub CLI authentication failed" - 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 + - name: Run Release Action + uses: CSVD/releaser@main + with: + github-token: ${{ steps.github_credentials.outputs.github_token }} + working-directory: '.' diff --git a/README.md b/README.md index 824072e..2db996b 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,15 @@ Developer NOTE: We should automate this configuration. | [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_ecr_authorization_token.ecr_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | +| [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | 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 | |------|-------------|------|---------|:--------:| +| [account\_id](#input\_account\_id) | aws account number | `string` | `""` | no | | [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 | | [namespace](#input\_namespace) | The namespace into which tempo will be deployed | `string` | `"tempo"` | no | | [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN in the EKS cluster for the OpenID Connect identity provider. | `string` | n/a | yes | diff --git a/copy_images.tf b/copy_images.tf index fbb90ef..e62712f 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -1,5 +1,6 @@ locals { - tempo_key = format("%v#%v", "tempo", var.tempo_tag) + ent_ecr_source = format("%v.%v.%v.%v", var.account_id, "dkr.ecr", var.region, "amazonaws.com/ent-images") + tempo_key = format("%v#%v", "tempo", var.tempo_tag) image_config = [ { @@ -7,7 +8,7 @@ locals { dest_path = null name = "tempo" source_image = "bitnami/grafana-tempo" - source_registry = "public.ecr.aws" + source_registry = format("%v/%v", local.ent_ecr_source, "public-ecr") source_tag = var.tempo_tag tag = var.tempo_tag } @@ -25,5 +26,19 @@ module "images" { enable_lifecycle_policy = true lifecycle_policy_all = true force_delete = true - lifecycle_policy_keep_count = 3 + lifecycle_policy_keep_count = 5 + + source_username = data.aws_ecr_authorization_token.ecr_token.user_name + source_password = data.aws_ecr_authorization_token.ecr_token.password + + destination_username = data.aws_ecr_authorization_token.token.user_name + destination_password = data.aws_ecr_authorization_token.token.password +} + +data "aws_ecr_authorization_token" "ecr_token" { + registry_id = var.account_id +} + +data "aws_ecr_authorization_token" "token" { + registry_id = var.account_id } diff --git a/variables.tf b/variables.tf index ce7152f..bfc1d30 100644 --- a/variables.tf +++ b/variables.tf @@ -1,12 +1,7 @@ -variable "tags" { - description = "Additional tags to add to resources created in AWS (s3 bucket, ...)" - type = map(string) - default = {} -} - -variable "region" { - description = "The region holding these resources (for the s3 bucket.)" +variable "account_id" { + description = "aws account number" type = string + default = "" } variable "cluster_name" { @@ -14,12 +9,6 @@ variable "cluster_name" { type = string } -variable "profile" { - description = "AWS config profile used to upload images into ECR" - type = string - default = "" -} - variable "namespace" { description = "The namespace into which tempo will be deployed" type = string @@ -31,22 +20,22 @@ variable "oidc_provider_arn" { type = string } -variable "rwo_storage_class" { - description = "Specify the storage class for persistent volumes." +variable "profile" { + description = "AWS config profile used to upload images into ECR" type = string - default = "gp3-encrypted" + default = "" } -variable "tempo_chart_version" { - description = "Which version of the grafana/tempo helm chart to use." +variable "prometheus_namespace" { + description = "Namespace where Prometheus is installed." type = string - default = "1.10.3" + default = "prometheus" } -variable "tempo_tag" { - description = "The tag of the tempo image to use." +variable "prometheus_port" { + description = "Port number of Prometheus service, mostly either 80 or 9090" type = string - default = "2.5.0" + default = "80" } # Prometheus data for metrics generator @@ -56,14 +45,31 @@ variable "prometheus_svc" { default = "prometheus-server" } -variable "prometheus_namespace" { - description = "Namespace where Prometheus is installed." +variable "region" { + description = "The region holding these resources (for the s3 bucket.)" type = string - default = "prometheus" } -variable "prometheus_port" { - description = "Port number of Prometheus service, mostly either 80 or 9090" +variable "rwo_storage_class" { + description = "Specify the storage class for persistent volumes." type = string - default = "80" + default = "gp3-encrypted" +} + +variable "tags" { + description = "Additional tags to add to resources created in AWS (s3 bucket, ...)" + type = map(string) + default = {} +} + +variable "tempo_chart_version" { + description = "Which version of the grafana/tempo helm chart to use." + type = string + default = "1.10.3" +} + +variable "tempo_tag" { + description = "The tag of the tempo image to use." + type = string + default = "2.5.0" } From bc03cac33cd26ee77c5ebc49100b8f3a936f9109 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 17 Apr 2025 14:20:22 -0400 Subject: [PATCH 15/25] pull across accounts from central ecr --- README.md | 1 + copy_images.tf | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2db996b..451529d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Developer NOTE: We should automate this configuration. | Name | Version | |------|---------| | [aws](#provider\_aws) | >= 5.14.0 | +| [aws.eecr](#provider\_aws.eecr) | >= 5.14.0 | | [helm](#provider\_helm) | >= 2.11.0 | | [terraform](#provider\_terraform) | n/a | diff --git a/copy_images.tf b/copy_images.tf index e62712f..03acacb 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -36,7 +36,8 @@ module "images" { } data "aws_ecr_authorization_token" "ecr_token" { - registry_id = var.account_id + provider = aws.eecr + registry_id = var.eecr_account_id } data "aws_ecr_authorization_token" "token" { From 43d3a913f9c6cfcf1087e842be8715fb11a445d2 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 17 Apr 2025 19:35:24 -0400 Subject: [PATCH 16/25] fix ent_ecr_source --- copy_images.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copy_images.tf b/copy_images.tf index 03acacb..900c50a 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -1,5 +1,5 @@ locals { - ent_ecr_source = format("%v.%v.%v.%v", var.account_id, "dkr.ecr", var.region, "amazonaws.com/ent-images") + ent_ecr_source = format("%v.%v.%v.%v", var.eecr_account_id, "dkr.ecr", var.region, "amazonaws.com/ent-images") tempo_key = format("%v#%v", "tempo", var.tempo_tag) image_config = [ From 1dfe2a528beec7bc06799d3e84d2bd989502c217 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 17 Apr 2025 23:29:21 -0400 Subject: [PATCH 17/25] dynamic version --- README.md | 3 +++ version.tf | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 451529d..cf0f3d9 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Developer NOTE: We should automate this configuration. | [aws](#provider\_aws) | >= 5.14.0 | | [aws.eecr](#provider\_aws.eecr) | >= 5.14.0 | | [helm](#provider\_helm) | >= 2.11.0 | +| [null](#provider\_null) | >= 3.2.1 | | [terraform](#provider\_terraform) | n/a | ## Modules @@ -48,6 +49,8 @@ Developer NOTE: We should automate this configuration. | Name | Type | |------|------| | [helm_release.tempo](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | +| [null_resource.git_version](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.module_name](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | 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_ecr_authorization_token.ecr_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | diff --git a/version.tf b/version.tf index 7717186..39f03d8 100644 --- a/version.tf +++ b/version.tf @@ -1,4 +1,27 @@ +resource "null_resource" "git_version" { + triggers = { + # Force this to run on every apply to get the latest tag value + always_run = timestamp() + } + + provisioner "local-exec" { + command = "git describe --tags --abbrev=0 2>/dev/null || echo 'unknown' > ${path.module}/.git_tag" + on_failure = continue + } +} + +resource "null_resource" "module_name" { + triggers = { + module_path = path.module + } + + provisioner "local-exec" { + command = "basename $(pwd) > ${path.module}/.module_name" + on_failure = continue + } +} + locals { - module_name = "tfmod-tempo" - module_version = "0.1.1" + module_name = fileexists("${path.module}/.module_name") ? trimspace(file("${path.module}/.module_name")) : "tfmod-tempo" + module_version = fileexists("${path.module}/.git_tag") ? trimspace(file("${path.module}/.git_tag")) : "latest" } From dd1e20d0a9ab525835d970f809f678047412bc74 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 17 Apr 2025 23:59:51 -0400 Subject: [PATCH 18/25] add eecr_account_id --- README.md | 1 + variables.tf | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index cf0f3d9..153a1ad 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Developer NOTE: We should automate this configuration. |------|-------------|------|---------|:--------:| | [account\_id](#input\_account\_id) | aws account number | `string` | `""` | no | | [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 | +| [eecr\_account\_id](#input\_eecr\_account\_id) | enterpirse ecr source aws account number | `string` | `""` | no | | [namespace](#input\_namespace) | The namespace into which tempo will be deployed | `string` | `"tempo"` | no | | [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN in the EKS cluster for the OpenID Connect identity provider. | `string` | n/a | yes | | [profile](#input\_profile) | AWS config profile used to upload images into ECR | `string` | `""` | no | diff --git a/variables.tf b/variables.tf index bfc1d30..640cc7f 100644 --- a/variables.tf +++ b/variables.tf @@ -9,6 +9,12 @@ variable "cluster_name" { type = string } +variable "eecr_account_id" { + description = "enterpirse ecr source aws account number" + type = string + default = "" +} + variable "namespace" { description = "The namespace into which tempo will be deployed" type = string From b36c38a65f2386480cf51f93f8084f16708f4d32 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 18 Apr 2025 01:35:40 -0400 Subject: [PATCH 19/25] update image source --- copy_images.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/copy_images.tf b/copy_images.tf index 900c50a..8970535 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -7,8 +7,8 @@ locals { enabled = true dest_path = null name = "tempo" - source_image = "bitnami/grafana-tempo" - source_registry = format("%v/%v", local.ent_ecr_source, "public-ecr") + source_image = "opensource/grafana/tempo" + source_registry = format("%v/%v", local.ent_ecr_source, "ironbank") source_tag = var.tempo_tag tag = var.tempo_tag } From 43fb85d7eebd8e8ad6536144e47203187a8dd8cd Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 18 Apr 2025 14:58:04 -0400 Subject: [PATCH 20/25] remove eecr data item as it is in the provider --- README.md | 2 -- copy_images.tf | 5 ----- 2 files changed, 7 deletions(-) diff --git a/README.md b/README.md index 153a1ad..e9719ed 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ Developer NOTE: We should automate this configuration. | Name | Version | |------|---------| | [aws](#provider\_aws) | >= 5.14.0 | -| [aws.eecr](#provider\_aws.eecr) | >= 5.14.0 | | [helm](#provider\_helm) | >= 2.11.0 | | [null](#provider\_null) | >= 3.2.1 | | [terraform](#provider\_terraform) | n/a | @@ -53,7 +52,6 @@ Developer NOTE: We should automate this configuration. | [null_resource.module_name](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | 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_ecr_authorization_token.ecr_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | | [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | | [aws_s3_bucket.s3_server_access_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket) | data source | diff --git a/copy_images.tf b/copy_images.tf index 8970535..585b445 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -35,11 +35,6 @@ module "images" { destination_password = data.aws_ecr_authorization_token.token.password } -data "aws_ecr_authorization_token" "ecr_token" { - provider = aws.eecr - registry_id = var.eecr_account_id -} - data "aws_ecr_authorization_token" "token" { registry_id = var.account_id } From 45b1791afb2027b0364743d54986524af25d4670 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 18 Apr 2025 21:14:18 -0400 Subject: [PATCH 21/25] update copy images for eecr pulling --- README.md | 2 ++ copy_images.tf | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index e9719ed..153a1ad 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Developer NOTE: We should automate this configuration. | Name | Version | |------|---------| | [aws](#provider\_aws) | >= 5.14.0 | +| [aws.eecr](#provider\_aws.eecr) | >= 5.14.0 | | [helm](#provider\_helm) | >= 2.11.0 | | [null](#provider\_null) | >= 3.2.1 | | [terraform](#provider\_terraform) | n/a | @@ -52,6 +53,7 @@ Developer NOTE: We should automate this configuration. | [null_resource.module_name](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | 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_ecr_authorization_token.ecr_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | | [aws_ecr_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | | [aws_s3_bucket.s3_server_access_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/s3_bucket) | data source | diff --git a/copy_images.tf b/copy_images.tf index 585b445..833c076 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -38,3 +38,14 @@ module "images" { data "aws_ecr_authorization_token" "token" { registry_id = var.account_id } + +data "aws_ecr_authorization_token" "ecr_token" { + provider = aws.eecr + registry_id = var.eecr_info.account_id +} + +provider "aws" { + alias = "eecr" + profile = var.eecr_info.profile + region = var.eecr_info.region +} From 7be95bcae0e986f9eda0a17111199e66c84182e1 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Fri, 18 Apr 2025 21:33:24 -0400 Subject: [PATCH 22/25] update var and ent_ecr_source --- README.md | 2 +- copy_images.tf | 2 +- variables.tf | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 153a1ad..7cb2aba 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Developer NOTE: We should automate this configuration. |------|-------------|------|---------|:--------:| | [account\_id](#input\_account\_id) | aws account number | `string` | `""` | no | | [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 | -| [eecr\_account\_id](#input\_eecr\_account\_id) | enterpirse ecr source aws account number | `string` | `""` | no | +| [eecr\_info](#input\_eecr\_info) | Enterprise ECR source information |
object({
account_id = string
alias = string
profile = string
region = string
})
|
{
"account_id": "269222635945",
"alias": "lab-gov-shared-nonprod",
"profile": "269222635945-lab-gov-shared-nonprod",
"region": "us-gov-east-1"
}
| no | | [namespace](#input\_namespace) | The namespace into which tempo will be deployed | `string` | `"tempo"` | no | | [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN in the EKS cluster for the OpenID Connect identity provider. | `string` | n/a | yes | | [profile](#input\_profile) | AWS config profile used to upload images into ECR | `string` | `""` | no | diff --git a/copy_images.tf b/copy_images.tf index 833c076..c764b39 100644 --- a/copy_images.tf +++ b/copy_images.tf @@ -1,5 +1,5 @@ locals { - ent_ecr_source = format("%v.%v.%v.%v", var.eecr_account_id, "dkr.ecr", var.region, "amazonaws.com/ent-images") + ent_ecr_source = format("%v.%v.%v.%v", var.eecr_info.account_id, "dkr.ecr", var.region, "amazonaws.com/ent-images") tempo_key = format("%v#%v", "tempo", var.tempo_tag) image_config = [ diff --git a/variables.tf b/variables.tf index 640cc7f..dc41667 100644 --- a/variables.tf +++ b/variables.tf @@ -9,10 +9,20 @@ variable "cluster_name" { type = string } -variable "eecr_account_id" { - description = "enterpirse ecr source aws account number" - type = string - default = "" +variable "eecr_info" { + description = "Enterprise ECR source information" + type = object({ + account_id = string + alias = string + profile = string + region = string + }) + default = { + account_id = "269222635945" + alias = "lab-gov-shared-nonprod" + profile = "269222635945-lab-gov-shared-nonprod" + region = "us-gov-east-1" + } } variable "namespace" { From 8d0f7f08236c0334110c267ead0b2cdce244072c Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 21 Apr 2025 11:42:39 -0400 Subject: [PATCH 23/25] ensure workflows are current --- .github/workflows/terraform-release.yaml | 11 +++--- .github/workflows/terraform-validate.yaml | 6 ++-- terraform-release.yaml | 40 +++++++++++++++++++++ terraform-validate.yaml | 42 +++++++++++++++++++++++ 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 terraform-release.yaml create mode 100644 terraform-validate.yaml diff --git a/.github/workflows/terraform-release.yaml b/.github/workflows/terraform-release.yaml index 90910bc..a61d32d 100644 --- a/.github/workflows/terraform-release.yaml +++ b/.github/workflows/terraform-release.yaml @@ -1,4 +1,4 @@ -name: Terraform CI/CD +name: Terraform Module Release on: workflow_dispatch: pull_request: @@ -6,19 +6,18 @@ on: branches: - main jobs: - terraform-ci-cd: - runs-on: 229685449397 + terraform-release: + 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 + uses: CSVD/gh-actions-setup-terraform@v2 with: - terraform_version: "1.9.1" + terraform_version: '1.10.5' - name: Setup GITHUB Credentials id: github_credentials diff --git a/.github/workflows/terraform-validate.yaml b/.github/workflows/terraform-validate.yaml index 04b96db..1fc4848 100644 --- a/.github/workflows/terraform-validate.yaml +++ b/.github/workflows/terraform-validate.yaml @@ -1,4 +1,4 @@ -name: Terraform CI/CD +name: Terraform Module Validate on: workflow_dispatch: pull_request: @@ -6,8 +6,8 @@ on: branches: - main jobs: - terraform-ci-cd: - runs-on: 229685449397 + terraform-validate: + runs-on: "229685449397" permissions: contents: write diff --git a/terraform-release.yaml b/terraform-release.yaml new file mode 100644 index 0000000..3f67574 --- /dev/null +++ b/terraform-release.yaml @@ -0,0 +1,40 @@ +name: Terraform Module Release +on: + workflow_dispatch: + pull_request: + types: [closed] + branches: + - main +jobs: + terraform-release: + runs-on: "229685449397" + permissions: + contents: write + + steps: + - name: Checkout code + uses: CSVD/gh-actions-checkout@v4 + + - 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: 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: Run Release Action + uses: CSVD/releaser@main + with: + github-token: ${{ steps.github_credentials.outputs.github_token }} + working-directory: '.' diff --git a/terraform-validate.yaml b/terraform-validate.yaml new file mode 100644 index 0000000..ac349eb --- /dev/null +++ b/terraform-validate.yaml @@ -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.10.5' + + - 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 From a435173864aaf4269702484c6693e6732799bb5b Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Mon, 21 Apr 2025 15:43:18 -0400 Subject: [PATCH 24/25] ensure workflows are current --- .github/workflows/terraform-release.yaml | 38 ++--------------- .github/workflows/terraform-validate.yaml | 50 ++++++++++++----------- terraform-release.yaml | 40 ------------------ terraform-validate.yaml | 42 ------------------- 4 files changed, 29 insertions(+), 141 deletions(-) delete mode 100644 terraform-release.yaml delete mode 100644 terraform-validate.yaml diff --git a/.github/workflows/terraform-release.yaml b/.github/workflows/terraform-release.yaml index a61d32d..3f67574 100644 --- a/.github/workflows/terraform-release.yaml +++ b/.github/workflows/terraform-release.yaml @@ -10,15 +10,11 @@ jobs: 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.10.5' - - name: Setup GITHUB Credentials id: github_credentials uses: CSVD/gh-auth@main @@ -27,28 +23,6 @@ jobs: 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 @@ -59,14 +33,8 @@ jobs: # 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 + - name: Run Release Action + uses: CSVD/releaser@main with: github-token: ${{ steps.github_credentials.outputs.github_token }} working-directory: '.' diff --git a/.github/workflows/terraform-validate.yaml b/.github/workflows/terraform-validate.yaml index 1fc4848..ac349eb 100644 --- a/.github/workflows/terraform-validate.yaml +++ b/.github/workflows/terraform-validate.yaml @@ -1,40 +1,42 @@ -name: Terraform Module Validate +name: Terraform Validate on: - workflow_dispatch: pull_request: - types: [closed] - branches: - - main + workflow_dispatch: + jobs: + terraform-validate: runs-on: "229685449397" permissions: contents: write - steps: - name: Checkout code uses: CSVD/gh-actions-checkout@v4 - - name: Setup GITHUB Credentials - id: github_credentials - uses: CSVD/gh-auth@main + - name: Setup Terraform + uses: CSVD/gh-actions-setup-terraform@v2 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 }} + terraform_version: '1.10.5' + + - name: Validate Terraform Configuration + id: validate + uses: CSVD/terraform-validate@main - - name: Setup GitHub CLI + - name: Check Validation/Test Results + if: always() 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 + # Set default values if outputs are empty + IS_VALID="${{ steps.validate.outputs.is_valid }}" + TESTS_PASSED="${{ steps.validate.outputs.tests_passed }}" - # Test GitHub CLI auth status - gh auth status || echo "GitHub CLI authentication failed" + # If outputs are empty, set them to false + [ -z "$IS_VALID" ] && IS_VALID="false" + [ -z "$TESTS_PASSED" ] && TESTS_PASSED="false" - - name: Run Release Action - uses: CSVD/releaser@main - with: - github-token: ${{ steps.github_credentials.outputs.github_token }} - working-directory: '.' + 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 diff --git a/terraform-release.yaml b/terraform-release.yaml deleted file mode 100644 index 3f67574..0000000 --- a/terraform-release.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: Terraform Module Release -on: - workflow_dispatch: - pull_request: - types: [closed] - branches: - - main -jobs: - terraform-release: - runs-on: "229685449397" - permissions: - contents: write - - steps: - - name: Checkout code - uses: CSVD/gh-actions-checkout@v4 - - - 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: 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: Run Release Action - uses: CSVD/releaser@main - with: - github-token: ${{ steps.github_credentials.outputs.github_token }} - working-directory: '.' diff --git a/terraform-validate.yaml b/terraform-validate.yaml deleted file mode 100644 index ac349eb..0000000 --- a/terraform-validate.yaml +++ /dev/null @@ -1,42 +0,0 @@ -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.10.5' - - - 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 From 72b60846f918fcfd64dd3aa10f063b436ddeb844 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Tue, 22 Apr 2025 00:04:55 -0400 Subject: [PATCH 25/25] ensure committed --- README.md | 1 - version.tf | 13 +------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/README.md b/README.md index 7cb2aba..2b75d13 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,6 @@ Developer NOTE: We should automate this configuration. |------|------| | [helm_release.tempo](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | [null_resource.git_version](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.module_name](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | 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_ecr_authorization_token.ecr_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_authorization_token) | data source | diff --git a/version.tf b/version.tf index 39f03d8..27af354 100644 --- a/version.tf +++ b/version.tf @@ -10,18 +10,7 @@ resource "null_resource" "git_version" { } } -resource "null_resource" "module_name" { - triggers = { - module_path = path.module - } - - provisioner "local-exec" { - command = "basename $(pwd) > ${path.module}/.module_name" - on_failure = continue - } -} - locals { - module_name = fileexists("${path.module}/.module_name") ? trimspace(file("${path.module}/.module_name")) : "tfmod-tempo" + module_name = "tfmod-tempo" module_version = fileexists("${path.module}/.git_tag") ? trimspace(file("${path.module}/.git_tag")) : "latest" }