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

Add resource and data sources for private registry GPG keys #1160

Closed
wants to merge 8 commits into from

Conversation

tmatilai
Copy link
Contributor

@tmatilai tmatilai commented Dec 2, 2023

Description

Add tfe_registry_gpg_key resource and data source, and tfe_registry_gpg_keys data source, for managing and retrieving private registry GPG keys.

Related to #584.

Testing plan

Create and retrieve GPG keys with the new resource and data sources.

Example configuration
resource "tfe_organization" "foobar" {
  name  = "foobar"
  email = "admin@tfe.local"
}

resource "tfe_registry_gpg_key" "foobar" {
  organization = tfe_organization.foobar.name

  ascii_armor = <<ASCII_ARMOR
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGKnWEYBEACsTJ9HEUrXBaBvQvXZAXEIMWloG96MVAdCj547jJviSS4TqMIQ
EST2pzDq7lEpqL+JkW3ptyLEAeQs6gJJeuhODGm2EcxjJ9/JM4ZH+p9zq2wBeXVe
0XJcP3HD8/7MesjMyGSsoX7tR7TcIhs5Y7zS+/L1xnoReYUsBgC6QdqjQwkuntaq
2y6yxdYG4gVlxb4yA0Ga6Qfy0VGIKjbCdPqCRyJ76YHE3t+Skq9oDCOV3VSiwKsU
V/ivf/MVZ1GyE03anW0+poVK38Ekogsd2+34uEjusbuoJGmHzh/20IDS8VnxQHIY
qdVwcZrW+a3O6nexL4dJJGMfXMbCdS87FxpSnC1FDGMSJ2c5cxlMuKuDboTpbRy5
Dd80p6voJQcLcpr0hKYIwwDGJYE336KMFqf/apCc6HbCFfN8kCYg3K7+4yganRWu
h/9qIhP0QaYOYEQl4RdjJTSyJSP3srAJ3F5OmrAhRXlHlLo1p00zxFxG7ZcJER6l
+uRubtL9WN2kgGbr9NDJbz/HeOTjJhCASdQuzstcL8RrFMDftE/P2K8LnkxUNIbT
dhZtwvkhnyIwOZIHwsQddeJboeHD445SlHJ+4vFsP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SIDsNjnDTtfh9Z8gXz
gvF7mSC0lZu/RvDSRyHfCw4zCQ04HieIvq3hZLy+QS11ykJTSKAePKk77EmwtoLd
Je9n9FCKhLknUp1/dsu0lsznvttOLwYy6xFP4JNPgiq6iYlVHs417oib67DrGlsI
3Ki44OESW/vL3WAC091TOF4OYgGw+TMauB8SxZo0PLXrIwKeBsQEB4tf6bX66OvJ
UFpas2r53xTaraRDpu6+u66hLY+/XV9Uf5YzETuPQnX/nw==
=bBSS
-----END PGP PUBLIC KEY BLOCK-----
ASCII_ARMOR
}

data "tfe_registry_gpg_key" "foobar" {
  organization = tfe_organization.foobar.name

  id = tfe_registry_gpg_key.foobar.id
}

data "tfe_registry_gpg_keys" "all" {
  organization = tfe_organization.foobar.name

  depends_on = [tfe_registry_gpg_key.foobar]
}

External links

Output from acceptance tests

$ make testacc TESTARGS='-run=TestAccTFERegistryGPGKey'
TF_ACC=1 TF_LOG_SDK_PROTO=OFF go test $(go list ./... |grep -v 'vendor') -v -run=TestAccTFERegistryGPGKey -timeout 15m
?       github.com/hashicorp/terraform-provider-tfe     [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-tfe/internal/client     (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-tfe/internal/logging    (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-tfe/version     [no test files]
=== RUN   TestAccTFERegistryGPGKeyDataSource_basic
--- PASS: TestAccTFERegistryGPGKeyDataSource_basic (4.29s)
=== RUN   TestAccTFERegistryGPGKeysDataSource_basic
--- PASS: TestAccTFERegistryGPGKeysDataSource_basic (3.69s)
=== RUN   TestAccTFERegistryGPGKeysDataSource_basicNoKeys
--- PASS: TestAccTFERegistryGPGKeysDataSource_basicNoKeys (2.80s)
=== RUN   TestAccTFERegistryGPGKeyResource_basic
--- PASS: TestAccTFERegistryGPGKeyResource_basic (2.74s)
PASS
ok      github.com/hashicorp/terraform-provider-tfe/internal/provider   13.854s

@tmatilai tmatilai requested a review from a team as a code owner December 2, 2023 16:27
}

var organization string
resp.Diagnostics.Append(r.config.dataOrDefaultOrganization(ctx, req.State, &organization)...)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suffers from #1152, but there seems to be no good solution to it. I tried using ModifyPlan(), but it will cause Provider produced inconsistent result after apply errors for the updated_at attribute unless it is marked as "unknown". That would be fine for one resource, but doesn't scale.

@tmatilai
Copy link
Contributor Author

tmatilai commented Dec 2, 2023

Sorry, the PR is big. But it can be reviewed a commit at a time. Or I can split it into three PRs if requested, although the data source commits depend on the first one.

@tmatilai tmatilai changed the title Add resources and data sources for private registry GPG keys Add resource and data sources for private registry GPG keys Dec 2, 2023
@brandonc
Copy link
Collaborator

brandonc commented Dec 4, 2023

@tmatilai Thanks again for the contribution! I especially appreciate that you used the provider framework. I will be reviewing and testing this sometimes this week.

tmatilai and others added 6 commits December 6, 2023 10:48
Manages a public key of the GPG key pair used to sign releases of
private providers in the private registry.
Retrieves a private registry GPG key.
Retrieves all private registry GPG keys of an organization.
@brandonc
Copy link
Collaborator

brandonc commented Dec 6, 2023

@tmatilai oh no! I rebased and force-pushed to the wrong branch. This was meant to go to #1164

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I'm moving these commits to a repo branch in #1164

"organization": schema.StringAttribute{
Description: "Name of the organization. If omitted, organization must be defined in the provider config.",
Optional: true,
Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one will need a couple of plan modifiers: RequiresReplace as well as another to detect when the provider organization changes (Thanks for the bug report!) as you pointed out. I accomplished this in d53886b by implementing ResourceWithModifyPlan interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fine. I tried to do the organization change without replacing the whole resource, as the API supports it. And then I got into issues with the updated_at attribute being changed only after apply (as those attributes seem hard to set to unset in a generic way).

@tmatilai
Copy link
Contributor Author

tmatilai commented Dec 7, 2023

oh no! I rebased and force-pushed to the wrong branch

You are free to do what ever you want with this branch, too. 🙂
Thanks!

@brandonc
Copy link
Collaborator

brandonc commented Dec 7, 2023

Prefer local branch #1164

@brandonc brandonc closed this Dec 7, 2023
@tmatilai tmatilai deleted the registry-gpg-keys branch December 8, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants