Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and Validate throw and error for valid ami_name #13157

Closed
dylanfoster opened this issue Sep 3, 2024 · 2 comments
Closed

Build and Validate throw and error for valid ami_name #13157

dylanfoster opened this issue Sep 3, 2024 · 2 comments

Comments

@dylanfoster
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

Both packer validate and packer build are throwing an error for a valid ami_name. I'm using timestamp and format to build the ami_name but even with trimmed down string it still throws the error. More interestingly, the build still runs and the ami is built with the name specified. If I use -only the error is not generated.

I should note that I have my source and build blocks separated as it's building several different amis off of the same source, but other image configurations I have that only have a single build template do not generate this error

Reproduction Steps

Create a packer file to have your source definition
Create another packer file with your build definition.

Packer version

From packer version

Simplified Packer Template

gist

Operating system and Environment details

OS, Architecture, and any other information you can provide about the
environment.

Log Fragments and crash.log files

Error: 2 error(s) occurred:

* ami_name must be specified
* ami_name must be between 3 and 128 characters long

  on packer/devops/jenkins-agents/sources.pkr.hcl line 10:
  (source code not available)

Error: 2 error(s) occurred:

* ami_name must be specified
* ami_name must be between 3 and 128 characters long

  on packer/devops/jenkins-agents/sources.pkr.hcl line 10:
  (source code not available)

Error: 2 error(s) occurred:

* ami_name must be specified
* ami_name must be between 3 and 128 characters long

  on packer/devops/jenkins-agents/sources.pkr.hcl line 10:
  (source code not available)

Error: 2 error(s) occurred:

* ami_name must be specified
* ami_name must be between 3 and 128 characters long

  on packer/devops/jenkins-agents/sources.pkr.hcl line 10:
  (source code not available)
@dylanfoster dylanfoster added the bug label Sep 3, 2024
@nywilken
Copy link
Member

nywilken commented Sep 5, 2024

Hi @dylanfoster thanks for reaching out and for providing the detailed issue.

Looking at the configurations I see that you have a main source block source "amazon-ebs" "debian-docker-base", which you then reference in the build blocks contained in build.android.pkr.hcl and build.web.pkr.hcl.

Are "web" and "android" the builds you are referring to when you say "the build still runs and the ami is built"?

Since you are you are including sources = ["source.amazon-ebs.debian-docker-base"] in each of the build blocks Packer will try to execute a build for the base source block but will fail with the error you provided because ami_name is not set.

Given the configuration of your template setting an ami_name in sources.pkr.hcl will prevent you from overriding the ami_name in other source references. So I suggest replacing the sources = ["source.amazon-ebs.debian-docker-base"] in build.android.pkr.hcl and build.web.pkr.hcl with another source reference block. For example

#build.android.pkr.hcl
build {
  name = "android"

  source "amazon-ebs.debian-docker-base" {
    name = "android"

    ami_name        = "images/jenkins-agent-android"
    ami_description = local.ami-description["android"]

    tags = merge(
      local.default-tags,
      {
        Name                  = "jenkins-agent-android"
        "Android API Version" = "system-images;android-25;google_apis;armeabi-v7a"
        "Android SDK Version" = "sdk-tools-linux-4333796"
      }
    )
  }

  source "amazon-ebs.debian-docker-base" {
    name = "base" # Change this name to what you see fit

    ami_name        = "images/jenkins-agent-base"
    ami_description = "base description"
    .....
  }
}

Alternatively if the source block in sources.pkr.hcl is just meant to be a shared cofiguration that you reference in other build blocks you can just remove ["source.amazon-ebs.debian-docker-base"] from each build block.

Please let use know if this suggested change resolves your issue.

@dylanfoster
Copy link
Author

Thanks. Just removing the sources = [] worked to resolve the issue. Just using the main source block for each

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants