Skip to content

Instantly share code, notes, and snippets.

@nak3
Created July 2, 2017 02:39
Show Gist options
  • Save nak3/0540757c02aca20191c7b47f9a1365e0 to your computer and use it in GitHub Desktop.
Save nak3/0540757c02aca20191c7b47f9a1365e0 to your computer and use it in GitHub Desktop.

Getting start with Azure, packer and terraform

Recently, I started using Azure for my test env. This is a reminder for myself.

Preparation

Install Azure CLI

How https://github.com/Azure/azure-cli

NOTE Both v1 and v2 are installed, as packer's azure-setup.sh requires v1.

Clone lab repository

git clone git@github.com:nak3/lab3.git
cd lab3

Creating a quick VM

This just creates single VM instance from CentOS image.

azure vm quick-create -M ~/.ssh/id_rsa.pub \
      --location southeastasia \
      -g ${RESOURCE_GROUP} \
      -n centos73-01 \
      -Q OpenLogic:CentOS:7.3:7.3.20170612 \
      -y Linux \
      --admin-username ${USERNAME} \
      --admin-password ${PASSWORD}

Creating ARM with Paker

Setting up the account info.

wget https://raw.githubusercontent.com/hashicorp/packer/master/contrib/azure-setup.sh
bash azure-setup.sh setup
cd packer
cp variables.sample.json variables.json
vim variables.sample.json

Run packer

$GOBIN/packer build -var-file=variables.json

Creating ARM from created image

az image create \
  --resource-group ${RESOURCE_GROUP} \
  --name nak3testimage \
  --os-type linux \
  --source ${IMAGE_ID}

Deploy clusters

setup the account

cd terraform/centos7-cluster
cp terraform.tfvars.template terraform.tfvars
vim terraform.tfvars.template

Reference: https://www.terraform.io/docs/providers/azurerm/

deploy clusters

$GOBIN/terraform init
$GOBIN/terraform plna
$GOBIN/terraform apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment