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

Data source for packer registry #169

Merged
merged 40 commits into from
Aug 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5d91f37
add file for packer registry
SwampDragons Jul 12, 2021
e594afe
add packe registry to provider.go
SwampDragons Jul 12, 2021
d381e02
packer client
SwampDragons Jul 13, 2021
9092ab2
WIP
azr Jul 14, 2021
d1867aa
Merge branch 'data_source_packer_registry' of ssh://github.com/hashic…
azr Jul 14, 2021
3be9aca
flattenPackerBuildList
azr Jul 14, 2021
7500dac
fix pointer type errors after dependency update
azr Jul 14, 2021
76bb967
Update data_source_packer_image.go
azr Jul 14, 2021
bfe5099
add & run tests
azr Jul 15, 2021
1d3ed90
Update data_source_packer_image.go
azr Jul 15, 2021
ff12e1e
it works !
azr Jul 16, 2021
66254ef
go mod tidy
azr Jul 21, 2021
7afcdc7
fix description for bucket
azr Jul 27, 2021
8063413
nest iteration stuff under iteration
azr Jul 27, 2021
be602f5
start showing builds & hcp_packer_image -> hcp_packer_image_iteration
azr Jul 27, 2021
4dbb8bd
Revert "fix pointer type errors after dependency update"
azr Jul 27, 2021
5cb2338
Update internal/provider/data_source_packer_image_iteration.go
azr Jul 28, 2021
2db3cba
Update internal/provider/data_source_packer_image_iteration.go
azr Jul 28, 2021
aa1be36
up go mods
azr Jul 28, 2021
9874c8b
Update data_source_packer_image_iteration.go
azr Jul 28, 2021
9e5728f
Create packer_image_iteration.md
azr Jul 28, 2021
63d18cf
make channel mandatory for now
azr Jul 28, 2021
630880f
go get github.com/hashicorp/[email protected] && go mod tidy
azr Aug 3, 2021
280ff02
Update internal/provider/data_source_packer_image_iteration.go
azr Aug 3, 2021
9d00c67
Create data-source.tf
azr Aug 3, 2021
ca6d036
Create packer_image_iteration.md.tmpl
azr Aug 3, 2021
7397f83
Update packer_image_iteration.md
azr Aug 3, 2021
73d79d8
Merge branch 'data_source_packer_registry' of ssh://github.com/hashic…
azr Aug 3, 2021
5512bac
Delete data_source_packer_image_iteration_test.go
azr Aug 3, 2021
31760fc
Update data_source_packer_image_iteration.go
azr Aug 3, 2021
6707024
Update packer_image_iteration.md
azr Aug 3, 2021
f4bcb91
Revert "Delete data_source_packer_image_iteration_test.go"
azr Aug 3, 2021
3c2cb91
auto-upsert acc tests data
azr Aug 3, 2021
34b5f2c
go get github.com/hashicorp/[email protected] && tidy
azr Aug 4, 2021
7ae2cd9
Update data_source_packer_image_iteration.go
azr Aug 4, 2021
14ad128
Update data_source_packer_image_iteration_test.go
azr Aug 4, 2021
b835c06
go get -u github.com/hashicorp/terraform-json
azr Aug 4, 2021
d9eacad
Merge remote-tracking branch 'origin/main' into data_source_packer_re…
azr Aug 4, 2021
6343175
manually fix docs
azr Aug 5, 2021
cdc0c02
Add CheckDestroy step for Packer Data Source Test (#180)
Aug 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions internal/provider/data_source_packer_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package provider

import (
"context"
"log"

sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

func dataSourcePackerRegistry() *schema.Resource {
return &schema.Resource{
Description: "The Packer Registry data source provides information about an existing image build stored in the Packer registry",
ReadContext: dataSourcePackerRegistryRead,
Timeouts: &schema.ResourceTimeout{
Default: &defaultPackerRegistryTimeout,
},
Schema: map[string]*schema.Schema{
// Required inputs
"bucket_id": {
Description: "The ID of the HCP Packer Registry image bucket to pull from.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validateSlugID,
},
// Optional inputs
"channel": {
Description: "The channel that points to the version of the image you want.",
Type: schema.TypeString,
Required: false,
ValidateDiagFunc: validateSlugID,
},
// computed outputs
"organization_id": {
Description: "The ID of the organization this HCP Packer registry is located in.",
Type: schema.TypeString,
Computed: true,
},
"project_id": {
Description: "The ID of the project this HCP Packer registry is located in.",
Type: schema.TypeString,
Computed: true,
},
"incremental_version": {
Description: "The Packer version of the registry.",
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Description: "The time that the Packer registry was created.",
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourcePackerRegistryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
bucketID := d.Get("bucket_id").(string)
client := meta.(*clients.Client)

loc := &sharedmodels.HashicorpCloudLocationLocation{
OrganizationID: client.Config.OrganizationID,
ProjectID: client.Config.ProjectID,
}

log.Printf("[INFO] Reading HCP Packer registry (%s) [project_id=%s, organization_id=%s]", registryID, loc.ProjectID, loc.OrganizationID)

bucket, err := clients.GetPackerBucketByID(ctx, client, loc, registryID)
if err != nil {
return diag.FromErr(err)
}

// build the id for this Packer registry
link := newLink(loc, PackerRegistryResourceType, registryID)
url, err := linkURL(link)
if err != nil {
return diag.FromErr(err)
}

d.SetId(url)

// registry found, update resource data.
if err := setPackerRegistryResourceData(d, registry); err != nil {
return diag.FromErr(err)
}

return nil
}