diff --git a/examples/azure-terraform/arm/storage.json b/examples/azure-terraform/arm/storage.json index e479f7f1eb..ef0b0742d8 100644 --- a/examples/azure-terraform/arm/storage.json +++ b/examples/azure-terraform/arm/storage.json @@ -52,8 +52,8 @@ } ], "outputs": { - "STORAGE_ACCOUNT_KEY": { - "type": "string", + "storage_account_key": { + "type": "string", "value": "[first(listKeys(parameters('storageAccountName'), '2018-02-01').keys).value]" } } diff --git a/examples/azure-terraform/helpers.sh b/examples/azure-terraform/helpers.sh deleted file mode 100755 index 4ebb062b16..0000000000 --- a/examples/azure-terraform/helpers.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -dump-account-key() { - echo "Here is a the storage account key (base64 encoded) ==> $(echo $1 | base64)" -} - -# Call the requested function and pass the arguments as-is -"$@" diff --git a/examples/azure-terraform/porter.yaml b/examples/azure-terraform/porter.yaml index 6aba0c96b9..c6fbbef1f7 100644 --- a/examples/azure-terraform/porter.yaml +++ b/examples/azure-terraform/porter.yaml @@ -1,17 +1,17 @@ -## This section defines which Mixins will be used by the bundle. -mixins: - - arm - - exec - - terraform - ## This section defines the metadata that defines the bundle. This includes the name of the generated ## invocation image as well as the tag that will be applied to the bundle when it is published. name: azure-terraform -version: 1.0.0 +version: 1.1.0 description: "An example Porter Bundle using Terraform and Azure" tag: getporter/azure-terraform +## This section defines which Mixins will be used by the bundle. +mixins: + - arm + - exec + - terraform + ## This section defines what credentials are used for the bundle. In this case, we are operating ## against Azure, so we need some Azure Service Principal information. credentials: @@ -54,32 +54,22 @@ parameters: type: string default: "porter-terraform" - - name: tf_storage_account_key - type: string - applyTo: - - upgrade - - uninstall - ## Here we designate outputs at the top level that we wish ## to see after an action has completed (via `porter installation outputs list`) ## and/or utilize in a subsequent action. -## Note that currently, outputs don't persist across more than one action unless -## all of the actions traversed (re-)state the output value. outputs: - - name: STORAGE_ACCOUNT_KEY + - name: storage_account_key type: string - sensitive: true applyTo: - install + sensitive: true + - name: cosmos-db-uri type: string - applyTo: - - install + - name: eventhubs_connection_string type: string sensitive: true - applyTo: - - install install: - arm: @@ -93,14 +83,8 @@ install: storageAccountName: "{{ bundle.parameters.storage_account_name }}" storageContainerName: "{{ bundle.parameters.storage_container_name }}" outputs: - - name: "STORAGE_ACCOUNT_KEY" - key: "STORAGE_ACCOUNT_KEY" - - - exec: - description: "Emit the key in base64 encoded form" - command: ./helpers.sh - arguments: - - "dump-account-key {{bundle.outputs.STORAGE_ACCOUNT_KEY}}" + - name: storage_account_key + key: storage_account_key - terraform: description: "Create Azure CosmosDB and Event Hubs" @@ -109,7 +93,7 @@ install: key: "{{ bundle.name }}.tfstate" storage_account_name: "{{ bundle.parameters.storage_account_name }}" container_name: "{{ bundle.parameters.storage_container_name }}" - access_key: "{{ bundle.outputs.STORAGE_ACCOUNT_KEY }}" + access_key: "{{ bundle.outputs.storage_account_key }}" vars: subscription_id: "{{bundle.credentials.subscription_id}}" tenant_id: "{{bundle.credentials.tenant_id}}" @@ -119,8 +103,8 @@ install: resource_group_name: "{{bundle.parameters.resource_group_name}}" resource_group_location: "{{bundle.parameters.location}}" outputs: - - name: cosmos-db-uri - - name: eventhubs_connection_string + - name: cosmos-db-uri + - name: eventhubs_connection_string upgrade: - terraform: @@ -138,7 +122,7 @@ upgrade: key: "{{ bundle.name }}.tfstate" storage_account_name: "{{ bundle.parameters.storage_account_name }}" container_name: "{{ bundle.parameters.storage_container_name }}" - access_key: "{{ bundle.parameters.tf_storage_account_key }}" + access_key: "{{ bundle.outputs.storage_account_key }}" uninstall: - terraform: @@ -147,7 +131,7 @@ uninstall: key: "{{ bundle.name }}.tfstate" storage_account_name: "{{ bundle.parameters.storage_account_name }}" container_name: "{{ bundle.parameters.storage_container_name }}" - access_key: "{{ bundle.parameters.tf_storage_account_key }}" + access_key: "{{ bundle.outputs.storage_account_key }}" vars: subscription_id: "{{bundle.credentials.subscription_id}}" tenant_id: "{{bundle.credentials.tenant_id}}" diff --git a/examples/exec-outputs/cluster.sh b/examples/exec-outputs/cluster.sh index cfd014d7ca..29712cd8db 100755 --- a/examples/exec-outputs/cluster.sh +++ b/examples/exec-outputs/cluster.sh @@ -68,5 +68,12 @@ uninstall() { echo 'Uninstalling Cluster...' } +assert-admin() { + if [ "$1" != "sally" ]; then + echo "$1 is not an admin." + exit 1 + fi +} + # Call the requested function and pass the arguments as-is "$@" \ No newline at end of file diff --git a/examples/exec-outputs/porter.yaml b/examples/exec-outputs/porter.yaml index f600f77ec0..6c4f903f8e 100644 --- a/examples/exec-outputs/porter.yaml +++ b/examples/exec-outputs/porter.yaml @@ -48,9 +48,10 @@ install: jsonPath: "$.users[0]" - exec: description: "Use a step-level output" - command: echo + command: ./cluster.sh arguments: - - "The admin user is: {{ bundle.outputs.admin }}" + - assert-admin + - "{{ bundle.outputs.admin }}" add-user: - exec: @@ -105,3 +106,7 @@ outputs: path: /root/.kube/config applyTo: - install + - name: admin + type: string + applyTo: + - install diff --git a/pkg/cnab/config-adapter/testdata/porter-with-templating.yaml b/pkg/cnab/config-adapter/testdata/porter-with-templating.yaml index 56d72b2c67..e59d75b662 100644 --- a/pkg/cnab/config-adapter/testdata/porter-with-templating.yaml +++ b/pkg/cnab/config-adapter/testdata/porter-with-templating.yaml @@ -19,6 +19,8 @@ outputs: - name: tfstate type: file path: /cnab/app/outputs/tfstate + - name: name + type: string install: - exec: diff --git a/pkg/runtime/runtime-manifest.go b/pkg/runtime/runtime-manifest.go index 6367726056..5f1d78c66c 100644 --- a/pkg/runtime/runtime-manifest.go +++ b/pkg/runtime/runtime-manifest.go @@ -100,7 +100,15 @@ func resolveCredential(cd manifest.CredentialDefinition) (string, error) { } func (m *RuntimeManifest) resolveBundleOutput(def manifest.OutputDefinition) (string, error) { - // Get the output's value from the injected parameter source + // The output value may be tracked on the runtime manifest for use during the same action, + // if it is both a step output and a bundle-level output. In this case, the wiring parameter + // env var (used below) for bundle-level outputs will not yet contain the output value. + if m.outputs[def.Name] != "" { + return m.outputs[def.Name], nil + } + + // Get the output's value from the injected parameter source, which is used to wire up + // bundle-level outputs for subsequent actions. psParamEnv := manifest.GetParameterSourceEnvVar(def.Name) outputValue, ok := os.LookupEnv(psParamEnv) if !ok { @@ -232,7 +240,7 @@ func (m *RuntimeManifest) buildSourceData() (map[string]interface{}, error) { m.setSensitiveValue(stepOutput) } - // Iterate through the bundle-level manifests and resolve for interpolation + // Iterate through the bundle-level outputs and resolve for interpolation for _, outputDef := range m.GetTemplatedOutputs() { // TODO: ApplyTo can impact if the output is available // See https://github.com/deislabs/porter/issues/1159