Skip to content

Commit

Permalink
docs: add packer_image alts examples
Browse files Browse the repository at this point in the history
With the introduction of `channel' in hcp_packer_image, we add some more
examples in the documentation for the data_source.
  • Loading branch information
lbajolet-hashicorp committed Jun 30, 2022
1 parent 8206f46 commit 1809ea9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
30 changes: 29 additions & 1 deletion docs/data-sources/packer_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The Packer Image data source iteration gets the most recent iteration (or build)
## Example Usage

```terraform
# If sourcing multiple images
data "hcp_packer_iteration" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel = "production"
Expand All @@ -24,13 +26,39 @@ data "hcp_packer_image" "foo" {
region = "us-east-1"
}
output "packer-registry-ubuntu" {
data "hcp_packer_image" "bar" {
bucket_name = "hardened-ubuntu-16-04"
cloud_provider = "aws"
iteration_id = data.hcp_packer_iteration.hardened-source.ulid
region = "us-west-1"
}
output "packer-registry-ubuntu-east-1" {
value = data.hcp_packer_image.foo.cloud_image_id
}
output "packer-registry-ubuntu-west-1" {
value = data.hcp_packer_image.bar.cloud_image_id
}
# Alternatively if sourcing a single image
data "hcp_packer_image" "baz" {
bucket_name = "hardened-ubuntu-16-04"
cloud_provider = "aws"
channel = "production"
region = "us-east-1"
}
output "packer-registry-ubuntu-east-1-alt" {
value = data.hcp_packer_image.baz.cloud_image_id
}
```

~> **Note:** This data source only returns the first found image's metadata filtered by the given schema values, from the returned list of images associated with the specified iteration. Therefore, if multiple images exist in the same region, it will only pick one of them. If that's the case, you may consider separating your builds into different buckets.

~> **Note:** The `channel` attribute in this data source will incur a billable request to HCP Packer. This attribute is intended for convenience when using a single image. When sourcing multiple images from a single iteration, the separate data source object for the iteration alternative is preferred for saving costs.

<!-- schema generated by tfplugindocs -->
## Schema

Expand Down
28 changes: 27 additions & 1 deletion examples/data-sources/hcp_packer_image/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# If sourcing multiple images

data "hcp_packer_iteration" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel = "production"
Expand All @@ -10,6 +12,30 @@ data "hcp_packer_image" "foo" {
region = "us-east-1"
}

output "packer-registry-ubuntu" {
data "hcp_packer_image" "bar" {
bucket_name = "hardened-ubuntu-16-04"
cloud_provider = "aws"
iteration_id = data.hcp_packer_iteration.hardened-source.ulid
region = "us-west-1"
}

output "packer-registry-ubuntu-east-1" {
value = data.hcp_packer_image.foo.cloud_image_id
}

output "packer-registry-ubuntu-west-1" {
value = data.hcp_packer_image.bar.cloud_image_id
}

# Alternatively if sourcing a single image

data "hcp_packer_image" "baz" {
bucket_name = "hardened-ubuntu-16-04"
cloud_provider = "aws"
channel = "production"
region = "us-east-1"
}

output "packer-registry-ubuntu-east-1-alt" {
value = data.hcp_packer_image.baz.cloud_image_id
}
2 changes: 2 additions & 0 deletions templates/data-sources/packer_image.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ description: |-

~> **Note:** This data source only returns the first found image's metadata filtered by the given schema values, from the returned list of images associated with the specified iteration. Therefore, if multiple images exist in the same region, it will only pick one of them. If that's the case, you may consider separating your builds into different buckets.

~> **Note:** The `channel` attribute in this data source will incur a billable request to HCP Packer. This attribute is intended for convenience when using a single image. When sourcing multiple images from a single iteration, the separate data source object for the iteration alternative is preferred for saving costs.

{{ .SchemaMarkdown | trimspace }}

0 comments on commit 1809ea9

Please sign in to comment.