All Projects → nozaq → terraform-aws-remote-state-s3-backend

nozaq / terraform-aws-remote-state-s3-backend

Licence: MIT License
A terraform module to set up remote state management with S3 backend for your account.

Programming Languages

HCL
1544 projects

Projects that are alternatives of or similar to terraform-aws-remote-state-s3-backend

terraform-provider-papertrail
Papertrail support for Terraform
Stars: ✭ 14 (-80.28%)
Mutual labels:  terraform, terraform-modules
terraform-aws-mongodb
Simplify MongoDB provisioning on AWS using Terraform
Stars: ✭ 20 (-71.83%)
Mutual labels:  terraform, terraform-modules
Terraform Docs
Generate documentation from Terraform modules in various output formats
Stars: ✭ 2,483 (+3397.18%)
Mutual labels:  terraform, terraform-modules
Awesome Terraform
Curated list of resources on HashiCorp's Terraform
Stars: ✭ 2,618 (+3587.32%)
Mutual labels:  terraform, terraform-modules
aws docker swarm
setup to bootstrap docker swarm cluster and a controller on AWS using terraform
Stars: ✭ 24 (-66.2%)
Mutual labels:  terraform
Red-Baron
Automate creating resilient, disposable, secure and agile infrastructure for Red Teams
Stars: ✭ 326 (+359.15%)
Mutual labels:  terraform-modules
catalog
Catalog of cluster services as Kustomize bases.
Stars: ✭ 29 (-59.15%)
Mutual labels:  terraform-modules
terraform-provider-nutanix
Terraform Nutanix Provider
Stars: ✭ 53 (-25.35%)
Mutual labels:  terraform
terraform-aws-account
🌳 A sustainable Terraform Package which creates Account & IAM resources on AWS
Stars: ✭ 18 (-74.65%)
Mutual labels:  terraform-modules
yor
Extensible auto-tagger for your IaC files. The ultimate way to link entities in the cloud back to the codified resource which created it.
Stars: ✭ 459 (+546.48%)
Mutual labels:  terraform
aws-terraform
AWS & Terraform Rocket Start Guide
Stars: ✭ 53 (-25.35%)
Mutual labels:  terraform
aws-lambda-edge-basic-auth-terraform
A Terraform module that creates AWS Lambda@Edge resources to protect CloudFront distributions with Basic Authentication.
Stars: ✭ 18 (-74.65%)
Mutual labels:  terraform-modules
terraform-aws-bigip
BIG-IP AWS module for the Terraform Registry
Stars: ✭ 12 (-83.1%)
Mutual labels:  terraform
terraform-aws-ec2-ami-backup
Terraform module for automatic & scheduled AMI creation
Stars: ✭ 19 (-73.24%)
Mutual labels:  terraform-modules
devops-governance
Example end-to-end Governance Model from CI/CD to Azure Resource Manager. Use this project to deploy example AAD, ARM and Azure DevOps resources to learn about e2e RBAC.
Stars: ✭ 79 (+11.27%)
Mutual labels:  terraform
tf aws ecs
Terraform module which creates AWS ECS resources
Stars: ✭ 64 (-9.86%)
Mutual labels:  terraform-modules
terraform-provider-bigip
Terraform resources that can configure F5 BIG-IP products
Stars: ✭ 74 (+4.23%)
Mutual labels:  terraform
terraform-aws-rabbitmq
A terraform module to deploy a rabbitmq cluster with AutoScaling Group and Load Balancer
Stars: ✭ 25 (-64.79%)
Mutual labels:  terraform
terraform-aws-ecs-service
Creates an ECS Service.
Stars: ✭ 86 (+21.13%)
Mutual labels:  terraform-modules
terraform-cloudinit-container-server
A batteries included cloud-init config to quickly and easily deploy a single Docker image or Docker Compose file to any Cloud™ VM.
Stars: ✭ 52 (-26.76%)
Mutual labels:  terraform

terraform-aws-remote-state-s3-backend

Github Actions

Terraform Module Registry

A terraform module to set up remote state management with S3 backend for your account. It creates an encrypted S3 bucket to store state files and a DynamoDB table for state locking and consistency checking. Resources are defined following best practices as described in the official document and ozbillwang/terraform-best-practices.

Features

  • Create a S3 bucket to store remote state files.
  • Encrypt state files with KMS.
  • Enable bucket replication and object versioning to prevent accidental data loss.
  • Automatically transit non-current versions in S3 buckets to AWS S3 Glacier to optimize the storage cost.
  • Optionally you can set to expire aged non-current versions(disabled by default).
  • Optionally you can set fixed S3 bucket name to be user friendly(false by default).
  • Create a DynamoDB table for state locking.
  • Optionally create an IAM policy to allow permissions which Terraform needs.

Usage

The module outputs terraform_iam_policy which can be attached to IAM users, groups or roles running Terraform. This will allow the entity accessing remote state files and the locking table. This can optionally be disabled with terraform_iam_policy_create = false

provider "aws" {
  region = "us-east-1"
}

provider "aws" {
  alias  = "replica"
  region = "us-west-1"
}

module "remote_state" {
  source = "nozaq/remote-state-s3-backend/aws"

  providers = {
    aws         = aws
    aws.replica = aws.replica
  }
}

resource "aws_iam_user" "terraform" {
  name = "TerraformUser"
}

resource "aws_iam_user_policy_attachment" "remote_state_access" {
  user       = aws_iam_user.terraform.name
  policy_arn = module.remote_state.terraform_iam_policy.arn
}

Note that you need to provide two providers, one for the main state bucket and the other for the bucket to which the main state bucket is replicated to. Two providers must point to different AWS regions.

Once resources are created, you can configure your terraform files to use the S3 backend as follows.

terraform {
  backend "s3" {
    bucket         = "THE_NAME_OF_THE_STATE_BUCKET"
    key            = "some_environment/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    kms_key_id     = "THE_ID_OF_THE_KMS_KEY"
    dynamodb_table = "THE_ID_OF_THE_DYNAMODB_TABLE"
  }
}

THE_NAME_OF_THE_STATE_BUCKET, THE_ID_OF_THE_DYNAMODB_TABLE and THE_ID_OF_THE_KMS_KEY can be replaced by state_bucket.bucket, dynamodb_table.id and kms_key.id in outputs from this module respectively.

See the official document for more detail.

Requirements

Name Version
terraform >= 1.1.4
aws >= 3.39.0

Providers

Name Version
aws >= 3.39.0
aws.replica >= 3.39.0

Inputs

Name Description Type Required
dynamodb_table_billing_mode Controls how you are charged for read and write throughput and how you manage capacity. string no
dynamodb_table_name The name of the DynamoDB table to use for state locking. string no
enable_replication Set this to true to enable S3 bucket replication in another region bool no
iam_policy_attachment_name The name of the attachment. string no
iam_policy_name_prefix Creates a unique name beginning with the specified prefix. string no
iam_role_arn Use IAM role of specified ARN for s3 replication instead of creating it. string no
iam_role_name_prefix Creates a unique name beginning with the specified prefix. string no
kms_key_deletion_window_in_days Duration in days after which the key is deleted after destruction of the resource, must be between 7 and 30 days. number no
kms_key_description The description of the key as viewed in AWS console. string no
kms_key_enable_key_rotation Specifies whether key rotation is enabled. bool no
noncurrent_version_expiration Specifies when noncurrent object versions expire. See the aws_s3_bucket document for detail.
object({
days = number
})
no
noncurrent_version_transitions Specifies when noncurrent object versions transitions. See the aws_s3_bucket document for detail.
list(object({
days = number
storage_class = string
}))
no
override_s3_bucket_name override s3 bucket name to disable bucket_prefix and create bucket with static name bool no
replica_bucket_prefix Creates a unique replica bucket name beginning with the specified prefix. string no
s3_bucket_force_destroy A boolean that indicates all objects should be deleted from S3 buckets so that the buckets can be destroyed without error. These objects are not recoverable. bool no
s3_bucket_name If override_s3_bucket_name is true, use this bucket name for replica instead of dynamic name with bucket_prefix string no
s3_bucket_name_replica If override_s3_bucket_name is true, use this bucket name instead of dynamic name with bucket_prefix string no
s3_logging_target_bucket The name of the bucket for log storage. The "S3 log delivery group" should have Objects-write und ACL-read permissions on the bucket. string no
s3_logging_target_prefix The prefix to apply on bucket logs, e.g "logs/". string no
state_bucket_prefix Creates a unique state bucket name beginning with the specified prefix. string no
tags A mapping of tags to assign to resources. map(string) no
terraform_iam_policy_create Specifies whether to terraform IAM policy is created. bool no
terraform_iam_policy_name_prefix Creates a unique name beginning with the specified prefix. string no

Outputs

Name Description
dynamodb_table The DynamoDB table to manage lock states.
kms_key The KMS customer master key to encrypt state buckets.
replica_bucket The S3 bucket to replicate the state S3 bucket.
state_bucket The S3 bucket to store the remote state file.
terraform_iam_policy The IAM Policy to access remote state environment.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].