Skip to content

Updated code to use S3 bucket name and AWS region from GitHub secrets #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 31, 2025

Conversation

hadagalikarthik
Copy link
Contributor

@hadagalikarthik hadagalikarthik commented Mar 30, 2025

New changes:

  1. Added GitHub secrets for AWS_S3_BUCKET_NAME and AWS_REGION and declared them as environment variables in workflow file
    TF_VAR_AWS_S3_BUCKET_NAME: ${{ secrets.TF_VAR_AWS_S3_BUCKET_NAME }}
    TF_VAR_AWS_REGION: ${{ secrets.TF_VAR_AWS_REGION }}

  2. Initialized backend code for those variables in workflow file under jobs wherever required, instead of declaring them in backend.tf to remove redunduncy

  • name: Terraform Init
    run: |
    terraform init
    -backend-config="bucket=${{ secrets.TF_VAR_AWS_S3_BUCKET_NAME }}"
    -backend-config="region=${{ secrets.TF_VAR_AWS_REGION }}"
  1. Defined AWS_REGION and AWS_S3_BUCKET_NAME in variables.tf under folders wherever required

  2. Updated "bucket" and "region" variables in data.tf to use values declared in GitHub secrets

config = {
bucket = var.AWS_S3_BUCKET_NAME # Your S3 bucket name
region = var.AWS_REGION # AWS region
}

  1. Replaced "tf_state_bucket" variable with "AWS_S3_BUCKET_NAME" and "aws_region" with "AWS_REGION" in S3 folder

  2. Updated variable "azs" with "local.azs" and made it dynamic to build the AZ list based on region in "infra" folder
    Note :- We might need to add a note in our readme highlighting users need to use region where atleast two availability zones are supported

  3. Replaced "var.azs" with "local.azs" in outputs.tf and network.tf under "infra" folder

  4. "aws_region" and "azs" are no longer needed to be declared in infra->terraform.tfvars

  5. Commented out "unique_bucket_name" variable, since we cannot use this in other references once we start using S3 bucket name from GitHub secrets

Please refer below pipelines for more information.
Deploy -> https://github.com/hadagalikarthik/nginx_automation_examples/actions/runs/14154048262
Destroy -> https://github.com/hadagalikarthik/nginx_automation_examples/actions/runs/14154356076

Below attached screenshot of my GitHub secrets.
Screenshot 2025-03-30 at 14 44 38

@akananth akananth merged commit 91ae7ba into f5devcentral:main Mar 31, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants