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
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion internal/clients/hvn_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func hvnRouteRefreshState(ctx context.Context, client *Client, hvnID, routeID st
return nil, "", err
}

return route, string(route.State), nil
return route, string(*route.State), nil
azr marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/clients/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func WaitForOperation(ctx context.Context, client *Client, operationName string,
// Reset consecutive errors after a successful response.
consecutiveErrors = 0

log.Printf("[INFO] Received state of %s operation (%s): %s", operationName, operationID, waitResponse.Payload.Operation.State)
if waitResponse.Payload.Operation.State == sharedmodels.HashicorpCloudOperationOperationStateDONE {
log.Printf("[INFO] Received state of %s operation (%s): %s", operationName, operationID, *waitResponse.Payload.Operation.State)
if *waitResponse.Payload.Operation.State == sharedmodels.HashicorpCloudOperationOperationStateDONE {
if waitResponse.Payload.Operation.Error != nil {
err := fmt.Errorf("%s operation (%s) failed [code=%d, message=%s]",
operationName, waitResponse.Payload.Operation.ID, waitResponse.Payload.Operation.Error.Code, waitResponse.Payload.Operation.Error.Message)
Expand Down
2 changes: 1 addition & 1 deletion internal/clients/peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func peeringRefreshState(ctx context.Context, client *Client, peeringID string,
return nil, "", err
}

return peering, string(peering.State), nil
return peering, string(*peering.State), nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/consul/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func RecommendedVersion(versions []*consulmodels.HashicorpCloudConsul20210204Ver
for _, v := range versions {
defaultVersion = v.Version

if v.Status == "RECOMMENDED" {
if v.Status != nil && *v.Status == consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED {
return defaultVersion
}
}
Expand Down Expand Up @@ -44,7 +44,7 @@ func VersionsToString(versions []*consulmodels.HashicorpCloudConsul20210204Versi
continue
}

if v.Status == consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED {
if v.Status != nil && *v.Status == consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED {
recommendedVersion = v.Version
} else {
otherVersions = append(otherVersions, v.Version)
Expand Down
42 changes: 23 additions & 19 deletions internal/consul/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/stretchr/testify/require"
)

func statusPTR(s consulmodels.HashicorpCloudConsul20210204VersionStatus) *consulmodels.HashicorpCloudConsul20210204VersionStatus {
return &s
}

func Test_RecommendedVersion(t *testing.T) {
tcs := map[string]struct {
expected string
Expand All @@ -16,15 +20,15 @@ func Test_RecommendedVersion(t *testing.T) {
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED),
},
{
Version: "v1.8.6",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.4",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
},
expected: "v1.9.0",
Expand All @@ -33,15 +37,15 @@ func Test_RecommendedVersion(t *testing.T) {
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.6",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.4",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
},
expected: "v1.8.4",
Expand Down Expand Up @@ -69,15 +73,15 @@ func Test_IsValidVersion(t *testing.T) {
validVersions: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED),
},
{
Version: "v1.8.6",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.4",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
},
expected: true,
Expand All @@ -87,15 +91,15 @@ func Test_IsValidVersion(t *testing.T) {
validVersions: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED),
},
{
Version: "v1.8.6",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.4",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
},
expected: false,
Expand Down Expand Up @@ -126,15 +130,15 @@ func Test_VersionsToString(t *testing.T) {
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED),
},
{
Version: "v1.8.6",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.4",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
},
expected: "v1.9.0 (recommended), v1.8.6, v1.8.4",
Expand All @@ -143,11 +147,11 @@ func Test_VersionsToString(t *testing.T) {
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.8.6",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
{
Version: "v1.8.4",
Status: "AVAILABLE",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusAVAILABLE),
},
},
expected: "v1.8.6, v1.8.4",
Expand All @@ -156,7 +160,7 @@ func Test_VersionsToString(t *testing.T) {
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED),
},
},
expected: "v1.9.0",
Expand All @@ -170,7 +174,7 @@ func Test_VersionsToString(t *testing.T) {
nil,
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Status: statusPTR(consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED),
},
nil,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/data_source_consul_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func dataSourceConsulVersionsRead(ctx context.Context, d *schema.ResourceData, m
previewVersions := make([]string, 0)

for _, v := range availableConsulVersions {
switch v.Status {
switch *v.Status {
case consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED:
recommendedVersion = v.Version
availableVersions = append(availableVersions, v.Version)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_aws_network_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func resourceAwsNetworkPeeringRead(ctx context.Context, d *schema.ResourceData,

// The network peering failed to provision properly so we want to let the user know and
// remove it from state
if peering.State == networkmodels.HashicorpCloudNetwork20200907PeeringStateFAILED {
if *peering.State == networkmodels.HashicorpCloudNetwork20200907PeeringStateFAILED {
log.Printf("[WARN] Network peering (%s) failed to provision, removing from state", peering.ID)
d.SetId("")
return nil
Expand Down
8 changes: 5 additions & 3 deletions internal/provider/resource_consul_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ func resourceConsulClusterCreate(ctx context.Context, d *schema.ResourceData, me

connectEnabled := d.Get("connect_enabled").(bool)
publicEndpoint := d.Get("public_endpoint").(bool)
tier := consulmodels.HashicorpCloudConsul20210204ClusterConfigTier(strings.ToUpper(d.Get("tier").(string)))
size := consulmodels.HashicorpCloudConsul20210204CapacityConfigSize(strings.ToUpper(d.Get("size").(string)))

// Enabling auto peering will peer this cluster's HVN with every other HVN with members in this federation.
// The peering happens within the secondary cluster create operation.
Expand All @@ -320,9 +322,9 @@ func resourceConsulClusterCreate(ctx context.Context, d *schema.ResourceData, me

consulCuster := &consulmodels.HashicorpCloudConsul20210204Cluster{
Config: &consulmodels.HashicorpCloudConsul20210204ClusterConfig{
Tier: consulmodels.HashicorpCloudConsul20210204ClusterConfigTier(strings.ToUpper(d.Get("tier").(string))),
Tier: &tier,
CapacityConfig: &consulmodels.HashicorpCloudConsul20210204CapacityConfig{
Size: consulmodels.HashicorpCloudConsul20210204CapacityConfigSize(strings.ToUpper(d.Get("size").(string))),
Size: &size,
},
ConsulConfig: &consulmodels.HashicorpCloudConsul20210204ConsulConfig{
ConnectEnabled: connectEnabled,
Expand Down Expand Up @@ -539,7 +541,7 @@ func resourceConsulClusterRead(ctx context.Context, d *schema.ResourceData, meta

// The Consul cluster failed to provision properly so we want to let the user know and
// remove it from state
if cluster.State == consulmodels.HashicorpCloudConsul20210204ClusterStateFAILED {
if *cluster.State == consulmodels.HashicorpCloudConsul20210204ClusterStateFAILED {
log.Printf("[WARN] Consul cluster (%s) failed to provision, removing from state", clusterID)
d.SetId("")
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_consul_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func resourceConsulSnapshotRead(ctx context.Context, d *schema.ResourceData, met

// The Consul snapshot failed to provision properly so we want to let the user know and
// remove it from state
if snapshotResp.Snapshot.State == consulmodels.HashicorpCloudConsul20210204SnapshotSnapshotStateCREATINGFAILED {
if *snapshotResp.Snapshot.State == consulmodels.HashicorpCloudConsul20210204SnapshotSnapshotStateCREATINGFAILED {
log.Printf("[WARN] Consul snapshot (%s) failed to provision, removing from state", snapshotResp.Snapshot.ID)
d.SetId("")
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_hvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func resourceHvnRead(ctx context.Context, d *schema.ResourceData, meta interface

// The HVN failed to provision properly so we want to let the user know and remove it from
// state
if hvn.State == networkmodels.HashicorpCloudNetwork20200907NetworkStateFAILED {
if *hvn.State == networkmodels.HashicorpCloudNetwork20200907NetworkStateFAILED {
log.Printf("[WARN] HVN (%s) failed to provision, removing from state", hvnID)
d.SetId("")
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_hvn_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func resourceHvnRouteRead(ctx context.Context, d *schema.ResourceData, meta inte
}

// The HVN route failed to provision properly so we want to let the user know and remove it from state.
if route.State == networkmodels.HashicorpCloudNetwork20200907HVNRouteStateFAILED {
if *route.State == networkmodels.HashicorpCloudNetwork20200907HVNRouteStateFAILED {
log.Printf("[WARN] HVN route (%s) failed to provision, removing from state", idLink.ID)
d.SetId("")
return nil
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/resource_vault_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func resourceVaultClusterCreate(ctx context.Context, d *schema.ResourceData, met
}

publicEndpoint := d.Get("public_endpoint").(bool)
tier := vaultmodels.HashicorpCloudVault20201125Tier(strings.ToUpper(d.Get("tier").(string)))

log.Printf("[INFO] Creating Vault cluster (%s)", clusterID)

Expand All @@ -184,7 +185,7 @@ func resourceVaultClusterCreate(ctx context.Context, d *schema.ResourceData, met
VaultConfig: &vaultmodels.HashicorpCloudVault20201125VaultConfig{
InitialVersion: vaultVersion,
},
Tier: vaultmodels.HashicorpCloudVault20201125Tier(strings.ToUpper(d.Get("tier").(string))),
Tier: &tier,
NetworkConfig: &vaultmodels.HashicorpCloudVault20201125InputNetworkConfig{
NetworkID: hvn.ID,
PublicIpsEnabled: publicEndpoint,
Expand Down Expand Up @@ -253,7 +254,7 @@ func resourceVaultClusterRead(ctx context.Context, d *schema.ResourceData, meta

// The Vault cluster failed to provision properly so we want to let the user know and
// remove it from state.
if cluster.State == vaultmodels.HashicorpCloudVault20201125ClusterStateFAILED {
if *cluster.State == vaultmodels.HashicorpCloudVault20201125ClusterStateFAILED {
log.Printf("[WARN] Vault cluster (%s) failed to provision, removing from state", clusterID)
d.SetId("")
return nil
Expand Down