Skip to content

Commit

Permalink
Update terraform-apply.yml
Browse files Browse the repository at this point in the history
we need to make sure that the correct IDs are passed on to subsequent calls
  • Loading branch information
mihai-satmarean authored Dec 5, 2024
1 parent 2552eed commit 978c3ac
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,46 @@ jobs:
run: |
cd terraform/terraform-modules/tf-ec2-module/
terraform refresh
# Step 7: Validate Resources with AWS CLI
- name: List Resources Created by Terraform
# Step 7: Capture Terraform Outputs to Variables
- name: Capture Terraform Outputs
id: terraform_outputs
run: |
cd terraform/terraform-modules/tf-ec2-module/
# Capture Terraform output variables
VPC_ID=$(terraform output -raw vpc_id)
PUBLIC_SUBNET_ID=$(terraform output -raw public_subnet_id)
PRIVATE_SUBNET_ID=$(terraform output -raw private_subnet_id)
SECURITY_GROUP_ID=$(terraform output -raw security_group_id)
export VPC_ID=$(terraform output -raw vpc_id)
export PUBLIC_SUBNET_ID=$(terraform output -raw public_subnet_id)
export PRIVATE_SUBNET_ID=$(terraform output -raw private_subnet_id)
export SECURITY_GROUP_ID=$(terraform output -raw security_group_id)
echo "VPC_ID=$VPC_ID" >> $GITHUB_ENV
echo "PUBLIC_SUBNET_ID=$PUBLIC_SUBNET_ID" >> $GITHUB_ENV
echo "PRIVATE_SUBNET_ID=$PRIVATE_SUBNET_ID" >> $GITHUB_ENV
echo "SECURITY_GROUP_ID=$SECURITY_GROUP_ID" >> $GITHUB_ENV
# Print and List VPC
# Step 8: Validate Resources with AWS CLI
- name: List Resources Created by Terraform
run: |
# List VPC
echo "Listing VPC with ID: $VPC_ID"
aws ec2 describe-vpcs --vpc-ids $VPC_ID || echo "Failed to list VPC with ID: $VPC_ID"
# Print and List Public Subnet
# List Public Subnet
echo "Listing Public Subnet with ID: $PUBLIC_SUBNET_ID"
aws ec2 describe-subnets --subnet-ids $PUBLIC_SUBNET_ID || echo "Failed to list Public Subnet with ID: $PUBLIC_SUBNET_ID"
# Print and List Private Subnet
# List Private Subnet
echo "Listing Private Subnet with ID: $PRIVATE_SUBNET_ID"
aws ec2 describe-subnets --subnet-ids $PRIVATE_SUBNET_ID || echo "Failed to list Private Subnet with ID: $PRIVATE_SUBNET_ID"
# Print and List Security Group
# List Security Group
echo "Listing Security Group with ID: $SECURITY_GROUP_ID"
aws ec2 describe-security-groups --group-ids $SECURITY_GROUP_ID || echo "Failed to list Security Group with ID: $SECURITY_GROUP_ID"
# Step 8: Destroy Infrastructure
# Step 9: Destroy Infrastructure
- name: Destroy Infrastructure
run: |
cd terraform/terraform-modules/tf-ec2-module/
terraform destroy -auto-approve
# Step 9: Verify Resources are Destroyed (Optional)
# Step 10: Verify Resources are Destroyed
- name: Verify Resources are Destroyed
run: |
# Verify that resources were destroyed by listing them again
Expand Down

0 comments on commit 978c3ac

Please sign in to comment.