We recommend using the env zero-provided module to create the required S3 bucket and IAM resources. The module sets up the correct bucket configuration and a trust relationship that allows env zero’s infrastructure to securely access your state.It is possible to use an existing S3 bucket, but the bucket configuration and IAM role must match what the module creates. Review the module source code to ensure your existing resources are configured correctly.
Prerequisites
- An AWS account with permissions to create S3 buckets and IAM roles
- AWS credentials configured on the project where you will create the environment (if deploying through env zero)
- Your env zero Organization ID (found in Organization Settings, where you can copy it directly)
Setup
Deploy the remote state bucket module
Deploy the env0/remote-state-bucket-module to create the required S3 bucket and IAM role in your AWS account.
Deploying through env zero (recommended)
- Create a new template with the following settings:
- Repository URL:
https://github.com/env0/remote-state-bucket-module - Terraform folder path:
aws
- Repository URL:
- Create a new environment from this template
- Make sure the Use env zero Remote Backend option is disabled for this environment
- Configure the following Terraform variables for the environment:
| Variable | Description |
|---|---|
external_id | Your env zero Organization ID |
state_bucket_name | The name for the S3 bucket to create |
region | The AWS region to deploy the bucket in |
- Deploy the environment
Deploying locally
Alternatively, you can deploy the module from your local machine or any other CI/CD pipeline. Make sure you have valid AWS credentials configured (for example, viaaws configure or environment variables).main.tf
terraform
opentofu
Collect the module outputs
After the apply completes, note the following outputs:
| Output | Description |
|---|---|
role_arn | The IAM role ARN that env zero will assume to access your bucket |
external_id | Your env zero Organization ID (used for secure role assumption) |
region | The AWS region of your bucket |
bucket_name | The name of the created S3 bucket |
Contact env zero support
Send the four output values to env zero support. The support team will configure your organization to use your bucket for remote state storage.