Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 2.06 KB

README.md

File metadata and controls

73 lines (54 loc) · 2.06 KB

yc-ig-packer-tf

Prerequisites

As using any Hashicorp software you're presumably read and agree with following licenses terraform packer

In this example we would:

  • Build image with some code to use
    • Based on Ubuntu 18.04

Now set some variables to work with packer and then terraform:

unset IMAGE_FAMILY
unset PACKER_APPNAME
unset PACKER_BUILDTIME
unset IMAGE_NAME
unset TF_VAR_packer_buildtime
unset TF_VAR_image_id
unset TF_VAR_image_name

export IMAGE_FAMILY=ubuntu-1804
export PACKER_APPNAME=dwno
export PACKER_BUILDTIME=$(date +%Y-%m-%d--%H-%M)
export IMAGE_NAME=${IMAGE_FAMILY}-${PACKER_APPNAME}-${PACKER_BUILDTIME}

Packer part

Build image:

packer build -machine-readable image.json | tee output

export TF_VAR_packer_buildtime=${PACKER_BUILDTIME}
export TF_VAR_image_id=$(grep -e "yandex,artifact,0,id," output | cut -d"," -f6)
export TF_VAR_image_name=${IMAGE_NAME}

This terraform code perform following actions: Create/Update:

tf output -json | jq -r '.[]| .value'

Now to the target group part

yc compute ig  --id $(tf output -json | jq -r '.[]| .value') list-instances --format json | jq -r '.[].network_interfaces  | .[].primary_v4_address  | .address'

Terraform part

Watch out, and you need sane defaults for this block, in my case for testing, is OK to some application unavailability

 deploy_policy {
    max_unavailable = "${var.cluster_size}"
    max_creating    = "${var.cluster_size}"
    max_expansion   = "${var.cluster_size}"
    max_deleting    = "${var.cluster_size}"
  }
terraform apply -auto-approve -parallelism=50