Coder Social home page Coder Social logo

hcp-packer-ubuntu22's Introduction

Demo builds for HCP Packer

A collection of Packer builds for Ubuntu 22.04 (jammy) which publish to the HCP Packer registry. Used to demonstrate image channels, ancestry, revocation, and Terraform integrations.

Requirements

Packer v1.10.1 or higher.

To build all images, AWS and Azure credentials must be available using one of the following mechanisms:

  • AWS: environment variables, credential file, or run from an EC2 instance with an instance profile
  • Azure: CLI (az login), Azure AD interactive login, or run from an Azure VM with a managed identity

An HCP Packer organization, with a "Contributor" service principal key set via the HCP_CLIENT_ID and HCP_CLIENT_SECRET environment variables.

For Azure:

  • An existing resource group where the builds will take place
  • An Azure Compute Gallery in the same resource group, where images will be published
  • Image definition(s) in the gallery corresponding to the shared_image_gallery_destination.image_name property of each build

Usage

Copy variables.pkrvars.hcl.example to variables.pkrvars.hcl and customize.

Run the build script: ./build.sh <build_name> Where build_name is one of the subfolders - base (must be built first), db, or web.

Or if you're not on Linux/macOS, you can run Packer directly (ex: in a Windows PowerShell): packer -var-file ./variables.pkrvars.hcl ./<base|db|web>

To build only the AWS or Azure images but not both, comment out the provider-specific references in each config file (data source, source block, and entry in the build->sources list).

Terraform integration

Use the "Use as data source" code generator in the HCP Packer UI to generate a Terraform hcp_packer_artifact data source block.

Example:

data "hcp_packer_artifact" "ubuntu22-nginx" {
  bucket_name  = "ubuntu22-nginx"
  channel_name = "production"
  platform     = "aws"
  region       = "us-east-1"
}

# Then replace your existing references with
# data.hcp_packer_artifact.ubuntu22-nginx.external_identifier

To integrate with Terraform Cloud continuous validation, add a lifecycle postcondition block to your instance/VM resource:

AWS:

resource "aws_instance" "my_ec2" {
  # ... resource config ...

  lifecycle {
    postcondition {
      condition     = self.ami == data.hcp_packer_artifact.ubuntu22-nginx.external_identifier
      error_message = "A new source AMI is available in the HCP Packer channel."
    }    
  }
}

Azure:

resource "azurerm_linux_virtual_machine" "my_vm" {
  # ... resource config ...

  lifecycle {
    postcondition {
      condition     = self.source_image_id == data.hcp_packer_artifact.ubuntu22-nginx.external_identifier
      error_message = "A new source image is available in the HCP Packer channel."
    }    
  }
}

hcp-packer-ubuntu22's People

Contributors

danbarr avatar

Watchers

 avatar  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.