Skip to content

Commit

Permalink
Update resource name to hcp_packer_channel
Browse files Browse the repository at this point in the history
```
~>  make testacc TESTARGS='-run=TestAccPackerChannel'
==> Checking that code complies with gofmt requirements...
golangci-lint run --config ./golangci-config.yml
TF_ACC=1 go test ./internal/... -v -run=TestAccPackerChannel -timeout 210m
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-hcp/internal/clients 0.182s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-hcp/internal/consul 0.194s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-hcp/internal/input 0.199s [no tests to run]
=== RUN   TestAccPackerChannel
--- PASS: TestAccPackerChannel (9.19s)
=== RUN   TestAccPackerChannel_AssignedIteration
--- PASS: TestAccPackerChannel_AssignedIteration (8.00s)
=== RUN   TestAccPackerChannel_UpdateAssignedIteration
--- PASS: TestAccPackerChannel_UpdateAssignedIteration (12.91s)
PASS
ok      github.com/hashicorp/terraform-provider-hcp/internal/provider 30.382s

```
  • Loading branch information
nywilken committed Jan 23, 2023
1 parent 6beb8d3 commit 847e9ba
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .changelog/435.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:feature
New resource `hcp_packer_bucket_channel`
New resource `hcp_packer_channel`
```
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
page_title: "Resource hcp_packer_bucket_channel - terraform-provider-hcp"
page_title: "Resource hcp_packer_channel - terraform-provider-hcp"
subcategory: ""
description: |-
The Packer Bucket Channel resource allow you to manage a channel within an active HCP Packer Registry bucket.
The Packer Bucket Channel resource allows you to manage bucket channels within an active HCP Packer Registry.
---

# hcp_packer_bucket_channel (Resource)
# hcp_packer_channel (Resource)

The Packer Bucket Channel resource allow you to manage a channel within an active HCP Packer Registry bucket.
The Packer Bucket Channel resource allows you to manage bucket channels within an active HCP Packer Registry.

## Example Usage

To create a channel with no assigned iteration.
```terraform
resource "hcp_packer_bucket_channel" "staging" {
resource "hcp_packer_channel" "staging" {
name = "staging"
bucket_name = "alpine"
}
```

To create, or update an existing, managed channel with an assigned iteration.
```terraform
resource "hcp_packer_bucket_channel" "staging" {
resource "hcp_packer_channel" "staging" {
name = "staging"
bucket_name = "alpine"
assigned_iteration_id = "iteration-id"
Expand Down Expand Up @@ -66,5 +66,5 @@ Import is supported using the following syntax:

```shell
# The import ID requires the bucket and channel name in the following format {bucket_name}:{name}
terraform import hcp_packer_bucket_channel.staging alping:staging
terraform import hcp_packer_channel.staging alpine:staging
```
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# The import ID requires the bucket and channel name in the following format {bucket_name}:{name}
terraform import hcp_packer_bucket_channel.staging alping:staging
terraform import hcp_packer_channel.staging alpine:staging
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "hcp_packer_bucket_channel" "staging" {
resource "hcp_packer_channel" "staging" {
name = "staging"
bucket_name = "alpine"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "hcp_packer_bucket_channel" "staging" {
resource "hcp_packer_channel" "staging" {
name = "staging"
bucket_name = "alpine"
assigned_iteration_id = "iteration-id"
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func New() func() *schema.Provider {
"hcp_hvn": resourceHvn(),
"hcp_hvn_peering_connection": resourceHvnPeeringConnection(),
"hcp_hvn_route": resourceHvnRoute(),
"hcp_packer_bucket_channel": resourcePackerBucketChannel(),
"hcp_packer_channel": resourcePackerChannel(),
"hcp_vault_cluster": resourceVaultCluster(),
"hcp_vault_cluster_admin_token": resourceVaultClusterAdminToken(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ import (
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

func resourcePackerBucketChannel() *schema.Resource {
func resourcePackerChannel() *schema.Resource {
return &schema.Resource{
Description: "The Packer Bucket Channel resource allows you to manage bucket channels within an active HCP Packer Registry.",
CreateContext: resourcePackerBucketChannelCreate,
DeleteContext: resourcePackerBucketChannelDelete,
ReadContext: resourcePackerBucketChannelRead,
UpdateContext: resourcePackerBucketChannelUpdate,
CreateContext: resourcePackerChannelCreate,
DeleteContext: resourcePackerChannelDelete,
ReadContext: resourcePackerChannelRead,
UpdateContext: resourcePackerChannelUpdate,
Timeouts: &schema.ResourceTimeout{
Create: &defaultPackerTimeout,
Default: &defaultPackerTimeout,
Update: &defaultPackerTimeout,
Delete: &defaultPackerTimeout,
},
Importer: &schema.ResourceImporter{
StateContext: resourcePackerBucketChannelImport,
StateContext: resourcePackerChannelImport,
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -83,7 +83,7 @@ func resourcePackerBucketChannel() *schema.Resource {
}
}

func resourcePackerBucketChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourcePackerChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
bucketName := d.Get("bucket_name").(string)
client := meta.(*clients.Client)

Expand Down Expand Up @@ -112,10 +112,10 @@ func resourcePackerBucketChannelRead(ctx context.Context, d *schema.ResourceData
if channel.ID == "" {
return diag.Errorf("Unable to find channel in bucket %s named %s.", bucketName, channelName)
}
return setPackerBucketChannelResourceData(d, &channel)
return setPackerChannelResourceData(d, &channel)
}

func resourcePackerBucketChannelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourcePackerChannelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
bucketName := d.Get("bucket_name").(string)
channelName := d.Get("name").(string)

Expand Down Expand Up @@ -144,10 +144,10 @@ func resourcePackerBucketChannelCreate(ctx context.Context, d *schema.ResourceDa
return diag.Errorf("Unable to find channel in bucket %s named %s.", bucketName, channelName)
}

return setPackerBucketChannelResourceData(d, channel)
return setPackerChannelResourceData(d, channel)
}

func resourcePackerBucketChannelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourcePackerChannelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
channelInput := clients.ChannelResourceInput{
BucketName: d.Get("bucket_name").(string),
Name: d.Get("name").(string),
Expand All @@ -169,10 +169,10 @@ func resourcePackerBucketChannelUpdate(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

return setPackerBucketChannelResourceData(d, channel)
return setPackerChannelResourceData(d, channel)
}

func resourcePackerBucketChannelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourcePackerChannelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
bucketName := d.Get("bucket_name").(string)
channelName := d.Get("name").(string)

Expand All @@ -193,7 +193,7 @@ func resourcePackerBucketChannelDelete(ctx context.Context, d *schema.ResourceDa
return nil
}

func resourcePackerBucketChannelImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
func resourcePackerChannelImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*clients.Client)

var err error
Expand Down Expand Up @@ -251,7 +251,7 @@ func resourcePackerBucketChannelImport(ctx context.Context, d *schema.ResourceDa
return []*schema.ResourceData{d}, nil
}

func setPackerBucketChannelResourceData(d *schema.ResourceData, channel *packermodels.HashicorpCloudPackerChannel) diag.Diagnostics {
func setPackerChannelResourceData(d *schema.ResourceData, channel *packermodels.HashicorpCloudPackerChannel) diag.Diagnostics {
if channel == nil {
err := errors.New("unexpected empty channel provided when setting state")
return diag.FromErr(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccPackerBucketChannel(t *testing.T) {
resourceName := "hcp_packer_bucket_channel.production"
func TestAccPackerChannel(t *testing.T) {
resourceName := "hcp_packer_channel.production"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) },
Expand All @@ -22,7 +22,7 @@ func TestAccPackerBucketChannel(t *testing.T) {
Steps: []resource.TestStep{
{
PreConfig: func() { upsertBucket(t, acctestAlpineBucket) },
Config: testConfig(TestAccPackerBucketChannelBasic(acctestAlpineBucket, acctestProductionChannel)),
Config: testConfig(TestAccPackerChannelBasic(acctestAlpineBucket, acctestProductionChannel)),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "author_id"),
resource.TestCheckResourceAttr(resourceName, "bucket_name", acctestAlpineBucket),
Expand Down Expand Up @@ -54,8 +54,8 @@ func TestAccPackerBucketChannel(t *testing.T) {
})
}

func TestAccPackerBucketChannel_AssignedIteration(t *testing.T) {
resourceName := "hcp_packer_bucket_channel.production"
func TestAccPackerChannel_AssignedIteration(t *testing.T) {
resourceName := "hcp_packer_channel.production"
acctestChannelName := "assinged"

resource.Test(t, resource.TestCase{
Expand All @@ -77,7 +77,7 @@ func TestAccPackerBucketChannel_AssignedIteration(t *testing.T) {
}
upsertBuild(t, acctestAlpineBucket, fingerprint, itID)
},
Config: testConfig(testAccPackerBucketChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)),
Config: testConfig(testAccPackerChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "assigned_iteration_id"),
resource.TestCheckResourceAttr(resourceName, "assigned_iteration_version", "1"),
Expand Down Expand Up @@ -106,8 +106,8 @@ func TestAccPackerBucketChannel_AssignedIteration(t *testing.T) {
})
}

func TestAccPackerBucketChannel_UpdateAssignedIteration(t *testing.T) {
resourceName := "hcp_packer_bucket_channel.production"
func TestAccPackerChannel_UpdateAssignedIteration(t *testing.T) {
resourceName := "hcp_packer_channel.production"
acctestChannelName := "update-test"

resource.Test(t, resource.TestCase{
Expand All @@ -129,7 +129,7 @@ func TestAccPackerBucketChannel_UpdateAssignedIteration(t *testing.T) {
}
upsertBuild(t, acctestAlpineBucket, fingerprint, itID)
},
Config: testConfig(testAccPackerBucketChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)),
Config: testConfig(testAccPackerChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "author_id"),
resource.TestCheckResourceAttrSet(resourceName, "created_at"),
Expand All @@ -150,7 +150,7 @@ func TestAccPackerBucketChannel_UpdateAssignedIteration(t *testing.T) {
}
upsertBuild(t, acctestAlpineBucket, fingerprint, itID)
},
Config: testConfig(testAccPackerBucketChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)),
Config: testConfig(testAccPackerChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "assigned_iteration_id"),
resource.TestCheckResourceAttr(resourceName, "assigned_iteration_version", "2"),
Expand All @@ -162,21 +162,21 @@ func TestAccPackerBucketChannel_UpdateAssignedIteration(t *testing.T) {
})
}

var TestAccPackerBucketChannelBasic = func(bucketName, channelName string) string {
var TestAccPackerChannelBasic = func(bucketName, channelName string) string {
return fmt.Sprintf(`
resource "hcp_packer_bucket_channel" "production" {
resource "hcp_packer_channel" "production" {
bucket_name = %q
name = %q
}`, bucketName, channelName)
}

var testAccPackerBucketChannelAssignedLatestIteration = func(bucketName, channelName string) string {
var testAccPackerChannelAssignedLatestIteration = func(bucketName, channelName string) string {
return fmt.Sprintf(`
data "hcp_packer_image_iteration" "test" {
bucket_name = %[2]q
channel = "latest"
}
resource "hcp_packer_bucket_channel" "production" {
resource "hcp_packer_channel" "production" {
name = %[1]q
bucket_name = %[2]q
assigned_iteration_id = data.hcp_packer_image_iteration.test.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ description: |-
## Example Usage

To create a channel with no assigned iteration.
{{ tffile "examples/resources/hcp_packer_bucket_channel/resource.tf" }}
{{ tffile "examples/resources/hcp_packer_channel/resource.tf" }}

To create, or update an existing, managed channel with an assigned iteration.
{{ tffile "examples/resources/hcp_packer_bucket_channel/resource_assignment.tf" }}
{{ tffile "examples/resources/hcp_packer_channel/resource_assignment.tf" }}

{{ .SchemaMarkdown | trimspace }}

## Import

Import is supported using the following syntax:

{{ codefile "shell" "examples/resources/hcp_packer_bucket_channel/import.sh" }}
{{ codefile "shell" "examples/resources/hcp_packer_channel/import.sh" }}

0 comments on commit 847e9ba

Please sign in to comment.