Deploying Kontena Pharos Cluster with Terraform

Overview

The pharos CLI tool can read information from Terraform JSON output. In this scenario cluster.yml contents can be partially read from a Terraform JSON output file.

Terraform output JSON integration can be enabled with --tf-json option, for example:

$ terraform apply
$ terraform output -json > tf.json
$ pharos up -c cluster.yml --tf-json tf.json

This example can be also executed as a single step:

$ pharos tf apply -c cluster.yml

To tear-down cluster:

$ pharos tf destroy

Terraform Output Configuration

This output format works only with Terraform >= 0.12.

Full cluster.yml configuration can be generated via pharos_cluster output. It's also possible to generate partial configuration which is then merged to cluster.yml contents (using deep-merge).

Example:

output "pharos_cluster" {
    value = {
        hosts = [
            for host in concat(aws_instance.pharos_master, aws_instance.pharos_worker)  : {
                address           = host.public_ip
                private_address   = host.private_ip
                role              = host.tags["role"]
                user              = "root"
                container_runtime = "${var.container_runtime}"
            }
        ]
        addons = {
            ingress-nginx = {
                enabled = true
            }
        }
    }
}

Legacy Terraform Output Configuration

This output format works only with Terraform < 0.12.x. Output value will be merged to cluster.yml contents so it's possible to generate only partial configuration via Terraform (usually hosts).

Setting Hosts

hosts array in Kontena Pharos cluster.yml can be set via pharos_hosts output.

For example:

output "pharos_hosts" {
  value = {
    masters = {
      address         = "${aws_instance.pharos_master.*.public_ip}"
      private_address = "${aws_instance.pharos_master.*.private_ip}"
      role            = "master"
      user            = "ubuntu"
    }

    workers = {
      address         = "${aws_instance.pharos_worker.*.public_ip}"
      private_address = "${aws_instance.pharos_worker.*.private_ip}"
      role            = "worker"
      user            = "ubuntu"

      label = {
        ingress = "nginx"
      }
    }
  }
}

is equal to:

hosts:
  - address: "..."
    private_address: "..."
    role: "master"
    user: "ubuntu"
  - address: "..."
    private_address: "..."
    role: "worker"
    user: "ubuntu"
    labels:
      ingress: "nginx"

in cluster.yml.

Setting Addon Values

It's possible to set addon values in Kontena Pharos cluster.yml via pharos_addons output.

For example:

output "pharos_addons" {
  value = {
    my-addon = {
      enabled = true
      region = "eu-west-1"
    }
  }
}

is equal to:

addons:
  my-addon:
    enabled: true
    region: "eu-west-1"

in cluster.yml.

Setting API Endpoint

api.endpoint in Kontena Pharos cluster.yml can be set via pharos_api output.

For example:

output "pharos_api" {
  value = {
    endpoint = "my.kubernetes-api.com"
  }
}

is equal to:

api:
  endpoint: "my.kubernetes-api.com"

in cluster.yml.

Full Examples

results matching ""

    No results matching ""