Skip to content

trackbone: support outputs via attributes

Ghost User requested to merge outputs into master

Outputs are implemented using attributes. Outputs can be used to pass values between configurations whether it is static values or dynamic values.

For example a configuration creates a network and can output the created network ID. Another configuration can get this output as an input and use it in it's configuration.

Same principle as terraform remote state, but the advantage is that an helm configuration will be able to consume outputs produced by a terraform configuration.

Outputs can be added to any field of the configuration whether the field has a static value or the result of some task with the @output(name=...) attribute.

envs: y: {
        configurations: configA: #TFConfig & {
                run: actions: post_tasks: tf_outputs: file#Read & {
                        name: "output.json"
                        format: "json"
                        content: id: {
                                value: string @output(name=output_id)
                        }
                }
        }
}

In this example the configuration has a post task that reads outputs produced by terraform from a JSON file. One of TF outputs is tagged with the @output attribute.

Attribute param name is optional. If not set the name of the field is used.

Outputs are serialized and stored in an external backend (file, S3, ...) depending on trackbone configuration. For example in trackbone configuration one can define:

trackbone: tb.#TBConfig & {
        backend: basedir: "/tmp/local-backend"
}

This will use a local directory to store configurations state.

Configurations can get other configurations outputs using the io.#Outputs task. When using outputs from another configuration an implicit dependency is created in trackbone graph:

envs: y: {
	configurations: configA: #TFConfig & {
                run: actions: post_tasks: tf_outputs: file#Read & {
                        name: "output.json"
                        format: "json"
                        content: id: {
                                value: string @output(name=id)
                        }
                }
	}
	configurations: configB: #TFConfig & {
		// Fetch some output
		run: actions: pre_tasks: configA_outputs: io.#Outputs & {
			env:    "y"
			config: "config_output"
			outputs: id: string
		}
		tfvars: input: run.actions.pre_tasks.configA_outputs.outputs.id
	}
}

In this example configA defines an output named id. configB uses a task to retrieve configA outputs and use id output value in tfvars.

Because configB uses configA outputs if both configurations are run configB will be run after configA to make sure it is using the latest output values.

A new subcommand 'outputs' is added and can be used to view some configuration outputs.

Edited by Ghost User

Merge request reports

Loading