This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom destinations for modules (#13)
* Added destination option to configuration, so each module could be added to one or more specific destination folder --------- Co-authored-by: Rafal Przybyla <[email protected]> Co-authored-by: Nathaniel Ritholtz <[email protected]>
- Loading branch information
1 parent
f625609
commit 2c10832
Showing
4 changed files
with
242 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,10 @@ | |
|
||
# Terrafile output | ||
vendor/modules | ||
testdata | ||
terrafile | ||
|
||
#IDEs | ||
.idea/ | ||
dist/ | ||
dist/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,12 @@ curl -L https://github.com/coretech/terrafile/releases/download/v{VERSION}/terra | |
## How to use | ||
Terrafile expects a file named `Terrafile` which will contain your terraform module dependencies in a yaml like format. | ||
|
||
An example Terrafile: | ||
There are two approaches that can be used for managing your modules depending on the structure of your terraform code: | ||
1. The default approach: `Terrafile` is located directly in the directory where terraform is run | ||
2. Centrally managed: `Terrafile` is located in "root" directory of your terraform code, managing modules in all subfolders / stacks | ||
|
||
### Default Approach | ||
An example of default approach (#1) to `Terrafile` | ||
``` | ||
tf-aws-vpc: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-vpc" | ||
|
@@ -34,24 +39,75 @@ tf-aws-vpc-experimental: | |
Terrafile config file in current directory and modules exported to ./vendor/modules | ||
```sh | ||
$ terrafile | ||
INFO[0000] [*] Checking out v1.46.0 of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out master of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out v1.46.0 of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out master of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
``` | ||
|
||
Terrafile config file in custom directory | ||
```sh | ||
$ terrafile -f config/Terrafile | ||
INFO[0000] [*] Checking out v1.46.0 of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out master of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out v1.46.0 of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out master of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
``` | ||
|
||
Terraform modules exported to custom directory | ||
```sh | ||
$ terrafile -p custom_directory | ||
INFO[0000] [*] Checking out master of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0001] [*] Checking out v1.46.0 of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0000] [*] Checking out master of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
INFO[0001] [*] Checking out v1.46.0 of [email protected]:terraform-aws-modules/terraform-aws-vpc | ||
``` | ||
|
||
### Centrally Managed Approach | ||
An example of using `Terrafile` in a root directory (#2): | ||
|
||
Let's assume the following directory structure: | ||
|
||
``` | ||
. | ||
├── iam | ||
│ ├── main.tf | ||
│ └── .....tf | ||
├── networking | ||
│ ├── main.tf | ||
│ └── .....tf | ||
├── onboarding | ||
. | ||
. | ||
. | ||
├── some-other-stack | ||
└── Terrafile | ||
``` | ||
|
||
In the above scenario, Terrafile is not in every single folder but in the "root" of terraform code. | ||
|
||
An example usage of centrally managed modules: | ||
|
||
``` | ||
tf-aws-vpc: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-vpc" | ||
version: "v1.46.0" | ||
destination: | ||
- networking | ||
tf-aws-iam: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-iam" | ||
version: "v5.11.1" | ||
destination: | ||
- iam | ||
tf-aws-s3-bucket: | ||
source: "[email protected]:terraform-aws-modules/terraform-aws-s3-bucket" | ||
version: "v3.6.1" | ||
destination: | ||
- networking | ||
- onboarding | ||
- some-other-stack | ||
``` | ||
|
||
The `destination` of module is an array of directories (stacks) where the module should be used. | ||
The module itself is fetched once and copied over to designated destinations. | ||
Final destination of the module is handled in a similar way as in first approach: `$destination/$module_path/$module_key`. | ||
|
||
The output of the run is exactly the same in both options. | ||
|
||
## TODO | ||
* Break out the main logic into seperate commands (e.g. version, help, run) | ||
* Update tests to include unit tests for broken out commands | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.