We needed way to run terraform modules using yaml files as it is much simpler.
We have decided to use terraform cloud to execute terraform code. We have decided that it is right to have workspace per module as we do not want giant module dependencies. We have created terraform module that can parse yaml files, create workspaces and make TFC to execute code / modules.
Current implementation si very basic:
- accepts module source/version, variables, dependencies and uses variables from other workspaces if allowed.
Modules does generate terraform code from yamls and sets up workspaces but since the code is not yet in git repository first run will fail. After another apply is run from local and resulting code is comitted to git repo it will pick up code and executel.
- Create workspace in terrqform cloud
- Create folder and place yaml files in the folder
- Yaml files point to modules and provide variables like done in tests/basic/example-infra folder
- Supply variables to the module like done in basic tests
- Terraform apply will create workspaces and code (by default in _terraform folder).
- Commit the code and TFC will pick up and apply changes as requested.
- Modify module to not create workspace immidiately but only when code is comitted (this might create issue with race condition, workspaces can be creared but TFC mighhave had already tried to execute code).
- There is an issue with some providers (more details in jira).
- Currently some generated code is escaped which is wrong.
- Get this repo be managed by terraform module manager terraform repo.
Name | Version |
---|---|
local | 2.4.0 |
tfe | 0.47.0 |
Name | Source | Version |
---|---|---|
provider_custom_vars_default_merged | cloudposse/config/yaml//modules/deepmerge | 1.0.2 |
Name | Type |
---|---|
local_file.this | resource |
tfe_project.project | resource |
tfe_workspace.this | resource |
tfe_workspace_variable_set.this | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
linked_workspaces | The list of workspaces from where we can pull outputs and use in our module variables | list(string) |
null |
no |
module_providers | The list of providers to add in providers.tf | any |
[] |
no |
module_source | The module source | string |
n/a | yes |
module_vars | The module variables | any |
{} |
no |
module_version | The module version | string |
n/a | yes |
name | module/repo-folder/workspace name and uniq identifier | string |
n/a | yes |
output | The module output | any |
[] |
no |
repo | git/vcs repository configurations | object({ |
null |
no |
target_dir | The directory where new module folder will be created, this will be terraform project repository root url | string |
"./" |
no |
terraform_backend | Allows to set terraform backend configurations | object({ |
{ |
no |
terraform_version | The required_version variable value for terraform{} block in versions.tf | string |
">= 1.3.0" |
no |
variable_set_ids | The list of variable set ids to attach to workspace | list(string) |
null |
no |
workspace | Terraform cloud workspace configurations | object({ |
n/a | yes |
Name | Description |
---|---|
project_id | The ID of terraform cloud project |
test-data | n/a |
workspace_id | The ID of created terraform cloud workspace |
Name | Version |
---|---|
terraform | >= 1.3.0 |
tfe | ~> 0.40 |
Name | Version |
---|---|
tfe | ~> 0.40 |
Name | Source | Version |
---|---|---|
aws_credentials_variable_set | ./modules/variable-set | n/a |
workspaces | ./modules/workspace | n/a |
Name | Type |
---|---|
tfe_oauth_client.this | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
auto_apply | To have workspaces automatically apply after plan is done successfully. | bool |
false |
no |
aws | Cloud Access (goes to shared variable set, should be adjusted) | map(any) |
{ |
no |
git_org | The github org/owner name | string |
n/a | yes |
git_provider | The vsc(github, gitlab, ...) provider id | string |
"gitlab" |
no |
git_repo | The github repo name without org prefix | string |
n/a | yes |
git_token | The vsc(github, gitlab, ...) personal access token. TFC oauth token can be created manually or externally and oken supplied via this variable. | string |
n/a | yes |
org | The terraform cloud org name | string |
n/a | yes |
rootdir | The directory on git repo where the workspaces creator main.tf file located | string |
"./_terraform/" |
no |
targetdir | The directory where tf cloud workspace corresponding workspaces will be created | string |
"./../_terraform/" |
no |
token | The terraform cloud token | string |
n/a | yes |
yamldir | The directory where yamls located | string |
"." |
no |
No outputs.