### Running Terraform Commands for SQS Queue Example (Bash) Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/examples/complete/README.md This snippet provides the standard `terraform` commands required to initialize, plan, and apply the AWS SQS queue configurations defined in this example. It sets up the necessary providers and modules, previews the changes, and then provisions the resources in AWS. Users should run `terraform destroy` when resources are no longer needed to avoid costs. ```bash $ terraform init $ terraform plan $ terraform apply ``` -------------------------------- ### Subscribing an SQS Queue to an SNS Topic with Terraform Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/README.md This example demonstrates how to integrate an SQS queue with an SNS topic, allowing messages published to the SNS topic to be delivered to the SQS queue. It involves configuring both the SNS topic policy to allow SQS subscription and the SQS queue policy to permit messages from the SNS topic. The `sns` module creates the topic, and the `sqs` module creates the queue and its policy. ```HCL module "sns" { source = "terraform-aws-modules/sns/aws" version = ">= 5.0" name = "pub-sub" topic_policy_statements = { sqs = { sid = "SQSSubscribe" actions = [ "sns:Subscribe", "sns:Receive" ] principals = [{ type = "AWS" identifiers = ["*"] }] conditions = [{ test = "StringLike" variable = "sns:Endpoint" values = [module.sqs.queue_arn] }] } } subscriptions = { sqs = { protocol = "sqs" endpoint = module.sqs.queue_arn } } tags = { Environment = "dev" } } ``` ```HCL module "sqs" { source = "terraform-aws-modules/sqs/aws" name = "pub-sub" create_queue_policy = true queue_policy_statements = { sns = { sid = "SNSPublish" actions = ["sqs:SendMessage"] principals = [ { type = "Service" identifiers = ["sns.amazonaws.com"] } ] conditions = [{ test = "ArnEquals" variable = "aws:SourceArn" values = [module.sns.topic_arn] }] } } tags = { Environment = "dev" } } ``` -------------------------------- ### Configuring SQS Module (v3.x) - Terraform HCL Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/UPGRADE-4.0.md This snippet demonstrates the configuration of the Terraform AWS SQS module version 3.x. It shows the use of `name_prefix` and how `redrive_policy` and `redrive_allow_policy` were defined as JSON-encoded strings. The `policy` variable was also directly used here. ```HCL module "sqs" { source = "terraform-aws-modules/sqs/aws" version = "~> 3.0" name_prefix = "example-" redrive_policy = jsonencoded({ redrivePermission = "byQueue", sourceQueueArns = [aws_sqs_queue.example.arn] }) redrive_allow_policy = jsonencoded({ deadLetterTargetArn = aws_sqs_queue.example.arn maxReceiveCount = 4 }) policy = "..." } ``` -------------------------------- ### Configuring SQS Module (v4.x) - Terraform HCL Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/UPGRADE-4.0.md This snippet illustrates the updated configuration for the Terraform AWS SQS module version 4.x. It replaces `name_prefix` with `name` and `use_name_prefix`, and changes `redrive_policy` and `redrive_allow_policy` to direct HCL maps, as JSON encoding is now handled internally. The `policy` variable is removed, with an example of using `source_queue_policy_documents` for policy migration. ```HCL module "sqs" { source = "terraform-aws-modules/sns/aws" version = "~> 4.0" name = "example" use_name_prefix = true redrive_policy = { redrivePermission = "byQueue", sourceQueueArns = [aws_sqs_queue.example.arn] } redrive_allow_policy = { deadLetterTargetArn = aws_sqs_queue.example.arn maxReceiveCount = 4 } # Can be used to utilize v3.x `var.policy` value without modification # source_queue_policy_documents = ["..."] } ``` -------------------------------- ### Managing Multiple S3 Buckets with Terragrunt Wrapper Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/wrappers/README.md This HCL snippet provides a concrete example of using the `terraform-aws-s3-bucket` module wrapper with Terragrunt to manage multiple S3 buckets. It sets global defaults for bucket policies and defines individual bucket configurations, showcasing how to apply different settings per bucket while leveraging the wrapper pattern for resource consolidation. ```HCL terraform { source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers" # Alternative source: # source = "git::git@github.com:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master" } inputs = { defaults = { force_destroy = true attach_elb_log_delivery_policy = true attach_lb_log_delivery_policy = true attach_deny_insecure_transport_policy = true attach_require_latest_tls_policy = true } items = { bucket1 = { bucket = "my-random-bucket-1" } bucket2 = { bucket = "my-random-bucket-2" tags = { Secure = "probably" } } } } ``` -------------------------------- ### Creating an SQS Queue Encrypted with Customer Managed KMS Key in Terraform Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/README.md This example shows how to configure an SQS queue with server-side encryption using a customer-managed KMS key. The `kms_master_key_id` specifies the ARN or ID of the KMS key, and `kms_data_key_reuse_period_seconds` defines how long SQS can reuse the data key. ```HCL module "sqs" { source = "terraform-aws-modules/sqs/aws" name = "cmk" kms_master_key_id = "0d1ba9e8-9421-498a-9c8a-01e9772b2924" kms_data_key_reuse_period_seconds = 3600 tags = { Environment = "dev" } } ``` -------------------------------- ### Configuring SQS Module Wrapper with Terraform Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/wrappers/README.md This HCL snippet illustrates how to use the `terraform-aws-sqs` module wrapper directly with native Terraform. It defines a `module` block, specifying the wrapper source and providing default input values and item-specific configurations for multiple SQS queues, similar to the Terragrunt approach but within a standard Terraform configuration. ```HCL module "wrapper" { source = "terraform-aws-modules/sqs/aws//wrappers" defaults = { # Default values create = true tags = { Terraform = "true" Environment = "dev" } } items = { my-item = { # omitted... can be any argument supported by the module } my-second-item = { # omitted... can be any argument supported by the module } # omitted... } } ``` -------------------------------- ### Configuring SQS Module Wrapper with Terragrunt Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/wrappers/README.md This HCL snippet demonstrates how to configure the `terraform-aws-sqs` module wrapper using Terragrunt. It specifies the module source and defines default input values, along with individual item configurations for multiple SQS queues. This pattern is useful for managing multiple resources without duplicating `terragrunt.hcl` files. ```HCL terraform { source = "tfr:///terraform-aws-modules/sqs/aws//wrappers" # Alternative source: # source = "git::git@github.com:terraform-aws-modules/terraform-aws-sqs.git//wrappers?ref=master" } inputs = { defaults = { # Default values create = true tags = { Terraform = "true" Environment = "dev" } } items = { my-item = { # omitted... can be any argument supported by the module } my-second-item = { # omitted... can be any argument supported by the module } # omitted... } } ``` -------------------------------- ### Creating a FIFO SQS Queue with Terraform Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/README.md This snippet demonstrates how to create a FIFO (First-In, First-Out) SQS queue using the Terraform AWS SQS module. FIFO queues ensure message ordering and exactly-once processing. The `fifo_queue` parameter is set to `true` to enable this functionality. ```HCL module "sqs" { source = "terraform-aws-modules/sqs/aws" name = "fifo" fifo_queue = true tags = { Environment = "dev" } } ``` -------------------------------- ### Conditionally Creating SQS Resources with Terraform Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/README.md This snippet demonstrates how to use conditional flags within the Terraform AWS SQS module to control the creation of various SQS-related resources. Setting `create` to `false` disables all resource creation, while specific flags like `create_queue_policy` or `create_dlq` can enable individual components. ```HCL module "sqs" { source = "terraform-aws-modules/sqs/aws" # Disable creation of all resources create = false # Enable creation of queue policy create_queue_policy = true # Enable creation of dead letter queue create_dlq = true # Enable creation of dead letter queue policy create_dlq_queue_policy = true # ... omitted } ``` -------------------------------- ### Creating an SQS Queue with a Dead Letter Queue (DLQ) in Terraform Source: https://github.com/terraform-aws-modules/terraform-aws-sqs/blob/master/README.md This snippet illustrates how to associate a Dead Letter Queue (DLQ) with an SQS queue. Messages that fail to be processed after a specified number of retries (defined by `maxReceiveCount` in `redrive_policy`) are moved to the DLQ for further analysis. Setting `create_dlq` to `true` enables the DLQ. ```HCL module "sqs" { source = "terraform-aws-modules/sqs/aws" name = "example" create_dlq = true redrive_policy = { # default is 5 for this module maxReceiveCount = 10 } tags = { Environment = "dev" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.