Skip to content

Conversation

@2ghrms
Copy link
Member

@2ghrms 2ghrms commented Aug 24, 2025

🎯 κ°œμš”

Clokey ν”„λ‘œμ νŠΈμ˜ AWS 인프라λ₯Ό Terraform으둜 κ΄€λ¦¬ν•˜κΈ° μœ„ν•œ Infrastructure as Code 초기 ꡬ성을 μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

μ£Όμš” ꡬ성 μš”μ†Œ

  1. Bootstrap λͺ¨λ“ˆ (terraform/bootstrap/)
    S3 λ°±μ—”λ“œ 버킷: Terraform μƒνƒœ 파일 μ €μž₯μ†Œ
    버전 관리 ν™œμ„±ν™”
    AES256 μ„œλ²„ μ‚¬μ΄λ“œ μ•”ν˜Έν™”
    곡개 μ•‘μ„ΈμŠ€ 차단
    계정별 고유 버킷λͺ… (clokey-terraform-state-{account_id})
  2. μž¬μ‚¬μš© λͺ¨λ“ˆ (terraform/modules/)
    Network: VPC, μ„œλΈŒλ„·, λΌμš°νŒ… ν…Œμ΄λΈ”, Internet Gateway
    Compute: EC2 μΈμŠ€ν„΄μŠ€ ꡬ성
    Database: RDS MySQL μ„€μ •
    Storage: S3 버킷 ꡬ성
    Security: λ³΄μ•ˆ κ·Έλ£Ή 및 NACL
  3. ν™˜κ²½λ³„ μ„€μ • (terraform/env/)
    Dev ν™˜κ²½: 개발용 인프라 ꡬ성
    Prod ν™˜κ²½: ν”„λ‘œλ•μ…˜μš© 인프라 ꡬ성
    각 ν™˜κ²½λ³„ 독립적인 λ³€μˆ˜ 관리
  4. CI/CD νŒŒμ΄ν”„λΌμΈ (.github/workflows/)
    Dev ν™˜κ²½: main 브랜치 push μ‹œ μžλ™ 배포
    Prod ν™˜κ²½: GitHub Release 생성 μ‹œ μžλ™ 배포
    ν™˜κ²½λ³„ AWS 인증 정보 뢄리 관리

@2ghrms 2ghrms requested a review from yongjun0511 August 24, 2025 12:18
@2ghrms 2ghrms self-assigned this Aug 24, 2025
@2ghrms 2ghrms added the ✨ feature New feature or request label Aug 24, 2025
2ghrms added 24 commits August 27, 2025 02:34
- terraform fmt -recursive & terraform validate μ‹€ν–‰
- 배포 κ΄€λ ¨ 브랜치 μ„€λͺ… μ½”λ“œμ™€ μΌμΉ˜ν™”
- secret.tfvars 이외에 μ œμ™Έ
- tfvars κ΄€λ ¨ ignore 파일λͺ… μˆ˜μ •
- S3 λͺ¨λ“ˆ μΆ”κ°€ μ •μ˜
- vars에 environment  μΆ”κ°€
- S3 λͺ¨λ“ˆ μ‚¬μš©λ²• README μΆ”κ°€
- tfvars κ΄€λ ¨ ignore 파일λͺ… μˆ˜μ • ν›„ terraform.tfvars 반영됨
- tfvars κ΄€λ ¨ ignore 파일λͺ… μˆ˜μ • ν›„ terraform.tfvars 반영됨
- 각 λͺ¨λ“ˆ variable.tf에 purpose와 environment, tags μΆ”κ°€
- 각 λͺ¨λ“ˆ main.tf에 tags μ •μ˜
- compute, database 등에 적용
- volume size μž…λ ₯λ°›μŒ
- volume type μž…λ ₯λ°›μŒ
- public IP μ‚¬μš© μ—¬λΆ€ μž…λ ₯λ°›μŒ
- SSH ν‚€ μ£Όμž…
- was-userdata.sh둜 wsa용 userdata μ˜ˆμ‹œ μΆ”κ°€
- volume size μž…λ ₯λ°›μŒ
- volume type μž…λ ₯λ°›μŒ
- public IP μ‚¬μš© μ—¬λΆ€ μž…λ ₯λ°›μŒ
- SSH ν‚€ μ£Όμž…
- was-userdata.sh둜 wsa용 userdata μ˜ˆμ‹œ μΆ”κ°€
- engine_version, instance_class, publicly_accessible, backup_retention_period, parameter_group_name μΆ”κ°€
- variables.tf에 description μΆ”κ°€
- output.tf에 description μΆ”κ°€
- VPC, IGW, Route Tables -> 곡유 λ¦¬μ†ŒμŠ€μ— environment νƒœκ·Έ μ‚­μ œ
- compute.tf -> api μ„œλ²„ λͺ…μ‹œ
- κ°€μš©μ˜μ—­, μ„œλΈŒλ„· λΆ€λΆ„ ν•˜λ“œμ½”λ”©μœΌλ‘œ μˆ˜μ •
- EC2와 RDS의 λ³΄μ•ˆκ·Έλ£Ή 뢄리
- RDS λ³΄μ•ˆκ·Έλ£Ήμ— 3306 포트 μ—΄μ–΄λ‘ 
- νŒŒλΌλ―Έν„° κ·Έλ£Ή 적용
- ACM λͺ¨λ“ˆ μΆ”κ°€ (SSL μΈμ¦μ„œ 관리)
- ALB λͺ¨λ“ˆ μΆ”κ°€ (Application Load Balancer)
- dev/prod ν™˜κ²½μ— ACMκ³Ό ALB 적용
- CI μ›Œν¬ν”Œλ‘œμš° μ΅œμ ν™” (terraform plan λ³€μˆ˜ μ΅œμ†Œν™”)
- DB ID 톡일 ('clokey_db'둜 μ„€μ •)
- Route53 λͺ¨λ“ˆ κ°œμ„  (ALB alias λ ˆμ½”λ“œ 지원)
- λ³΄μ•ˆ κ°•ν™” (EC2λŠ” ALBλ₯Ό ν†΅ν•΄μ„œλ§Œ μ ‘κ·Ό κ°€λŠ₯)
- EC2 KeyPair 이름 문제 ν•΄κ²°
- MySQL 버전을 8.0.35 β†’ 8.0.34둜 λ³€κ²½
- μΈμ¦μ„œ 검증 νƒ€μž„μ•„μ›ƒμ„ 10λΆ„ β†’ 20λΆ„μœΌλ‘œ 증가
- Route53 λ ˆμ½”λ“œ μ˜μ‘΄μ„± λͺ…μ‹œμ  μΆ”κ°€
- S3 버킷 쀑볡 문제
- website_endpoint β†’ website_domain으둜 λ³€κ²½
- EC2 KeyPair, RDS MySQL 버전, S3 버킷 좩돌 문제 ν•΄κ²°
- ACM μΈμ¦μ„œ 검증 및 UserData λ‘œκΉ… κ°œμ„ 
- deprecated 속성 μˆ˜μ •
@github-actions
Copy link

πŸ“ Terraform Plan Result (dev)

data.aws_ami.ubuntu_latest: Reading...
data.aws_availability_zones.available: Reading...
data.aws_region.current: Reading...
data.aws_caller_identity.current: Reading...
module.vpc.aws_vpc.this: Refreshing state... [id=vpc-08274a8d95d833104]
module.rds.aws_db_parameter_group.main[0]: Refreshing state... [id=dev-clokey-rds-parameter-group]
module.route53_zone.aws_route53_zone.main[0]: Refreshing state... [id=Z09909261Y36ELN4EONUQ]
module.s3.aws_s3_bucket.this: Refreshing state... [id=dev-clokey-storage-bucket]
data.aws_region.current: Read complete after 0s [id=ap-northeast-2]
module.acm.aws_acm_certificate.main: Refreshing state... [id=arn:aws:acm:ap-northeast-2:594755789271:certificate/c9eb1c76-81f0-4b8f-86d2-edb6cb6c2b9d]
data.aws_caller_identity.current: Read complete after 0s [id=594755789271]
data.aws_availability_zones.available: Read complete after 0s [id=ap-northeast-2]
module.acm.aws_route53_record.cert_validation["dev.clokey.store"]: Refreshing state... [id=Z09909261Y36ELN4EONUQ__0260b097a295b57f4ae0d8641e81a9f0.dev.clokey.store._CNAME]
data.aws_ami.ubuntu_latest: Read complete after 1s [id=ami-0e87051b5808b3155]
module.igw.aws_internet_gateway.this: Refreshing state... [id=igw-0d42973fe78800938]
module.subnet_public_a.aws_subnet.this: Refreshing state... [id=subnet-07166b82e397cee4f]
module.route_table_private.aws_route_table.this: Refreshing state... [id=rtb-0dcf39427dd9230eb]
module.subnet_public_c.aws_subnet.this: Refreshing state... [id=subnet-0d2ffedf584e19b7d]
module.route_table_public.aws_route_table.this: Refreshing state... [id=rtb-0159c824cca7c72af]
module.subnet_private_a.aws_subnet.this: Refreshing state... [id=subnet-04ce95e006ceee275]
module.sg_alb.aws_security_group.this: Refreshing state... [id=sg-03c4902cb0070a409]
module.alb.aws_lb_target_group.main: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-2:594755789271:targetgroup/dev-clokey-tg/acdb9eb824fd28d1]
module.subnet_private_c.aws_subnet.this: Refreshing state... [id=subnet-03a06747bd201f93c]
module.subnet_public_c.aws_route_table_association.this: Refreshing state... [id=rtbassoc-03f129f95d0b98be3]
module.route_table_public.aws_route.igw[0]: Refreshing state... [id=r-rtb-0159c824cca7c72af1080289494]
module.subnet_public_a.aws_route_table_association.this: Refreshing state... [id=rtbassoc-0dfdf6960a97bd93f]
module.s3.aws_s3_bucket_public_access_block.this[0]: Refreshing state... [id=dev-clokey-storage-bucket]
module.s3.aws_s3_bucket_server_side_encryption_configuration.this[0]: Refreshing state... [id=dev-clokey-storage-bucket]
module.s3.aws_s3_bucket_versioning.this[0]: Refreshing state... [id=dev-clokey-storage-bucket]
module.sg_ec2.aws_security_group.this: Refreshing state... [id=sg-0e3ddb785c09b7bd3]
module.alb.aws_lb.main: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-2:594755789271:loadbalancer/app/dev-clokey-alb/ec4b17bfa9ed77c4]
module.subnet_private_a.aws_route_table_association.this: Refreshing state... [id=rtbassoc-0e31c0af0ad13396e]
module.subnet_private_c.aws_route_table_association.this: Refreshing state... [id=rtbassoc-006e064dc70761fdf]
module.rds.aws_db_subnet_group.this: Refreshing state... [id=dev-clokey-rds]
module.sg_rds.aws_security_group.this: Refreshing state... [id=sg-0bc8567a3bd82199a]
module.ec2.aws_instance.this: Refreshing state... [id=i-016b6771c91fc84c9]
module.rds.aws_db_instance.this: Refreshing state... [id=db-NWBD7HN3KUUHLNNYX5IOSDHIDI]
module.alb.aws_lb_listener.http[0]: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-2:594755789271:listener/app/dev-clokey-alb/ec4b17bfa9ed77c4/eba8266a9e8816e9]
module.route53_record.aws_route53_record.alias[0]: Refreshing state... [id=Z09909261Y36ELN4EONUQ_dev.dev.clokey.store_A]
aws_lb_target_group_attachment.ec2: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-2:594755789271:targetgroup/dev-clokey-tg/acdb9eb824fd28d1-20251013183202550200000002]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:

  # module.ec2.aws_instance.this has changed
  ~ resource "aws_instance" "this" {
        id                                   = "i-016b6771c91fc84c9"
        tags                                 = {
            "Name" = "dev-clokey-api"
        }
        # (40 unchanged attributes hidden)

      ~ root_block_device {
          + tags                  = {}
            # (10 unchanged attributes hidden)
        }

        # (7 unchanged blocks hidden)
    }


Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

─────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.ec2.aws_instance.this will be updated in-place
  ~ resource "aws_instance" "this" {
        id                                   = "i-016b6771c91fc84c9"
        tags                                 = {
            "Name" = "dev-clokey-api"
        }
      ~ user_data_replace_on_change          = true -> false
        # (39 unchanged attributes hidden)

        # (8 unchanged blocks hidden)
    }

  # module.rds.aws_db_parameter_group.main[0] will be updated in-place
  ~ resource "aws_db_parameter_group" "main" {
        id           = "dev-clokey-rds-parameter-group"
        name         = "dev-clokey-rds-parameter-group"
        tags         = {
            "Name" = "dev-clokey-rds-parameter-group"
        }
        # (6 unchanged attributes hidden)

      - parameter {
          - apply_method = "pending-reboot" -> null
          - name         = "innodb_buffer_pool_size" -> null
          - value        = "{DBInstanceClassMemory*3/4}" -> null
        }
      + parameter {
          + apply_method = "immediate"
          + name         = "innodb_buffer_pool_size"
          + value        = "{DBInstanceClassMemory*3/4}"
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

Warning: Value for undeclared variable

The root module does not declare a variable named "vpc_cidr_block" but a
value was found in file "terraform.tfvars". If you meant to use this value,
add a "variable" block to the configuration.

To silence these warnings, use TF_VAR_... environment variables to provide
certain "global" settings to all configurations in your organization. To
reduce the verbosity of these warnings, use the -compact-warnings option.

Warning: Value for undeclared variable

The root module does not declare a variable named "public_subnet_cidr" but a
value was found in file "terraform.tfvars". If you meant to use this value,
add a "variable" block to the configuration.

To silence these warnings, use TF_VAR_... environment variables to provide
certain "global" settings to all configurations in your organization. To
reduce the verbosity of these warnings, use the -compact-warnings option.

Warning: Values for undeclared variables

In addition to the other similar warnings shown, 3 other variable(s) defined
without being declared.

Warning: Deprecated attribute

  on ../../modules/storage/s3/output.tf line 33, in output "bucket_website_endpoint":
  33:   value       = aws_s3_bucket.this.website_domain

The attribute "website_domain" is deprecated. Refer to the provider
documentation for details.

─────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

@2ghrms 2ghrms merged commit d784b17 into dev Oct 13, 2025
1 check passed
@2ghrms 2ghrms deleted the feature/init branch October 13, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants