Skip to content
/ yc-ig Public

Build image with packer on yandex cloud and deploy in yandex cloud as instance group

Notifications You must be signed in to change notification settings

Savemech/yc-ig

Repository files navigation

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

About

Build image with packer on yandex cloud and deploy in yandex cloud as instance group

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published