Skip to content

Commit

Permalink
pull from ent-ecr
Browse files Browse the repository at this point in the history
  • Loading branch information
morga471 committed Apr 14, 2025
1 parent a5e0e6f commit ae46088
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 81 deletions.
54 changes: 26 additions & 28 deletions .github/workflows/terraform-validate.yaml
Original file line number Diff line number Diff line change
@@ -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: '.'
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ resource "kubernetes_manifest" "example_grafana_datasource" {
| [helm_release.loki](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 |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | aws account number | `string` | `""` | no |
| <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_enterprise_logs_provisioner_tag"></a> [enterprise\_logs\_provisioner\_tag](#input\_enterprise\_logs\_provisioner\_tag) | The version of the grafana/enterprise-logs-provisioner image to use. | `string` | `"v1.7.0"` | no |
| <a name="input_exporter_tag"></a> [exporter\_tag](#input\_exporter\_tag) | The version of prom/memcached-exporter to use for the gateway. | `string` | `"v0.14.4"` | no |
Expand Down
42 changes: 24 additions & 18 deletions copy_images.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
locals {
ent_ecr_source = format("%v.%v.%v.%v", var.account_id, "dkr.ecr", var.region, "amazonaws.com/ent-images")
exporter_key = format("%v#%v", "prom/memcached-exporter", var.exporter_tag)
gateway_key = format("%v#%v", "grafana/nginx-unprivileged", var.gateway_tag)
loki_key = format("%v#%v", "grafana/loki", var.loki_tag)
Expand All @@ -12,7 +13,7 @@ locals {
dest_path = null
name = "grafana/loki"
source_image = "bitnami/grafana-loki"
source_registry = "public.ecr.aws"
source_registry = format("%v/%v", local.ent_ecr_source, "public-ecr")
source_tag = var.loki_tag
tag = var.loki_tag
},
Expand All @@ -21,7 +22,7 @@ locals {
dest_path = null
name = "memcached"
source_image = "bitnami/memcached"
source_registry = "public.ecr.aws"
source_registry = format("%v/%v", local.ent_ecr_source, "public-ecr")
source_tag = var.memcached_tag
tag = var.memcached_tag
},
Expand All @@ -30,7 +31,7 @@ locals {
dest_path = null
name = "prom/memcached-exporter"
source_image = "prom/memcached-exporter"
source_registry = "docker.io"
source_registry = format("%v/%v", local.ent_ecr_source, "docker")
source_tag = var.exporter_tag
tag = var.exporter_tag
},
Expand All @@ -39,7 +40,7 @@ locals {
dest_path = null
name = "kiwigrid/k8s-sidecar"
source_image = "kiwigrid/k8s-sidecar"
source_registry = "quay.io"
source_registry = format("%v/%v", local.ent_ecr_source, "quay")
source_tag = var.sidecar_tag
tag = var.sidecar_tag
},
Expand All @@ -48,7 +49,7 @@ locals {
dest_path = null
name = "grafana/enterprise-logs-provisioner"
source_image = "grafana/enterprise-logs-provisioner"
source_registry = "docker.io"
source_registry = format("%v/%v", local.ent_ecr_source, "docker")
source_tag = var.enterprise_logs_provisioner_tag
tag = var.enterprise_logs_provisioner_tag
},
Expand All @@ -57,7 +58,7 @@ locals {
dest_path = null
name = "grafana/nginx-unprivileged"
source_image = "nginx/nginx-unprivileged"
source_registry = "public.ecr.aws"
source_registry = format("%v/%v", local.ent_ecr_source, "public-ecr")
source_tag = var.gateway_tag
tag = var.gateway_tag
},
Expand All @@ -72,17 +73,22 @@ module "images" {
image_config = local.image_config
tags = {}

### optional
## account_alias = ""
## account_id = ""
## destination_password = ""
## destination_username = ""
## override_prefixes = {}
## region = ""
## source_password = ""
## source_username = ""
enable_lifecycle_policy = true
lifecycle_policy_all = true
force_delete = true
lifecycle_policy_keep_count = 5

enable_lifecycle_policy = true
lifecycle_policy_all = true
force_delete = true
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
}
75 changes: 40 additions & 35 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@

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" {
description = "EKS cluster name name component used through out the EKS cluster describing its purpose (ex: dice-dev)"
type = string
}

variable "profile" {
description = "AWS config profile used to upload images into ECR"
type = string
default = ""
}

variable "namespace" {
description = "The namespace into which grafana will be deployed"
variable "enterprise_logs_provisioner_tag" {
description = "The version of the grafana/enterprise-logs-provisioner image to use."
type = string
default = "loki"
default = "v1.7.0"
}

variable "oidc_provider_arn" {
description = "The ARN in the EKS cluster for the OpenID Connect identity provider."
variable "exporter_tag" {
description = "The version of prom/memcached-exporter to use for the gateway."
type = string
default = "v0.14.4"
}

variable "rwo_storage_class" {
description = "Specify the storage class for read/write/once persistent volumes."
variable "gateway_tag" {
description = "The version of nginxinc/nginx-unprivileged to use for the gateway."
type = string
default = "gp3-encrypted"
default = "1.25.2-alpine"
}

# helm add repo grafana "https://grafana.github.io/helm-charts"
Expand All @@ -53,32 +42,48 @@ variable "loki_tag" {
default = "3.1.1"
}

variable "enterprise_logs_provisioner_tag" {
description = "The version of the grafana/enterprise-logs-provisioner image to use."
variable "memcached_tag" {
description = "The version of memcached to use for the gateway."
type = string
default = "v1.7.0"
default = "1.6.23-alpine"
}

variable "gateway_tag" {
description = "The version of nginxinc/nginx-unprivileged to use for the gateway."
variable "namespace" {
description = "The namespace into which grafana will be deployed"
type = string
default = "1.25.2-alpine"
default = "loki"
}

variable "memcached_tag" {
description = "The version of memcached to use for the gateway."
variable "oidc_provider_arn" {
description = "The ARN in the EKS cluster for the OpenID Connect identity provider."
type = string
default = "1.6.23-alpine"
}

variable "exporter_tag" {
description = "The version of prom/memcached-exporter to use for the gateway."
variable "profile" {
description = "AWS config profile used to upload images into ECR"
type = string
default = "v0.14.4"
default = ""
}

variable "region" {
description = "The region holding these resources (for the s3 bucket.)"
type = string
}

variable "rwo_storage_class" {
description = "Specify the storage class for read/write/once persistent volumes."
type = string
default = "gp3-encrypted"
}

variable "sidecar_tag" {
description = "The version of kiwigrid/k8s-sidecar to use for the gateway."
type = string
default = "1.27.4"
}

variable "tags" {
description = "Additional tags to add to resources created in AWS (s3 bucket, ...)"
type = map(string)
default = {}
}

0 comments on commit ae46088

Please sign in to comment.