-
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.
- Loading branch information
Showing
10 changed files
with
498 additions
and
1 deletion.
There are no files selected for viewing
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,120 @@ | ||
| name: Package and Upload Terragrunt Configs | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| bootstrap: | ||
| description: 'Run bootstrap apply' | ||
| required: false | ||
| default: 'false' | ||
| type: choice | ||
| options: | ||
| - 'true' | ||
| - 'false' | ||
|
|
||
| env: | ||
| NODE_TLS_REJECT_UNAUTHORIZED: '0' | ||
| ACCOUNT_PROFILE_NAME: "lab-dev-gov" | ||
| CLUSTER_NAME: "csvd-platform-lab-mcm" | ||
| SOURCE_KEY: "platform-tg-infra.zip" | ||
| PIPELINE_PATH: "lab/development/us-gov-east-1/vpc/${CLUSTER_NAME}/eks-pipeline" | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| package-and-upload: | ||
| runs-on: [self-hosted, Linux, X64, buildkitsandbox] | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: etools/configure-aws-credentials@main | ||
| with: | ||
| aws-region: ${{ vars.AWS_REGION }} | ||
| role-to-assume: "arn:aws-us-gov:iam::${{ vars.AWS_ACCOUNT_ID }}:role/r-inf-terraform-eks" | ||
| role-skip-session-tagging: true | ||
|
|
||
| - name: Add profile credentials to ~/.aws/credentials | ||
| run: | | ||
| aws configure set aws_region ${{ vars.AWS_REGION }} --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| aws configure set aws_access_key_id ${{ env.AWS_ACCESS_KEY_ID }} --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| aws configure set aws_secret_access_key ${{ env.AWS_SECRET_ACCESS_KEY }} --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| aws configure set aws_session_token ${{ env.AWS_SESSION_TOKEN }} --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| aws sts get-caller-identity --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| - name: Package Terragrunt configs | ||
| run: | | ||
| # Create a zip file of the repository contents | ||
| zip -r platform-tg-infra.zip . -x "*.git*" "*.github*" "*.terragrunt-cache*" "*.terraform*" | ||
| # Calculate bucket name using the same format as in tfmod-pipeline/s3.tf | ||
| REGION_SHORT=$(echo ${{ vars.AWS_REGION }} | sed 's/\([a-z]\)[a-z]*-/\1/g') | ||
| SOURCE_BUCKET="inf-s3-${CLUSTER_NAME}-artifacts-${{ vars.AWS_ACCOUNT_ID }}-${REGION_SHORT}" | ||
| echo "SOURCE_BUCKET=${SOURCE_BUCKET}" >> $GITHUB_ENV | ||
| # Calculate the object key with the cluster-specific path | ||
| OBJECT_KEY="clusters/${CLUSTER_NAME}/platform-tg-infra.zip" | ||
| echo "OBJECT_KEY=${OBJECT_KEY}" >> $GITHUB_ENV | ||
| # Check if the source bucket exists, create it if it doesn't | ||
| if ! aws s3api head-bucket --bucket ${SOURCE_BUCKET} --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" 2>/dev/null; then | ||
| echo "Creating source bucket ${SOURCE_BUCKET}" | ||
| aws s3 mb s3://${SOURCE_BUCKET} --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" --region ${{ vars.AWS_REGION }} | ||
| # Configure bucket for versioning | ||
| aws s3api put-bucket-versioning --bucket ${SOURCE_BUCKET} \ | ||
| --versioning-configuration Status=Enabled \ | ||
| --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| # Block public access | ||
| aws s3api put-public-access-block --bucket ${SOURCE_BUCKET} \ | ||
| --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true \ | ||
| --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| # Create a flag file to indicate the bucket needs to be imported | ||
| echo "BUCKET_NEEDS_IMPORT=true" >> $GITHUB_ENV | ||
| else | ||
| echo "Bucket ${SOURCE_BUCKET} already exists" | ||
| fi | ||
| # Upload the zip file to S3 | ||
| aws s3 cp platform-tg-infra.zip s3://${SOURCE_BUCKET}/${OBJECT_KEY} \ | ||
| --profile "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" | ||
| echo "Uploaded platform-tg-infra.zip to s3://${SOURCE_BUCKET}/${OBJECT_KEY}" | ||
| - name: Make Import Script Executable | ||
| if: ${{ github.event.inputs.bootstrap == 'true' && env.BUCKET_NEEDS_IMPORT == 'true' }} | ||
| run: | | ||
| chmod +x scripts/import-s3-bucket.sh | ||
| - name: Bootstrap Pipeline (if requested) | ||
| if: ${{ github.event.inputs.bootstrap == 'true' }} | ||
| run: | | ||
| # If the bucket was just created, import it first | ||
| if [ "$BUCKET_NEEDS_IMPORT" = "true" ]; then | ||
| echo "Running import for newly created bucket $SOURCE_BUCKET" | ||
| ./scripts/import-s3-bucket.sh \ | ||
| "$SOURCE_BUCKET" \ | ||
| "${{ vars.AWS_REGION }}" \ | ||
| "${{ vars.AWS_ACCOUNT_ID }}-${{ env.ACCOUNT_PROFILE_NAME }}" \ | ||
| "$PIPELINE_PATH" | ||
| fi | ||
| # Now proceed with terragrunt apply | ||
| cd $PIPELINE_PATH | ||
| https_proxy=http://proxy.tco.census.gov:3128 \ | ||
| http_proxy=http://proxy.tco.census.gov:3128 \ | ||
| NO_PROXY=.census.gov,169.254.169.254,148.129.0.0/16,10.0.0.0/8,172.16.0/12,.eks.amazonaws.com,.s3.amazonaws.com,.amazonaws.com,.gcr.io,.pkg.dev \ | ||
| TERRAGRUNT_PROVIDER_CACHE=1 \ | ||
| terragrunt apply --terragrunt-non-interactive -auto-approve | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,72 @@ | ||
| version: 0.2 | ||
|
|
||
| env: | ||
| variables: | ||
| BASE_DIR: "lab" | ||
| TF_VERSION: "1.5.5" | ||
| TG_VERSION: "0.72.0" | ||
| TOOLS_DIR: "/tmp/build-tools" | ||
| exported-variables: | ||
| - TERRAGRUNT_PATH | ||
|
|
||
| cache: | ||
| paths: | ||
| - '/tmp/build-tools/**/*' | ||
|
|
||
| phases: | ||
| install: | ||
| runtime-versions: | ||
| python: 3.11 | ||
| commands: | ||
| - echo "Setting up environment and tools" | ||
| - export http_proxy=$PROXY_CONFIG | ||
| - export https_proxy=$PROXY_CONFIG | ||
| - export NO_PROXY=.census.gov,169.254.169.254,148.129.0.0/16,10.0.0.0/8,172.16.0/12,.eks.amazonaws.com,.s3.amazonaws.com,.amazonaws.com,.gcr.io,.pkg.dev | ||
|
|
||
| # Create tools directory if it doesn't exist | ||
| - mkdir -p $TOOLS_DIR/bin | ||
|
|
||
| # Check if cached Terraform exists and matches required version | ||
| - | | ||
| if [ -f "$TOOLS_DIR/bin/terraform" ] && [ "$($TOOLS_DIR/bin/terraform version | head -n1 | grep -o "v$TF_VERSION")" = "v$TF_VERSION" ]; then | ||
| echo "Using cached Terraform v$TF_VERSION" | ||
| else | ||
| echo "Downloading Terraform v$TF_VERSION" | ||
| curl -Lo /tmp/terraform.zip "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip" | ||
| unzip -o /tmp/terraform.zip -d $TOOLS_DIR/bin/ | ||
| chmod +x $TOOLS_DIR/bin/terraform | ||
| fi | ||
| # Check if cached Terragrunt exists and matches required version | ||
| - | | ||
| if [ -f "$TOOLS_DIR/bin/terragrunt" ] && [ "$($TOOLS_DIR/bin/terragrunt --version | grep -o "v$TG_VERSION")" = "v$TG_VERSION" ]; then | ||
| echo "Using cached Terragrunt v$TG_VERSION" | ||
| else | ||
| echo "Downloading Terragrunt v$TG_VERSION" | ||
| curl -Lo $TOOLS_DIR/bin/terragrunt "https://github.com/gruntwork-io/terragrunt/releases/download/v${TG_VERSION}/terragrunt_linux_amd64" | ||
| chmod +x $TOOLS_DIR/bin/terragrunt | ||
| fi | ||
| # Add tools to PATH | ||
| - export PATH=$TOOLS_DIR/bin:$PATH | ||
| - terraform --version | ||
| - terragrunt --version | ||
| - aws sts get-caller-identity | ||
|
|
||
| build: | ||
| commands: | ||
| - echo "Running Terragrunt apply" | ||
| - cd $TERRAGRUNT_PATH | ||
| - export http_proxy=$PROXY_CONFIG | ||
| - export https_proxy=$PROXY_CONFIG | ||
| - export NO_PROXY=.census.gov,169.254.169.254,148.129.0.0/16,10.0.0.0/8,172.16.0/12,.eks.amazonaws.com,.s3.amazonaws.com,.amazonaws.com,.gcr.io,.pkg.dev | ||
| - terragrunt run-all apply --terragrunt-non-interactive -auto-approve | ||
|
|
||
| post_build: | ||
| commands: | ||
| - echo "Terragrunt apply completed on `date`" | ||
|
|
||
| artifacts: | ||
| files: | ||
| - '**/*' | ||
| base-directory: '.' |
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,40 @@ | ||
| version: 0.2 | ||
|
|
||
| env: | ||
| variables: | ||
| TOOLS_DIR: "/tmp/build-tools" | ||
|
|
||
| cache: | ||
| paths: | ||
| - '/tmp/build-tools/**/*' | ||
|
|
||
| phases: | ||
| install: | ||
| runtime-versions: | ||
| python: 3.9 | ||
| commands: | ||
| - echo "Setting up security scanning tools" | ||
| - export http_proxy=$PROXY_CONFIG | ||
| - export https_proxy=$PROXY_CONFIG | ||
| - export NO_PROXY=.census.gov,169.254.169.254,148.129.0.0/16,10.0.0.0/8,172.16.0/12,.eks.amazonaws.com,.s3.amazonaws.com,.amazonaws.com,.gcr.io,.pkg.dev | ||
|
|
||
| # Install security scanning tools | ||
| - mkdir -p $TOOLS_DIR/bin | ||
| - pip install checkov -q | ||
| - pip install tfsec -q | ||
|
|
||
| build: | ||
| commands: | ||
| - echo "Running security scans" | ||
| - checkov --directory . --framework terraform --quiet --compact | ||
| - checkov --directory . --framework terragrunt --quiet --compact | ||
| - tfsec . --no-color | ||
|
|
||
| post_build: | ||
| commands: | ||
| - echo "Security scan completed on `date`" | ||
|
|
||
| artifacts: | ||
| files: | ||
| - '**/*' | ||
| base-directory: '.' |
Oops, something went wrong.