sr2c.terraform.terraform_s3_backend role – Create the AWS resources to keep Terraform state in S3
Note
This role is part of the sr2c.terraform collection (version 1.0.0).
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it use: ansible-galaxy collection install sr2c.terraform.
To use it in a playbook, specify: sr2c.terraform.terraform_s3_backend.
Entry point main – Create the AWS resources to keep Terraform state in S3
Synopsis
Creates a private S3 bucket for Terraform state, with versioning and default encryption, and optionally a KMS key for encrypting secrets with SOPS.
Locks the state with an S3 lock file (
use_lockfile), which needs Terraform 1.10 or later, or OpenTofu, or with a DynamoDB table whenterraform_s3_backend_use_lockfileisfalse.Sets the fact
terraform_s3_backend_configto the backend configuration, without akey, so add a differentkeyfor each module. Sets the factterraform_s3_backend_sops_kms_key_arnwhen it creates a KMS key.Creates no IAM roles or policies, so it assumes an administrator account in the same AWS account as the infrastructure. To keep state for several projects in one account, use per-project IAM roles. Policies limited to the state object must also allow
s3:GetObject,s3:PutObjectands3:DeleteObjecton<key>.tflock.Requires the
boto3andbotocorePython libraries on the host running the role, and the AWS CLI whenterraform_s3_backend_regionis not set.
Parameters
Parameter |
Comments |
|---|---|
The name of the S3 bucket to create for the state. |
|
The DynamoDB table to create when |
|
The region for the bucket and any DynamoDB table. Defaults to the AWS profile’s region, from |
|
Set the Choices:
|
|
Create a KMS key for encrypting secrets with SOPS. Defaults to Choices:
|
|
The alias of the KMS key to create. Required when |
|
Lock the state with an S3 lock file instead of a DynamoDB table. Existing tables are not deleted. Set to Choices:
|