34. Terraform을 사용하여 S3에 데이터 복사

발행: (2026년 2월 1일 오전 11:30 GMT+9)
6 min read
원문: Dev.to

Source: Dev.to

위에 제공된 소스 링크만으로는 번역할 본문이 포함되어 있지 않습니다. 번역을 원하는 전체 텍스트(마크다운 형식 포함)를 알려주시면 한국어로 번역해 드리겠습니다.

Lab Information

Nautilus DevOps 팀은 현재 데이터 마이그레이션을 수행하고 있으며, 온‑프레미스 스토리지 시스템에서 AWS S3 버킷으로 데이터를 이동하고 있습니다. 기존 S3 버킷에 복사해야 할 파일을 받았습니다.

  • Bucket name: datacenter-cp-13069 (already exists)
  • File to copy: /tmp/datacenter.txt
  • Terraform working directory: /home/bob/terraform

Note: In VS Code, right‑click under the EXPLORER section and select Open in Integrated Terminal to launch the terminal.

main.tf

resource "aws_s3_bucket" "my_bucket" {
  bucket = "datacenter-cp-13069"
  acl    = "private"

  tags = {
    Name = "datacenter-cp-13069"
  }
}

# Upload file to S3 bucket
resource "aws_s3_object" "upload_file" {
  bucket = aws_s3_bucket.my_bucket.bucket
  key    = "datacenter.txt"
  source = "/tmp/datacenter.txt"
  etag   = filemd5("/tmp/datacenter.txt")
}

소스 파일 확인

ls -l /tmp/datacenter.txt

출력

bob@iac-server ~/terraform via 💠 default ➜  ls -l /tmp/datacenter.txt 
-rw-rw-r-- 1 bob bob 27 Nov  8 15:11 /tmp/datacenter.txt

Terraform 초기화

cd /home/bob/terraform
terraform init

출력

bob@iac-server ~/terraform via 💠 default ➜  terraform init
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "5.91.0"...
- Installing hashicorp/aws v5.91.0...
- Installed hashicorp/aws v5.91.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

실행 계획 검토

terraform plan

출력

bob@iac-server ~/terraform via 💠 default ✖ terraform plan
aws_s3_bucket.my_bucket: Refreshing state... [id=datacenter-cp-13069]

Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_s3_object.upload_file will be created
  + resource "aws_s3_object" "upload_file" {
      + acl                    = (known after apply)
      + arn                    = (known after apply)
      + bucket                 = "datacenter-cp-13069"
      + bucket_key_enabled     = (known after apply)
      + checksum_crc32         = (known after apply)
      + checksum_crc32c        = (known after apply)
      + checksum_crc64nvme     = (known after apply)
      + checksum_sha1          = (known after apply)
      + checksum_sha256        = (known after apply)
      + content_type           = (known after apply)
      + etag                   = "628f77ec27c0e6eb1e0c6543cc3dd865"
      + force_destroy          = false
      + id                     = (known after apply)
      + key                    = "datacenter.txt"
      + kms_key_id             = (known after apply)
      + server_side_encryption = (known after apply)
      + source                 = "/tmp/datacenter.txt"
      + storage_class          = (known after apply)
      + tags_all               = (known after apply)
      + version_id             = (known after apply)
    }

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

│ Warning: Argument is deprecated

│   with aws_s3_bucket.my_bucket,
│   on main.tf line 3, in resource "aws_s3_bucket" "my_bucket":
│    3:   acl    = "private"

│ acl is deprecated. Use the aws_s3_bucket_acl resource instead.

│ (and one more similar warning elsewhere)


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

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.

변경 적용

terraform apply

프롬프트가 표시되면 객체 생성을 확인하기 위해 yes 를 입력하세요.

출력

bob@iac-server ~/terraform via 💠 default ➜  terraform apply
aws_s3_bucket.my_bucket: Refreshing state... [id=datacenter-cp-13069]

Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_s3_object.upload_file will be created
  + resource "aws_s3_object" "upload_file" {
      + acl                    = (known after apply)
      + arn                    = (known after apply)
      + bucket                 = "datacenter-cp-13069"
      + bucket_key_enabled     = (known after apply)
      + checksum_crc32         = (known after apply)
      + checksum_crc32c        = (known after apply)
      + checksum_crc64nvme     = (known after apply)
      + checksum_sha1          = (known after apply)
      + checksum_sha256        = (known after apply)
      + content_type           = (known after apply)
      + etag                   = "628f77ec27c0e6eb1e0c6543cc3dd865"
      + force_destroy          = false
      + id                     = (known after apply)
      + key                    = "datacenter.txt"
      + kms_key_id             = (known after apply)
      + server_side_encryption = (known after apply)
      + source                 = "/tmp/datacenter.txt"
      + storage_class          = (known after apply)
      + tags_all               = (known after apply)
      + version_id             = (known after apply)
    }

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

│ Warning: Argument is deprecated

│   with aws_s3_bucket.my_bucket,
│   on main.tf line 3, in resource "aws_s3_bucket" "my_bucket":
│    3:   acl    = "private"

│ acl is deprecated. Use the aws_s3_bucket_acl resource instead.

결과: 파일 /tmp/datacenter.txt 가 이제 Terraform을 사용하여 S3 버킷 datacenter-cp-13069datacenter.txt 로 업로드되었습니다.

line 3, in resource "aws_s3_bucket" "my_bucket":
│    3:   acl    = "private"

│ acl is deprecated. Use the aws_s3_bucket_acl resource instead.

│ (and one more similar warning elsewhere)


Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_s3_object.upload_file: Creating...
aws_s3_object.upload_file: Creation complete after 0s [id=datacenter.txt]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

리소스 및 다음 단계

  • 📦 전체 코드 저장소: KodeKloud Learning Labs
  • 📖 추가 심층 탐구: Whispering Cloud Insights – 다른 기술 기사 읽기
  • 💬 토론 참여: DEV Community – 생각과 질문을 공유하세요
  • 💼 연결하기: LinkedIn – 여러분과 연결하고 싶습니다

크레딧

  • 모든 실습은 KodeKloud에서 제공됩니다
  • 이 귀중한 리소스를 제공해 주셔서 진심으로 감사드립니다.
Back to Blog

관련 글

더 보기 »