Code Monkey home page Code Monkey logo

Comments (8)

ethanmdavidson avatar ethanmdavidson commented on July 4, 2024 1

Thank you so much for the PR! As you could probably see from the code, I am no master of Go either. I will try to review it this weekend.

from packer-plugin-git.

daroga0002 avatar daroga0002 commented on July 4, 2024 1

@sydrawat01 also you can do just packer validate -syntax-only . which will be checking does code is correctly written (all HCL references and etc.)

from packer-plugin-git.

ethanmdavidson avatar ethanmdavidson commented on July 4, 2024

No, there isn't currently a datasource which returns the branch. However, it should be pretty easy to build. I might add it myself if I have some free time, but PRs are also welcome :)

from packer-plugin-git.

daroga0002 avatar daroga0002 commented on July 4, 2024

I am not a master of go but I have created PR to address it. Please take a look when you will have a time

from packer-plugin-git.

sydrawat01 avatar sydrawat01 commented on July 4, 2024

Ca we have an example on how to use this? It would add great detail to the documentation!

from packer-plugin-git.

daroga0002 avatar daroga0002 commented on July 4, 2024

it is documented here:
https://github.com/ethanmdavidson/packer-plugin-git/blob/main/docs/datasources/commit.mdx

In my project I am using this as:

variable "ubuntu_version" {
  description = "Variable with version of AMI"
  type = string
}


locals {
  truncated_sha   = substr(data.git-commit.cwd-head.hash, 0, 8)
  version         = data.git-repository.cwd.head == "master" && data.git-repository.cwd.is_clean ? var.ubuntu_version : "${var.ubuntu_version}-${local.truncated_sha}"
}

data "git-repository" "cwd" {}

data "git-commit" "cwd-head" {}

so on the end local.version is variable which I am using:

source "amazon-ebs" "ubuntu" {
  ami_name          = "ubuntu-${local.version}"
  .......................

from packer-plugin-git.

sydrawat01 avatar sydrawat01 commented on July 4, 2024

Thanks for the example @daroga0002 ! I did try to use this as an example in my packer template, but it throws me an error saying the AMI name is invalid when i run packer validate . command:

Error: 1 error(s) occurred:

* AMIName should only contain alphanumeric characters, parentheses (()), square brackets ([]), spaces ( ), periods (.), slashes (/), dashes (-), single quotes ('), at-signs (@), or underscores(_). You can use the `clean_resource_name` template filter to automatically clean your ami name.

  on ami.pkr.hcl line 48:
  (source code not available)

Here's a snippet of my ami.pkr.hcl file where it fails:

.....
variable "ubuntu_version" {
  type        = string
  description = "Version of the custom AMI"
}

locals {
  truncated_sha = substr(data.git-commit.cwd-head.hash, 0, 8)
  version       = data.git-repository.cwd.head == "master" && data.git-repository.cwd.is_clean ? var.ubuntu_version : "${var.ubuntu_version}-${local.truncated_sha}"
}


data "git-repository" "cwd" {}
data "git-commit" "cwd-head" {}

source "amazon-ebs" "ubuntu" {
  region   = "${var.aws_region}"
  ami_name = "ubuntu-${local.version}"
  .....

Can't seem to find what I'm doing wrong here. I also didn't find any specific rules as to what the AMI name should follow, so it's a bit vague to me what not to name my AMI, because I wanted to have it specific to the PR during CI/CD workflows on GitHub actions.

from packer-plugin-git.

daroga0002 avatar daroga0002 commented on July 4, 2024

this is packer bug, if you run packer build it should go without issues.

In general looks that validate doesnt trying to predict a values for variables.

from packer-plugin-git.

Related Issues (11)

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.