Giter Club home page Giter Club logo

baking-images-on-azure's Introduction

baking-images-on-azure

Baking Images on Azure using Packer and Ansible

Configuration

1. Install azcli

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

2. Install Terraform & Packer

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common gpg
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y packer terraform

3. Create Azure Service Principal

az login --use-device-code

// Copy the Output after SP Creation and save it
az ad sp create-for-rbac
--role="Contributor"
--scopes="/subscriptions/<$subscriptionid>"

4. Create Terraform Blob Storage to store state file

There is a script in the repo named backend-storage.sh to create the azure storage account and container. Please dont forget to change the values in the script, according to your needs.

backend-storage.sh <RESOURCE_GROUP_NAME> <STORAGE_ACCOUNT_NAME> <CONTAINER_NAME> <LOCATION>

5. Exporting environment variables of SP for ARM authentication

Export the SP credentials that you created in the previous step (3) into shell, so that Terraform automatically reads the Environment variables and use it authenticate with Azure Resource Manager (ARM)

export ARM_CLIENT_ID=
export ARM_SUBSCRIPTION_ID=
export ARM_TENANT_ID=
export ARM_CLIENT_SECRET=
export ARM_ACCESS_KEY=

6. Terraform execute

terraform init
terraform apply -var-file=auto.tfvars

Packer

1. Format and validate Packer

packer init .
packer fmt -recursive .
packer validate -var-file="auto.pkrvars.hcl"

2. Build Packer

packer build -force -var-file="auto.pkrvars.hcl" \
             -var "azure_client_id=$ARM_CLIENT_ID" \
             -var "azure_client_secret=$ARM_CLIENT_SECRET" \
             -var "azure_subscription_id=$ARM_SUBSCRIPTION_ID" \
             -var "azure_tenant_id=$ARM_TENANT_ID" \
             .

Tips

  1. List out the availiable SKUs on the region
az vm list-skus --location southeastasia --size Standard_D --all --output table
  1. Remove all the published versions in the SIG before destroying it via terraform. Terraform is not knowing about the current state

References

  1. Creating Azure Virtual Desktop using Terraform
  2. Github Repo by Andreas Fleischmann
  3. Github Repo by GO-EUC

baking-images-on-azure's People

Contributors

mysticrenji avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.