Skip to content

Commit

Permalink
HPR-1514: Packer Nomenclature Version Data Source (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Sylvia Moss <[email protected]>
Co-authored-by: Jenna Goldstrich <[email protected]>
Co-authored-by: Devashish <[email protected]>
  • Loading branch information
4 people committed Jan 19, 2024
1 parent afacc47 commit f447f03
Show file tree
Hide file tree
Showing 77 changed files with 3,544 additions and 189 deletions.
7 changes: 7 additions & 0 deletions .changelog/tbd_HPR-1514.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:deprecation
`data.hcp_packer_iteration`: This data source will be removed in a future release, and is superseded by `data.hcp_packer_version`
```

```release-note:feature
`data.hcp_packer_version`: Added the `hcp_packer_version` data source, which replaces `data.hcp_packer_iteration`
```
7 changes: 7 additions & 0 deletions .changelog/tbd_HPR-1515.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:deprecation
`data.hcp_packer_image`: This data source will be removed in a future release, and is superseded by `data.hcp_packer_artifact`
```

```release-note:feature
`data.hcp_packer_artifact`: Added the `hcp_packer_artifact` data source, which replaces `data.hcp_packer_image`
```
93 changes: 93 additions & 0 deletions docs/data-sources/packer_artifact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
page_title: "Data Source hcp_packer_artifact - terraform-provider-hcp"
subcategory: "HCP Packer"
description: |-
The HCP Packer Artifact data source retrieves information about an Artifact.
---

# hcp_packer_artifact (Data Source)

The HCP Packer Artifact data source retrieves information about an Artifact.

## Example Usage

### Single artifact sourcing

```terraform
data "hcp_packer_artifact" "ubuntu-east" {
bucket_name = "hardened-ubuntu-16-04"
channel_name = "production"
platform = "aws"
region = "us-east-1"
}
output "packer-registry-ubuntu-east-1" {
value = data.hcp_packer_artifact.ubuntu-east.external_identifier
}
```

~> **Note:** The `channel` attribute in this data source may incur a billable request to HCP Packer. This attribute is intended for convenience when using a single artifact. When sourcing multiple artifacts from a single version, the `hcp_packer_version` data source is the alternative for querying a channel just once.

### Multiple artifact sourcing from a single version

```terraform
data "hcp_packer_version" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel_name = "production"
}
data "hcp_packer_artifact" "ubuntu-east" {
bucket_name = "hardened-ubuntu-16-04"
version_fingerprint = data.hcp_packer_version.hardened-source.fingerprint
platform = "aws"
region = "us-east-1"
}
data "hcp_packer_artifact" "ubuntu-west" {
bucket_name = "hardened-ubuntu-16-04"
version_fingerprint = data.hcp_packer_version.hardened-source.fingerprint
platform = "aws"
region = "us-west-1"
}
output "packer-registry-ubuntu-east-1" {
value = data.hcp_packer_artifact.ubuntu-east.external_identifier
}
output "packer-registry-ubuntu-west-1" {
value = data.hcp_packer_artifact.ubuntu-west.external_identifier
}
```

~> **Note:** This data source only returns the first found artifact's metadata filtered by the given arguments, from the returned list of artifacts associated with the specified version. Therefore, if multiple artifacts exist in the same region, it will only pick one of them. In this case, you can filter artifacts by a source build name (Ex: `amazon-ebs.example`) using the `component_type` optional argument.

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

### Required

- `bucket_name` (String) The name of the HCP Packer Bucket where the Artifact is located.
- `platform` (String) Name of the platform where the HCP Packer Artifact is stored. (i.e. aws, gce, azure)
- `region` (String) The Region where the HCP Packer Artifact is stored, if any.

### Optional

- `channel_name` (String) The name of the HCP Packer Channel the Version containing this Artifact is assigned to.
The Version currently assigned to the Channel will be fetched.
Exactly one of `channel_name` or `version_fingerprint` must be provided.
- `component_type` (String) Name of the Packer builder that built this Artifact. Ex: `amazon-ebs.example`.
- `project_id` (String) The ID of the HCP Organization where the Artifact is located
- `version_fingerprint` (String) The fingerprint of the HCP Packer Version where the Artifact is located.
If provided in the config, it is used to fetch the Version.
Exactly one of `channel_name` or `version_fingerprint` must be provided.

### Read-Only

- `build_id` (String) The ULID of the HCP Packer Build where the Artifact is located.
- `created_at` (String) The creation time of this HCP Packer Artifact.
- `external_identifier` (String) An external identifier for the HCP Packer Artifact.
- `id` (String) The ULID of the HCP Packer Artifact.
- `labels` (Map of String) Labels associated with the build containing this image.
- `organization_id` (String) The ID of the HCP Organization where the Artifact is located
- `packer_run_uuid` (String) The UUID of the build containing this image.
- `revoke_at` (String) The revocation time of the HCP Packer Version containing this Artifact. This field will be null for any Version that has not been revoked or scheduled for revocation.
52 changes: 1 addition & 51 deletions docs/data-sources/packer_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,7 @@ description: |-

The Packer Image data source gets an image associated with an iteration, either from a specific iteration or from the iteration assigned to a given Channel.

## Example Usage

### Single image sourcing

```terraform
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" {
value = data.hcp_packer_image.baz.cloud_image_id
}
```

~> **Note:** The `channel` attribute in this data source may 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 `hcp_packer_iteration` data source is the alternative for querying a channel just once.

### Multiple image sourcing from a single iteration

```terraform
data "hcp_packer_iteration" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel = "production"
}
data "hcp_packer_image" "foo" {
bucket_name = "hardened-ubuntu-16-04"
cloud_provider = "aws"
iteration_id = data.hcp_packer_iteration.hardened-source.ulid
region = "us-east-1"
}
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
}
```

~> **Note:** This data source only returns the first found image's metadata filtered by the given arguments, 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. In this case, you can filter images by a source build name (Ex: `amazon-ebs.example`) using the `component_type` optional argument.
~> **Deprecated:** This data source is deprecated and will be removed in a future release. Please use the [`hcp_packer_artifact`](./packer_artifact) data source instead.

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
9 changes: 1 addition & 8 deletions docs/data-sources/packer_iteration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ description: |-

The Packer Image data source iteration gets the most recent iteration (or build) of an image, given a channel.

## Example Usage

```terraform
data "hcp_packer_iteration" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel = "megan-test"
}
```
~> **Deprecated:** This data source is deprecated and will be removed in a future release. Please use the [`hcp_packer_version`](./packer_version) data source instead.

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
43 changes: 43 additions & 0 deletions docs/data-sources/packer_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
page_title: "hcp_packer_version Data Source - terraform-provider-hcp"
subcategory: "HCP Packer"
description: |-
The HCP Packer Version data source retrieves information about a Version.
---

# hcp_packer_version (Data Source)

The HCP Packer Version data source retrieves information about a Version.

## Example Usage

```terraform
data "hcp_packer_version" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel_name = "dev"
}
```

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

### Required

- `bucket_name` (String) The name of the HCP Packer Bucket where the Version is located
- `channel_name` (String) The name of the HCP Packer Channel the Version is assigned to.
The version currently assigned to the Channel will be fetched.

### Optional

- `project_id` (String) The ID of the HCP Organization where the Version is located

### Read-Only

- `author_id` (String) The name of the person who created this HCP Packer Version
- `created_at` (String) The creation time of this HCP Packer Version
- `fingerprint` (String) The fingerprint of the HCP Packer Version
- `id` (String) The ULID of the HCP Packer Version
- `name` (String) The name of the HCP Packer Version
- `organization_id` (String) The ID of the HCP Organization where the Version is located
- `revoke_at` (String) The revocation time of this HCP Packer Version. This field will be null for any Version that has not been revoked or scheduled for revocation
- `updated_at` (String) The last time this HCP Packer Version was updated
10 changes: 10 additions & 0 deletions examples/data-sources/hcp_packer_artifact/data-source-alt.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data "hcp_packer_artifact" "ubuntu-east" {
bucket_name = "hardened-ubuntu-16-04"
channel_name = "production"
platform = "aws"
region = "us-east-1"
}

output "packer-registry-ubuntu-east-1" {
value = data.hcp_packer_artifact.ubuntu-east.external_identifier
}
26 changes: 26 additions & 0 deletions examples/data-sources/hcp_packer_artifact/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
data "hcp_packer_version" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel_name = "production"
}

data "hcp_packer_artifact" "ubuntu-east" {
bucket_name = "hardened-ubuntu-16-04"
version_fingerprint = data.hcp_packer_version.hardened-source.fingerprint
platform = "aws"
region = "us-east-1"
}

data "hcp_packer_artifact" "ubuntu-west" {
bucket_name = "hardened-ubuntu-16-04"
version_fingerprint = data.hcp_packer_version.hardened-source.fingerprint
platform = "aws"
region = "us-west-1"
}

output "packer-registry-ubuntu-east-1" {
value = data.hcp_packer_artifact.ubuntu-east.external_identifier
}

output "packer-registry-ubuntu-west-1" {
value = data.hcp_packer_artifact.ubuntu-west.external_identifier
}
10 changes: 0 additions & 10 deletions examples/data-sources/hcp_packer_image/data-source-alt.tf

This file was deleted.

26 changes: 0 additions & 26 deletions examples/data-sources/hcp_packer_image/data-source.tf

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions examples/data-sources/hcp_packer_iteration/data-source.tf

This file was deleted.

4 changes: 0 additions & 4 deletions examples/data-sources/hcp_packer_iteration/variables.tf

This file was deleted.

4 changes: 4 additions & 0 deletions examples/data-sources/hcp_packer_version/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "hcp_packer_version" "hardened-source" {
bucket_name = "hardened-ubuntu-16-04"
channel_name = "dev"
}
31 changes: 30 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@ module github.com/hashicorp/terraform-provider-hcp

go 1.21

// TODO: FOR_EXTERNAL: Remove this replace directive once the HCP Packer v2 API is
// in the public SDK. Look for other `TODO: FOR_EXTERNAL:` comments in the code
// for a non-exhaustive list of other places that need to be updated for some
// reason.
//
// This replace directive assumes that this `terraform-provider-hcp` directory
// is a sibling of the `hcp-sdk-go` directory, containing your local clone of
// the HCP SDK. If you have the SDK cloned elsewhere, you'll need to adjust it
// to be in this location for the other import changes to work, or update those
// as well. Ideally, both packages will be located in `~/go/src/github.com/hashicorp/`
// as `~/go/src/github.com/hashicorp/hcp-sdk-go` and `~/go/src/github.com/hashicorp/terraform-provider-hcp`.
//
// If you are using a branch from the `hcp-sdk-go-internal` repo, you'll need
// to add it as another remote of `hcp-sdk-go` in `~/go/src/github.com/hashicorp/hcp-sdk-go`
// and then checkout the branch/commit you want to use.
// For example:
// ```
// cd ~/go/src/github.com/hashicorp/hcp-sdk-go
// git remote add internal [email protected]:hashicorp/hcp-sdk-go-internal.git
// git fetch --all
// git checkout internal/main
// ```
// Just be careful not to leak the internal repo history to the public repo as
// the `hcp-sdk-go-internal` repo git tree is not the same as the `hcp-sdk-go`
// repo git tree, but some branches on `hcp-sdk-go-internal` may have been
// branched from `hcp-sdk-go` branches instead. You might want to check the
// commit history to see which remote your branch is based on.
replace github.com/hashicorp/hcp-sdk-go => ../hcp-sdk-go-internal

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/go-openapi/runtime v0.26.2
Expand Down Expand Up @@ -78,7 +107,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/oklog/ulid v1.3.1
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/posener/complete v1.2.3 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ github.com/hashicorp/hc-install v0.6.2 h1:V1k+Vraqz4olgZ9UzKiAcbman9i9scg9GgSt/U
github.com/hashicorp/hc-install v0.6.2/go.mod h1:2JBpd+NCFKiHiu/yYCGaPyPHhZLxXTpz8oreHa/a3Ps=
github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI=
github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE=
github.com/hashicorp/hcp-sdk-go v0.80.0 h1:oKGx7+X0llBN5NEpkWg0Qe3x9DIAH6cc3MrxZptDB7Y=
github.com/hashicorp/hcp-sdk-go v0.80.0/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81SpgVtZNNtFSM=
Expand Down
Loading

0 comments on commit f447f03

Please sign in to comment.