Version1: Raw Direktiv Image
Version2: Use Terroform 1.3.2
Version3: Pretty Print with -no-color
Version4: Add Print info to get Aid
Version5: Add variable: consul-addr and handler logic
Version6: Fix args-on-init bug , no consist with 1.3.2
An example workflow of using the container on Direktiv. Notice we're providing the terraform file from the functions array. Which puts it into a temp directory where we call Terraform from.
description: "test how to use terraform"
functions:
- id: terraform
image: westwind027/terraform:v7
type: knative-workflow
states:
- id: run-terraform
type: action
action:
function: terraform
files:
- key: main.tf
scope: workflow
type: plain
input:
action: "apply"
variables:
"state-name": "terraform-nginx"
"consul-addr": "http://192.168.50.157:8500"
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 2.13.0"
}
}
backend "consul" {
address = "192.168.50.157:8500"
scheme = "http"
path = "terraform-nginx"
}
}
provider "docker" {
host = "tcp://192.168.50.167:2375"
}
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "nginx_tf"
ports {
internal = 80
external = 8000
}
}
output "container_id" {
description = "ID of the Docker container"
value = docker_container.nginx.id
}
output "image_id" {
description = "ID of the Docker image"
value = docker_image.nginx.id
}
variable "state-name" {
description = "Value of the name for state"
type = string
default = "terraform-nginx"
}
Passing the above 'consul-addr' and variable 'state-name' will allow the container to use a consul backend for Terraform to store the state. If not provided the state will be returned in the JSON output.
Note: the variable 'state-name' needs to match the path on the 'backend' path.
Note: the variable 'consul-addr' needs to match backend 'addr' and 'schema' config.
If the action is successful, the output should contain any outputs written in Terraform and the Terraform state.
{
"output": {},
"tfstate": {}
}
In the case that an error is encountered it will present in the following format:
{
"errorCode": "com.terraform.%s.error",
"errorMsg": "Something went wrong"
}
Note: '%s' will be replaced with a contextual error.
Content type
Image
Digest
sha256:8dfb00b84…
Size
54.3 MB
Last updated
almost 4 years ago
docker pull westwind027/terraform