-
Notifications
You must be signed in to change notification settings - Fork 44
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
[HPR-859] Add HCP Packer bucket channel resource #435
Conversation
40f0f9e
to
9f05312
Compare
9f05312
to
847e9ba
Compare
cfeb5c0
to
441134b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple of questions and suggestions, but overall LGTM! 👍🏼
docs/resources/packer_channel.md
Outdated
|
||
Read-Only: | ||
|
||
- `fingerprint` (String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why these are not including the description you gave them 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a limitation of the tfplugindocs command when it comes to nested computed attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcmdarroch Any thoughts on why the docs don't get generated for these nested attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is a known issue: hashicorp/terraform-plugin-docs#28. Unfortunately can't add further detail. :( The provider SDK doesn't have great support for nested objects in general.
Not sure if this would resolve this specific doc issue, but the new plugin framework has much better support for nested objects: https://developer.hashicorp.com/terraform/plugin/framework/migrating/benefits
}, | ||
Config: testConfig(testAccPackerChannelAssignedLatestIteration(acctestAlpineBucket, acctestChannelName)), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(resourceName, "iteration_assignment.0.id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a block is a list type so to reference the attributes for the first element in the list, which is the only element, we have to index the results to get the values - https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-types#typelist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall code looks good to me, I left a few comments, feel free to address them as you find relevant.
On another note, is there a reason why the terraform-provider-hcp_v0.51.0 binary is in the diff?
return nil | ||
} | ||
|
||
func resourcePackerChannelImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with the codebase here, but is there a reason why meta
is an interface{}
if we always expect it to be a *clients.Client
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. The interface is to fulfill the function signature expected by the underlying terraform plugin SDK: in this case, the StateContextFunc. The meta
argument provides access to the provider state, but generally resources only need the client out of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @bcmdarroch I was struggling to find how to word this without going too deep. 🙇♂️
6e2120e
to
e31543e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left a final doc nit, but other than that, LGTM!
@bcmdarroch could I get your review on this, as well. I would like to know if there are any thoughts or suggestion on the TF schema. |
7bd7d47
to
f606862
Compare
} | ||
|
||
func TestAccPackerChannel_UpdateAssignedIterationWithFingerprint(t *testing.T) { | ||
resourceName := "hcp_packer_channel.staging" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing for me:
terraform-provider-hcp (nywilken/add-packer-channel-resource) ✗ (~˘▾˘)~ ✧ make testacc TESTARGS='-run=PackerChannel'
==> Checking that code complies with gofmt requirements...
golangci-lint run --config ./golangci-config.yml
TF_ACC=1 go test ./internal/... -v -run=PackerChannel -timeout 210m -parallel=10
testing: warning: no tests to run
=== RUN TestAccPackerChannel
--- PASS: TestAccPackerChannel (10.50s)
=== RUN TestAccPackerChannel_AssignedIteration
--- PASS: TestAccPackerChannel_AssignedIteration (18.21s)
=== RUN TestAccPackerChannel_UpdateAssignedIteration
--- PASS: TestAccPackerChannel_UpdateAssignedIteration (14.24s)
=== RUN TestAccPackerChannel_UpdateAssignedIterationWithFingerprint
resource_packer_channel_test.go:181: Step 1/1 error: Check failed: Check 1/10 error: Not found: hcp_packer_channel.staging in [root]
--- FAIL: TestAccPackerChannel_UpdateAssignedIterationWithFingerprint (4.18s)
FAIL
FAIL github.com/hashicorp/terraform-provider-hcp/internal/provider 47.876s
FAIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. It should be fixed now.
|
||
func TestAccPackerChannel_UpdateAssignedIterationWithFingerprint(t *testing.T) { | ||
resourceName := "hcp_packer_channel.staging" | ||
acctestChannelName := "fingerprint-test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had some trouble with resource ID conflicts with our releaser acceptance test runs. Could you add a timestamp to this ID and the others? For example: https://github.com/hashicorp/terraform-provider-hcp/pull/440/files#diff-793cec3def4f921f6b01a086a16e6c0fb145f56b29613da7b36e9b10bcb4c922R17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this info. I'll update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! 🎉 Had a suggestion about timestamped IDs, and noticed that TestAccPackerChannel_UpdateAssignedIterationWithFingerprint
failed when I ran the tests against integration.
e337fff
to
f066cc1
Compare
@@ -22,7 +22,7 @@ import ( | |||
var ( | |||
acctestAlpineBucket = fmt.Sprintf("alpine-acc-%s", time.Now().Format("200601021504")) | |||
acctestUbuntuBucket = fmt.Sprintf("ubuntu-acc-%s", time.Now().Format("200601021504")) | |||
acctestProductionChannel = "production" | |||
acctestProductionChannel = fmt.Sprintf("packer-acc-channel-%s", time.Now().Format("200601021504")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validated all test pass as expected
~> make testacc TESTARGS='-run=Packer'
==> Checking that code complies with gofmt requirements...
golangci-lint run --config ./golangci-config.yml
TF_ACC=1 go test ./internal/... -v -run=Packer -timeout 210m -parallel=10
testing: warning: no tests to run
PASS
ok github.com/hashicorp/terraform-provider-hcp/internal/clients 0.216s [no tests to run]
testing: warning: no tests to run
PASS
ok github.com/hashicorp/terraform-provider-hcp/internal/consul 0.302s [no tests to run]
testing: warning: no tests to run
PASS
ok github.com/hashicorp/terraform-provider-hcp/internal/input 0.283s [no tests to run]
=== RUN TestAcc_dataSourcePacker
--- PASS: TestAcc_dataSourcePacker (12.48s)
=== RUN TestAcc_dataSourcePacker_revokedIteration
--- PASS: TestAcc_dataSourcePacker_revokedIteration (16.62s)
=== RUN TestAcc_dataSourcePackerImage
--- PASS: TestAcc_dataSourcePackerImage (11.65s)
=== RUN TestAcc_dataSourcePackerImage_revokedIteration
--- PASS: TestAcc_dataSourcePackerImage_revokedIteration (14.44s)
=== RUN TestAcc_dataSourcePackerImage_channelAndIterationIDReject
--- PASS: TestAcc_dataSourcePackerImage_channelAndIterationIDReject (5.60s)
=== RUN TestAcc_dataSourcePackerImage_channelAccept
--- PASS: TestAcc_dataSourcePackerImage_channelAccept (10.24s)
=== RUN TestAcc_dataSourcePackerIteration
--- PASS: TestAcc_dataSourcePackerIteration (9.56s)
=== RUN TestAcc_dataSourcePackerIteration_revokedIteration
--- PASS: TestAcc_dataSourcePackerIteration_revokedIteration (16.30s)
=== RUN TestAccPackerChannel
--- PASS: TestAccPackerChannel (12.18s)
=== RUN TestAccPackerChannel_AssignedIteration
--- PASS: TestAccPackerChannel_AssignedIteration (13.25s)
=== RUN TestAccPackerChannel_UpdateAssignedIteration
--- PASS: TestAccPackerChannel_UpdateAssignedIteration (21.26s)
=== RUN TestAccPackerChannel_UpdateAssignedIterationWithFingerprint
--- PASS: TestAccPackerChannel_UpdateAssignedIterationWithFingerprint (10.44s)
PASS
ok github.com/hashicorp/terraform-provider-hcp/internal/provider 154.408s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same!
* Add ability to update channel assignment * Add validation for channel and bucket names
* Add author_id to output * Add updated_at computed property
f066cc1
to
76b872b
Compare
The current implementation relies on the use of an extra iteration_assignment block to denote what iteration to assign to a channel. Instead of defining a separate block this change uses the single iteration block to denote the state of a channel. Modifying the iteration block will trigger the respective updates to the state of a channel. Removing the iteration block will remove the assigned iteration from the channel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more test run before final merge ✅
--- PASS: TestAccPackerChannel_UpdateAssignedIterationWithFingerprint (6.07s)
--- PASS: TestAccPackerChannel_UpdateAssignedIteration (13.34s)
--- PASS: TestAccPackerChannel_AssignedIteration (9.61s)
--- PASS: TestAccPackerChannel (7.26s)
--- PASS: TestAcc_dataSourcePackerIteration_revokedIteration (11.31s)
--- PASS: TestAcc_dataSourcePackerIteration (5.99s)
--- PASS: TestAcc_dataSourcePackerImage_channelAccept (6.21s)
--- PASS: TestAcc_dataSourcePackerImage_channelAndIterationIDReject (3.58s)
--- PASS: TestAcc_dataSourcePackerImage_revokedIteration (10.80s)
--- PASS: TestAcc_dataSourcePackerImage (7.79s)
--- PASS: TestAcc_dataSourcePacker_revokedIteration (11.53s)
--- PASS: TestAcc_dataSourcePacker (12.89s)
One more test as well
|
🛠️ Description
This change adds the
hcp_packer_bucket_channel
resource to manage channels within an active HCP Packer registry image bucket.🏗️ Acceptance tests
Are there any feature flags that are required to use this functionality?Output from acceptance testing:
Few Examples