23.06.15
DEVOTEE를 활성화 시키면
지금 작성한 커뮤니티 글에 대해 1개의 댓글을 달아줍니다.
버튼을 누르면 글 수정 시 ChatGPT가 작성한 댓글이 수정됩니다.
| 컨텐츠 유형 | 제목 | 저장일 | 삭제 |
|---|
본인인증 로그인에 실패하였습니다.
회원이 아니시거나 본인인증 등록이
완료되지 않은 사용자입니다.
Terraform SQS의 파일 구조는 다음과 같다.
위와 같은 구조로 파일을 구성하고, 실제 코드를 확인해 보자.
provider "aws" {
region = var.AWS_REGION
profile = var.PROFILE
shared_credentials_file = var.CREDENTIAL_FILES
}
variable "AWS_REGION" {
default = "ap-northeast-2"
}
variable "PROFILE" {
description = "This is an aws profile for shared credentials file"
default = "terraform_user"
}
variable "CREDENTIAL_FILES" {
description = "This is a path of credentials file"
default = "/Users/kido/.aws/credentials"
}
resource "aws_sqs_queue" "my_todo2" {
name = var.SQS_NAME
delay_seconds = var.DELAY_SEC
max_message_size = var.MAX_MESSAGE_SIZE
visibility_timeout_seconds = var.VISIBILITY_TIMEOUT_SECONDS
message_retention_seconds = var.MESSAGE_RETENTION_SECONDS
receive_wait_time_seconds = var.RECEIVE_WAIT_TIME_SECONDS
fifo_queue = var.FIFO_QUEUE
content_based_deduplication = var.CONTENT_BASED_DEDUPLICATION
}
variable "SQS_NAME" {
description = "This is sqs name to be created"
default = "my-todo2"
}
variable "DELAY_SEC" {
description = "대기열의 모슨 메시지 배달이 지연되는 시간 (초) 기본은 0, 0 ~ 900 까지 가능"
type = number
default = 0
}
variable "MAX_MESSAGE_SIZE" {
description = "메시지가 리젝되기 전에 가질 수 있는 바이트 수, 1024 ~ 262144 바이트까지 가능, 기본값 = 262144"
type = number
default = 262144
}
variable "MESSAGE_RETENTION_SECONDS" {
description = "SQS가 메시지를 보관하는 시간, 60초 ~ 1209600 (14일), 기본값 345600 (4일)"
type = number
default = 345600
}
variable "RECEIVE_WAIT_TIME_SECONDS" {
description = "ReceiveMessage 호출이 반환되기 전에 메시지가 도착하기를 기다리는 시간, 0 ~ 20초 사이"
type = number
default = 0
}
variable "VISIBILITY_TIMEOUT_SECONDS" {
description = "큐에서 가시성 타임아웃, 0 에서 43200 (12 hours)"
type = number
default = 30
}
variable "FIFO_QUEUE" {
description = "FIFO Queue 를 만들지 여부"
type = bool
default = false
}
variable "CONTENT_BASED_DEDUPLICATION" {
description = "FIFO 큐에서 컨텐츠 기반의 중복 제거를 활성화 할지 여부"
type = bool
default = false
}
resource "aws_sqs_queue_policy" "my_sqs_to_test_policy" {
queue_url = aws_sqs_queue.my_todo2.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "sqspolicy",
"Statement": [
{
"Sid": "First",
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "${aws_sqs_queue.my_todo2.arn}"
}
]
}
POLICY
}
output "sqs_queue_id" {
description = "SQS URL을 반환한다."
value = aws_sqs_queue.my_todo2.id
}
output "sqs_queue_name" {
description = "SQS Queue 의 이름"
value = aws_sqs_queue.my_todo2.name
}
terraform init
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v3.53.0... - Installed hashicorp/aws v3.53.0 (self-signed, key ID 34365D9472D7468F) Partner and community providers are signed by their developers. If you'd like to know more about provider signing, you can read about it here: https://www.terraform.io/docs/cli/plugins/signing.html 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 apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_sqs_queue.my_sqs_to_test will be created
+ resource "aws_sqs_queue" "my_sqs_to_test" {
+ arn = (known after apply)
+ content_based_deduplication = false
+ deduplication_scope = (known after apply)
+ delay_seconds = 0
+ fifo_queue = false
+ fifo_throughput_limit = (known after apply)
+ id = (known after apply)
+ kms_data_key_reuse_period_seconds = (known after apply)
+ max_message_size = 262144
+ message_retention_seconds = 345600
+ name = "my-todo2"
+ name_prefix = (known after apply)
+ policy = (known after apply)
+ receive_wait_time_seconds = 0
+ tags_all = (known after apply)
+ url = (known after apply)
+ visibility_timeout_seconds = 30
}
# aws_sqs_queue_policy.my_sqs_to_test_policy will be created
+ resource "aws_sqs_queue_policy" "my_sqs_to_test_policy" {
+ id = (known after apply)
+ policy = (known after apply)
+ queue_url = (known after apply)
}
Plan: 2 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ sqs_queue_id = (known after apply)
+ sqs_queue_name = "my-todo2"
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_sqs_queue.my_sqs_to_test: Creating...
aws_sqs_queue.my_sqs_to_test: Creation complete after 0s [id=https://sqs.ap-northeast-2.amazonaws.com/103946/my-todo2]
aws_sqs_queue_policy.my_sqs_to_test_policy: Creating...
aws_sqs_queue_policy.my_sqs_to_test_policy: Creation complete after 0s [id=https://sqs.ap-northeast-2.amazonaws.com/10336/my-todo2]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
sqs_queue_id = "https://sqs.ap-northeast-2.amazonaws.com/103346/my-todo2"
sqs_queue_name = "my-todo2"
yes를 입력하고 엔터를 치면 AWS에 SQS가 생성이 된다.
참고로 우리가 outputs.tf 파일에 지정한 출력 정보가 그대로 출력된 것을 확인할 수 있다.
실제 콘솔에 들어가서 살펴보면 방금 생성한 sqs를 확인할 수 있다.
terraform.tfstate 파일은 생성된 리소스에 대한 상태 정보를 가지고 있다. 이 정보를 버젼 관리하여 테라폼의 변경을 컨트롤 할 수 있다.
terraform destroy
DEVOTEE를 활성화 시키면
지금 작성한 댓글에 AI가 댓글을 달아줍니다.