Updated code to use S3 bucket name and AWS region from GitHub secrets #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New changes:
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 }}
Initialized backend code for those variables in workflow file under jobs wherever required, instead of declaring them in backend.tf to remove redunduncy
run: |
terraform init
-backend-config="bucket=${{ secrets.TF_VAR_AWS_S3_BUCKET_NAME }}"
-backend-config="region=${{ secrets.TF_VAR_AWS_REGION }}"
Defined AWS_REGION and AWS_S3_BUCKET_NAME in variables.tf under folders wherever required
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
}
Replaced "tf_state_bucket" variable with "AWS_S3_BUCKET_NAME" and "aws_region" with "AWS_REGION" in S3 folder
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
Replaced "var.azs" with "local.azs" in outputs.tf and network.tf under "infra" folder
"aws_region" and "azs" are no longer needed to be declared in infra->terraform.tfvars
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.
