Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miquido/terraform-tfstate-backend
https://github.com/miquido/terraform-tfstate-backend
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/miquido/terraform-tfstate-backend
- Owner: miquido
- Created: 2023-09-13T05:40:48.000Z (over 1 year ago)
- Default Branch: dependabot-terraform-hashicorp-aws-tw-5.16
- Last Pushed: 2024-08-13T06:30:00.000Z (5 months ago)
- Last Synced: 2024-11-09T11:34:52.512Z (2 months ago)
- Language: HCL
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Miquido][logo]](https://www.miquido.com/)
# terraform-tfstate-backend
Terraform module to provision S3 Bucket for Terraform State Backend and DynamoDB Table for state locking.### Open source modules used:
* https://github.com/cloudposse/terraform-aws-tfstate-backend
---
**Terraform Module**GitLab Repository: https://gitlab.com/miquido/terraform/terraform-tfstate-backend
## Usage
1. Use module to create bucket
```
terraform {}module "tfstate-backend" {
source = "git::ssh://[email protected]:miquido/terraform/terraform-tfstate-backend.git?ref=master"
name = "miquido"
environment = "devops"
}output "config" {
value = "${module.tfstate-backend.tf_backend_config}"
}
```2. Run commands
```bash
terraform init
terraform apply# in output there should be rendered tf backend config
```3. Add terraform backend
```
terraform {
backend "s3" {
region = "eu-west-2"
bucket = "miquido-devops-terraform-state"
key = "terraform.tfstate"
dynamodb_table = "miquido-devops-terraform-state-lock"
encrypt = true
}
}module "tfstate-backend" {
...
}
```
4. Run commands again```bash
terraform init
terraform apply
```5. When asked to copy local tfstate to s3 bucket, answer yes.
## Makefile Targets
```text
Available targets:help Help screen
help/all Display help for all targets
help/short This help short screen
lint Lint Terraform code```
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 0.13 |
| [aws](#requirement\_aws) | ~> 5.16 |
| [local](#requirement\_local) | >= 1.3 |## Providers
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | ~> 5.16 |
| [local](#provider\_local) | >= 1.3 |## Modules
| Name | Source | Version |
|------|--------|---------|
| [this](#module\_this) | cloudposse/tfstate-backend/aws | 1.1.1 |## Resources
| Name | Type |
|------|------|
| [local_file.terraform_backend_config](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [billing\_mode](#input\_billing\_mode) | DynamoDB billing mode | `string` | `"PAY_PER_REQUEST"` | no |
| [environment](#input\_environment) | Environment name | `string` | `""` | no |
| [name](#input\_name) | Account/Project Name | `string` | n/a | yes |
| [read\_capacity](#input\_read\_capacity) | DynamoDB read capacity units | `number` | `1` | no |
| [role\_account\_id](#input\_role\_account\_id) | The AWS Account ID of IAM Role to be assumed. If none provided current caller account id will be used. | `string` | `""` | no |
| [role\_name](#input\_role\_name) | The IAM Role name to be assumed | `string` | `"AdministratorAccess"` | no |
| [s3\_bucket\_name](#input\_s3\_bucket\_name) | S3 bucket name. If not provided, the name will be generated by the label module in the format namespace-stage-name | `string` | `""` | no |
| [tags](#input\_tags) | Tags to apply on repository | `map(string)` | `{}` | no |
| [terraform\_backend\_config\_file\_name](#input\_terraform\_backend\_config\_file\_name) | Name of terraform backend config file | `string` | `"tfstate-backend.tf"` | no |
| [terraform\_backend\_config\_file\_path](#input\_terraform\_backend\_config\_file\_path) | The path to terrafrom project directory. Won't create local file if variable value is empty. Recommended: `path.module` | `string` | `""` | no |
| [terraform\_minimum\_version](#input\_terraform\_minimum\_version) | Minimum version for terraform | `string` | `"0.13.5"` | no |
| [write\_capacity](#input\_write\_capacity) | DynamoDB write capacity units | `number` | `1` | no |## Outputs
| Name | Description |
|------|-------------|
| [dynamodb\_table\_arn](#output\_dynamodb\_table\_arn) | The ARN of created DynamoDB Table |
| [dynamodb\_table\_id](#output\_dynamodb\_table\_id) | The ID of created DynamoDB Table |
| [dynamodb\_table\_name](#output\_dynamodb\_table\_name) | The name of created DynamoDB Table |
| [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | S3 bucket ARN |
| [s3\_bucket\_domain\_name](#output\_s3\_bucket\_domain\_name) | S3 bucket domain name |
| [s3\_bucket\_id](#output\_s3\_bucket\_id) | S3 bucket ID |
| [tf\_backend\_config](#output\_tf\_backend\_config) | Rendered Terraform backend config file |## Developing
1. Make changes in terraform files
2. Regenerate documentation
```bash
bash <(git archive [email protected]:miquido/terraform/terraform-readme-update.git master update.sh | tar -xO)
```3. Run lint
```
make lint
```## Copyright
Copyright © 2017-2023 [Miquido](https://miquido.com)
### Contributors
| [![Konrad Obal][k911_avatar]][k911_homepage]
[Konrad Obal][k911_homepage] |
|---|[k911_homepage]: https://github.com/k911
[k911_avatar]: https://github.com/k911.png?size=150[logo]: https://www.miquido.com/img/logos/logo__miquido.svg
[website]: https://www.miquido.com/
[gitlab]: https://gitlab.com/miquido
[github]: https://github.com/miquido
[bitbucket]: https://bitbucket.org/miquido