Skip to content

Commit

Permalink
wip: update azure-terraform bundle; maybe found bug in step outputs?
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <vadice@microsoft.com>
  • Loading branch information
vdice committed Aug 11, 2020
1 parent b5e3e34 commit 4fb9f99
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 49 deletions.
4 changes: 2 additions & 2 deletions examples/azure-terraform/arm/storage.json
Expand Up @@ -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]"
}
}
Expand Down
9 changes: 0 additions & 9 deletions examples/azure-terraform/helpers.sh

This file was deleted.

52 changes: 18 additions & 34 deletions 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:
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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}}"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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}}"
Expand Down
7 changes: 7 additions & 0 deletions examples/exec-outputs/cluster.sh
Expand Up @@ -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
"$@"
9 changes: 7 additions & 2 deletions examples/exec-outputs/porter.yaml
Expand Up @@ -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:
Expand Down Expand Up @@ -105,3 +106,7 @@ outputs:
path: /root/.kube/config
applyTo:
- install
- name: admin
type: string
applyTo:
- install
2 changes: 2 additions & 0 deletions pkg/cnab/config-adapter/testdata/porter-with-templating.yaml
Expand Up @@ -19,6 +19,8 @@ outputs:
- name: tfstate
type: file
path: /cnab/app/outputs/tfstate
- name: name
type: string

install:
- exec:
Expand Down
12 changes: 10 additions & 2 deletions pkg/runtime/runtime-manifest.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4fb9f99

Please sign in to comment.