Skip to content

Terraform test #48

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

Open
wants to merge 38 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fb70b65
Merge pull request #1 from 2024-Iris/vpc
lvalentine6 May 20, 2025
cc3880b
refactor: add workflow for terraform plan
lvalentine6 May 23, 2025
8ecb6ee
Merge pull request #2 from 2024-Iris/terraform_plan
lvalentine6 May 23, 2025
034e028
fix: change branch name
lvalentine6 May 23, 2025
3a2b921
Merge pull request #3 from 2024-Iris/terraform_plan
lvalentine6 May 23, 2025
4d0551f
fix: change pr comment formating
lvalentine6 May 23, 2025
5b5dc20
Merge pull request #4 from 2024-Iris/terraform_plan
lvalentine6 May 23, 2025
103cf1a
fix: add AWS credentials, working directory
lvalentine6 May 23, 2025
3b22f20
Merge pull request #5 from 2024-Iris/terraform_plan
lvalentine6 May 23, 2025
c12a3a2
Merge pull request #46 from 2024-Iris/main
lvalentine6 May 23, 2025
a0de1c9
fix: change branch name
lvalentine6 May 23, 2025
e9e26e9
feat: add terraform files
lvalentine6 May 23, 2025
0bffd7f
fix: change working-directory
lvalentine6 May 23, 2025
95906a1
fix: add tee command
lvalentine6 May 23, 2025
4dc6a93
fix: change working directory
lvalentine6 May 23, 2025
4940d24
fix: add ls command
lvalentine6 May 23, 2025
e287f41
fix: add summary
lvalentine6 May 23, 2025
da0a99f
fix: fix output formatting
lvalentine6 May 23, 2025
c7c3b1a
fix: change artifact version
lvalentine6 May 23, 2025
4ba6671
fix: terraform code matching
lvalentine6 May 23, 2025
58c9a87
fix: terraform code matching
lvalentine6 May 23, 2025
6acf721
fix: terraform code matching
lvalentine6 May 23, 2025
af5f0a4
fix: terraform code matching
lvalentine6 May 23, 2025
1244c7e
fix: fix output
lvalentine6 May 23, 2025
c2f73d3
fix: change exit code
lvalentine6 May 23, 2025
c9c9f6e
fix: change exit code
lvalentine6 May 23, 2025
4e6ca7c
fix: hide exit code
lvalentine6 May 23, 2025
8454775
fix: remove pipefail
lvalentine6 May 23, 2025
39caa86
fix: change output formatting
lvalentine6 May 23, 2025
b10ec1b
fix: change result formatting
lvalentine6 May 23, 2025
ab8c378
refactor: use secret for AWS region configuration
lvalentine6 May 23, 2025
a25c52c
refactor: add plan summary
lvalentine6 May 23, 2025
28e22d5
feat: add terraform files
lvalentine6 May 23, 2025
cd6a163
fix: change exit_code return
lvalentine6 May 23, 2025
f3deb9d
fix: wrapper option false
lvalentine6 May 23, 2025
9237170
fix: rollback tee
lvalentine6 May 23, 2025
9b27fba
fix: rollback tee
lvalentine6 May 23, 2025
960751f
style: code sorting
lvalentine6 May 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/ecs_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to Amazon ECS

on:
push:
branches: [ "main" ]
branches: [ "test" ]

env:
AWS_REGION: ${{ secrets.AWS_REGION }}
Expand Down Expand Up @@ -33,6 +33,22 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.GH_ISSUEFY_ROY_TOKEN }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2

- name: Terraform Init
run: terraform init

- name: Terraform Apply
run: terraform apply -auto-approve

- name: Set up Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -72,13 +88,6 @@ jobs:
chmod +x gradlew
./gradlew clean build

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/terraform_plan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Terraform Plan on PR

on:
pull_request:
branches:
- test

permissions:
contents: read
pull-requests: write
issues: write

jobs:
terraform-plan:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.6.6
terraform_wrapper: false

- name: Terraform Init
run: terraform init
working-directory: ./terraform

- name: Terraform Plan and Capture Output
id: plan
working-directory: ./terraform
run: |
set +e
terraform plan -no-color -detailed-exitcode > >(tee plan_full.txt) 2> >(tee plan_full.txt >&2)
exit_code=$?
set -e

resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50)

plan_summary=$(grep -E '^Plan:' plan_full.txt)

echo "summary_output<<EOF" >> $GITHUB_OUTPUT
echo "$resource_summary" >> $GITHUB_OUTPUT
echo "$plan_summary" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

if [ "$exit_code" -eq 0 ]; then
echo "βœ… Terraform plan completed with no changes."
echo "plan_status=success" >> $GITHUB_OUTPUT
elif [ "$exit_code" -eq 2 ]; then
echo "βœ… Terraform plan completed with changes."
echo "plan_status=changes" >> $GITHUB_OUTPUT
elif [ "$exit_code" -eq 1 ]; then
echo "❌ Terraform plan failed with errors."
echo "plan_status=error" >> $GITHUB_OUTPUT
fi

exit 0

- name: Upload full plan as artifact
uses: actions/upload-artifact@v4
with:
name: terraform-plan
path: ./terraform/plan_full.txt

- name: Comment PR with Plan Summary
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## πŸ“„ Terraform Plan Summary

### πŸ’¬ λ³€κ²½ μš”μ•½
```terraform
${{ steps.plan.outputs.summary_output }}
```

### πŸ“Œ μƒνƒœ
${{ steps.plan.outputs.plan_status == 'error' && '❌ **μ‹€νŒ¨**: Terraform Plan 도쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.' || '' }}
${{ steps.plan.outputs.plan_status == 'changes' && 'πŸ”„ **변경사항 있음**: 적용 μ‹œ λ¦¬μ†ŒμŠ€ 변경이 λ°œμƒν•©λ‹ˆλ‹€.' || '' }}
${{ steps.plan.outputs.plan_status == 'success' && 'βœ… **λ³€κ²½ μ—†μŒ**: ν˜„μž¬ 인프라 μƒνƒœλŠ” μ΅œμ‹ μž…λ‹ˆλ‹€.' || '' }}

### πŸ“Ž μ°Έκ³ 
전체 Terraform Plan κ²°κ³ΌλŠ” [GitHub Actions Artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})μ—μ„œ ν™•μΈν•˜μ‹€ 수 μžˆμŠ΅λ‹ˆλ‹€.

- name: Fail job if plan failed
if: ${{ steps.plan.outputs.plan_status == 'error' }}
run: exit 1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ out/
/config.yml
/src/main/resources/logback.xml
docker-compose.yml

### terraform ###
.terraform/
*.tfstate
*.tfstate.*
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

@Data
public class LokiQueryAddRepositoryDto {
private String addRepositoryCount = "0";
private static final int COUNT_INDEX = 1;
private static final int FIRST_RESULT_INDEX = 0;
private String addRepositoryCount = "0";

@JsonProperty("data")
private void unpackData(Data data) {
Expand Down
Loading