Skip to content

Commit

Permalink
Merge pull request #6 from dasmeta/DMVP-fix-var
Browse files Browse the repository at this point in the history
fix(DMVP-fix-var): Fix provider
  • Loading branch information
aghamyan44 authored Jul 26, 2023
2 parents 9c69cd7 + d3fb5a4 commit 16be9f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ git config core.hooksPath githooks

| Name | Version |
|------|---------|
| <a name="provider_local"></a> [local](#provider\_local) | n/a |
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | ~> 0.40 |
| <a name="provider_local"></a> [local](#provider\_local) | 2.4.0 |
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | 0.47.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_provider_custom_vars_default_merged"></a> [provider\_custom\_vars\_default\_merged](#module\_provider\_custom\_vars\_default\_merged) | cloudposse/config/yaml//modules/deepmerge | 0.2.0 |
| <a name="module_provider_custom_vars_default_merged"></a> [provider\_custom\_vars\_default\_merged](#module\_provider\_custom\_vars\_default\_merged) | cloudposse/config/yaml//modules/deepmerge | 1.0.2 |

## Resources

Expand Down
15 changes: 8 additions & 7 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ locals {
providers = [for group in local.module_providers_grouped : {
name = group[0].name
version = group[0].version
source = coalesce(group[0].source, "hashicorp/${group[0].name}")
configuration_aliases = replace(jsonencode([for item in group : "${group[0].name}.${item.alias}" if item.alias != null]), "\"", "")
source = coalesce(try(group[0].source, null), "hashicorp/${group[0].name}")
configuration_aliases = replace(jsonencode([for item in group : "${group[0].name}.${try(item.alias, null)}" if try(item.alias, null) != null]), "\"", "")
}]
terraform_cloud = {
org = var.workspace.org
Expand All @@ -52,8 +52,9 @@ locals {
{
note = local.note
providers = [for provider in var.module_providers : merge(provider, {
custom_vars = { for key, value in provider.custom_vars : key => jsonencode(value) if !try(contains(keys(local.provider_custom_var_blocks[provider.name]), key), false) }
custom_var_blocks = { for key, value in try(module.provider_custom_vars_default_merged["${provider.name}${provider.alias == null ? "" : "-${provider.alias}"}"].merged) : key => value if try(contains(keys(local.provider_custom_var_blocks[provider.name]), key), false) }
alias = try(provider.alias, null)
custom_vars = { for key, value in try(provider.custom_vars, {}) : key => jsonencode(value) if !try(contains(keys(local.provider_custom_var_blocks[provider.name]), key), false) }
custom_var_blocks = { for key, value in try(module.provider_custom_vars_default_merged["${provider.name}${try(provider.alias, null) == null ? "" : "-${provider.alias}"}"].merged) : key => value if try(contains(keys(local.provider_custom_var_blocks[provider.name]), key), false) }
})]
}
)
Expand Down Expand Up @@ -113,12 +114,12 @@ locals {

module "provider_custom_vars_default_merged" {
source = "cloudposse/config/yaml//modules/deepmerge"
version = "0.2.0"
version = "1.0.2"

for_each = { for provider in var.module_providers : "${provider.name}${provider.alias == null ? "" : "-${provider.alias}"}" => provider }
for_each = { for provider in var.module_providers : "${provider.name}${try(provider.alias, null) == null ? "" : "-${provider.alias}"}" => provider }

maps = [
each.value.custom_vars,
try(each.value.custom_vars, {}),
try(local.provider_custom_var_blocks[each.value.name], {})
]
}
2 changes: 1 addition & 1 deletion tests/yaml-conf-and-workspace-link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for aws access tokens you will need to have a user having api/cli access to crea
| Name | Version |
|------|---------|
| <a name="provider_test"></a> [test](#provider\_test) | n/a |
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | 0.40.0 |
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | ~> 0.40 |

## Modules

Expand Down

0 comments on commit 16be9f1

Please sign in to comment.