Skip to content

Commit

Permalink
Allow outputting additional TF outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Oct 25, 2024
1 parent c4b5605 commit 47907ae
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
git: {}
provider: ${facts:cloud}
version: ${openshift4_terraform:_tf_module_version:${openshift4_terraform:provider}}
additional_outputs: {}
terraform_variables:
source: git::https://github.com/appuio/terraform-openshift4-${openshift4_terraform:provider}.git//?ref=${openshift4_terraform:version}
cluster_id: ${cluster:name}
Expand Down
5 changes: 3 additions & 2 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ local terraform_config =
},
},
},
local mergedOutputs = params.additional_outputs + outputs[params.provider],
'outputs.tf': {
output: {
[out]: {
value: outputs[params.provider][out],
value: mergedOutputs[out],
}
for out in std.objectFields(outputs[params.provider])
for out in std.objectFields(mergedOutputs)
},
},
'variables.tf': {
Expand Down
20 changes: 20 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ Terraform input variables for the selected Terraform module (see parameter `prov
They're passed to the module without any further processing.
The variables are merged with the defaults, unless overridden.


== `additional_outputs`

[horizontal]
type:: object
default:: `{}`
example::
+
[source,yaml]
----
additional_outputs:
my_output: '\${module.cluster.my_output}'
----

Additional outputs that are passed to the Terraform module.
The outputs are merged with the defaults, defaults can't be overridden.
The keys are then name of the output, the value should contain a reference to a output variable from the Terraform module.
Additional escaping might be needed since Terraform variables use the same syntax as reclass; see the example above.


== `version`

[horizontal]
Expand Down
2 changes: 2 additions & 0 deletions tests/cloudscale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ parameters:
- ssh-ed25519 AA...
control_vshn_net_token: asdf...
hieradata_repo_user: project_123_bot
additional_outputs:
region: '\${module.cluster.region}'
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
},
"hieradata_mr": {
"value": "${module.cluster.hieradata_mr}"
},
"region": {
"value": "${module.cluster.region}"
}
}
}

0 comments on commit 47907ae

Please sign in to comment.