Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magodo/tfadd
Generate valid Terraform configuration from state
https://github.com/magodo/tfadd
terraform
Last synced: 7 days ago
JSON representation
Generate valid Terraform configuration from state
- Host: GitHub
- URL: https://github.com/magodo/tfadd
- Owner: magodo
- License: mpl-2.0
- Created: 2022-04-08T02:14:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T04:45:07.000Z (21 days ago)
- Last Synced: 2024-10-23T10:34:26.465Z (14 days ago)
- Topics: terraform
- Language: Go
- Homepage:
- Size: 7.38 MB
- Stars: 87
- Watchers: 6
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tfadd
Generate valid Terraform configuration from state.
## Install
```
go install github.com/magodo/tfadd@latest
```## Intro
The goal of this tool is to improve the [import experience](https://learn.hashicorp.com/tutorials/terraform/state-import?in=terraform/state&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) of Terraform, that rather than constructing the configurations from scratch, `tfadd` (try its best to) provide users a **valid** configuration automatically.
> The **valid** here means the generated configuration should raise no error and show no diff during `terraform plan`.
Currently to generate the state, the tool supports *full mode* (with `-full`) or *partial mode* (by default).
- In *full mode*, `tfadd` outputs all non-computed properties in the generated config. The generated config might be **invalid** for kinds of reasons, where manual modification is needed. But the benefit is that it works for any Terraform provider.
- In *partial mode*, `tfadd` only outputs properties without `Optional+Computed` properties, with cross property constraints taken into consideration. This mode aims aims to generate a **valid** Terraform config. Currently, this mode can only works for the following providers:|Name|Version|
|-|-|
|hashicorp/aws|v5.64.0|
|hashicorp/azurerm|v4.5.0|
|hashicorp/google|v6.0.1|
|azure/azapi|v2.0.1|## Usage
The typical usage is to use `tfadd` together with `terraform import`:
1. Prepare an empty [workspace](https://www.terraform.io/language/state/workspaces) (e.g. an empty directory for *local* backend)
1. Identify the existing resources to import, write down the empty resource block
1. (*partial mode* only) Run `tfadd init [providers...] > terraform.tf` to populate the Terraform setting to pin the provider version
1. Run `terraform init` to initialize the providers
1. Import the resources via `terraform import`
1. Run `tfadd state` or `tfadd state -full` to generate the configuration## Limitation
- Only the managed resources of the root module in the state file will get the config generated, any child module will be skipped.
- No inter-resource dependency generated.