hashicorp / hashicorp/packer

Support Centralized Provider Configurations

Open
#11,877 3 comments 5 reactions 0 assignees View on GitHub
enhancement hcl2
Dominant language
Go
Stars
15.8k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

#### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) 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

#### Description

Assume you're building many templates for your organization or a large build farm consisting of several operating systems, architectures, and configurations. As a result, you end up with many different Packer templates. Some provider-specific information, like how to authenticate, which hosts to use, and whatnot, is being duplicated everywhere. You could define a local or variable and reuse that, but the extra boilerplate adds noise to the templates.

This feature request is to be able to centralize the configuration of a provider and reuse that. The provider can be seen as having defaults that sources and builders can use if nothing is specified but perhaps be overwritten in the builder and sources themselves.

#### Use Case(s)

You tend to duplicate provider-specific information when you have numerous packer templates using VMware vSphere (as an example). It just adds toil and unnecessary boilerplate. With this feature request, we can reduce the boilerplate required by Packer and reuse the configuration.

#### Potential configuration

Taken from Terraform

```
provider "vsphere" {
host = var.vsphere_host
insecure_connection = true
username = var.vcenter_username
password = var.vcenter_password
vcenter_server = var.vcenter_server
folder = var.vcenter_folder
datastore = var.vsphere_datastore
}

source "vsphere-clone" "ubuntu-2204" {
// will use the single vSphere provider defined earlier
}

source "vsphere-clone" "ubuntu-2004" {
// will use the single vSphere provider defined earlier
}

source "vsphere-clone" "rhel7" {
// will use the single vSphere provider defined earlier
}

source "vsphere-clone" "rhel9" {
// will use the single vSphere provider defined earlier
}
```

Or, in the case where you need to support multiple isolated installations of VMware vSphere (as an example):

```
provider "vsphere" {
alias = "oak02"
// oak02 specific information
}

provider "vsphere" {
alias = "sjc01"
// sjc01 specific information
}

source "vsphere-clone" "ubuntu-2204-sjc01" {
provider = vsphere.sjc01
// will use the SJC01 vSphere provider defined earlier
}

source "vsphere-clone" "ubuntu-2204-oak02" {
provider = vsphere.oak02
// will use the OAK02 vSphere provider defined earlier
}

```

Something Terraform does not support but would be somewhat helpful is something as follows:

```
provider "vsphere" {
alias = "oak02"
// oak02 specific information
}

provider "vsphere" {
alias = "sjc01"
// sjc01 specific information
}

source "vsphere-clone" "ubuntu-2204" {
providers = [vsphere.sjc01, vsphere.oak02]
// This is essentially doing a foreach provider.
}

```

I'm using VMware vSphere purely for illustrative examples. It also applies to other providers.

#### Potential References

- [Provider Configuration](https://www.terraform.io/language/providers/configuration)

Contributor guide

Open the contributing guide

Research direction

No implementation files or tests are named. Start by comparing the proposed provider blocks and aliases with Packer's existing template configuration model, then determine how defaults, overrides, and multiple providers should be represented. Done means centralized provider settings can be reused by sources and builders, including isolated aliases, with appropriate validation and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
terraform
Domain
devtools, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.