Terraform script for creating an SQS FIFO queue, including the use of variables and remote state:
This script (Terraform script for creating an SQS FIFO queue, including the use of variables and remote state) uses variables for the AWS region, environment, queue name, S3 bucket name for storing the Terraform state, and the file name for the state file. This allows you to easily change these values as needed, and also makes it easier to manage multiple environments and resources.
It also uses remote state to store the state of the SQS queue in an S3 bucket, so that multiple people can work on the same Terraform configuration and share the state.
You will need to configure the AWS provider with your AWS access key and secret key in order to use this script.
Please also note that you need to have the S3 bucket and IAM user setup with the right permission, before running this script.
######################################################################
provider "aws" {
region = var.region
}
resource "aws_sqs_queue" "example" {
name = var.queue_name
content_based_deduplication = true
fifo_queue = true
tags = {
Environment = var.environment
}
}
terraform {
backend "s3" {
bucket = var.bucket_name
key = var.state_file
region = var.region
}
}
variable "region" {
default = "us-east-1"
}
variable "environment" {
default = "production"
}
variable "queue_name" {
default = "example-queue.fifo"
}
variable "bucket_name" {
default = "terraform-state-bucket"
}
variable "state_file" {
default = "sqs-queue-state.tfstate"
}