Terrawrap
Generate Terraform modules for Hashicorp-maintained providers/resources.
Currently only supporting hashicorp/terraform-provider-aws provider resources.
Install
- Build it
- Clone this repository
bin/terrawrap
- Build
go build .
- Add the binary to the path
(e.g.
mv bin/terrawrap /usr/local/bin/terrawrap
)
- via
go install
:
# Note: This isn't working at the moment due to git LFS
# see https://github.com/git-lfs/lfs-test-server/issues/98
go install github.com/infracasts/terrawrap@latest
Usage
Terrawrap will append or create new files (main.tf
, variables.tf
, outputs.tf
) in your
specified output directory, depending on whether or not they exist already.
Terrawrap will only append data; never truncate or overwrite your existing data.
To get started, just specify a resource type to wrap:
momer:~/projects/terraform-modules/my-module$ bin/terrawrap generate -a "Mo Omer <mo@infracasts.com>" -o . aws_secretsmanager_secret
2022/09/05 12:04:11 appending to /home/momer/projects/terraform-modules/my-module/main.tf
2022/09/05 12:04:11 appending to /home/momer/projects/terraform-modules/my-module/variables.tf
2022/09/05 12:04:11 appending to /home/momer/projects/terraform-modules/my-module/outputs.tf
Your new module is ready at
/home/momer/projects/terraform-modules/my-module/
Support/caveats
- This project is specifically tailored currently to support the aws
provider, and is a bit of a proof-of-concept/fun project.
- As a result, individual resources' schemas are extracted via a fork of the hashicorp/terraform-provider-aws
implementation. As the provider itself is not meant to be consumed externally (all schemas/provider details are in the
internal
package),
a fork was necessary to expose required details.
- The AWS provider doesn't provide descriptions as part of its schema, so I walked the AST of the markdown documentation that
Hashicorp provides as part of the hashicorp/terraform-provider-aws
repo, and parsed it out via regexp.