terraform-provider-proxmox
terraform-provider-proxmox copied to clipboard
WIP: feat(node): implement resources and data sources for node config
Contributor's Note
- [ ] I have added / updated documentation in
/docsfor any user-facing features or additions. - [ ] I have added / updated acceptance tests in
/fwprovider/testsfor any new or updated resources / data sources. - [ ] I have ran
make exampleto verify that the change works as expected.
Proof of Work
Community Note
- Please vote on this pull request by adding a π reaction to the original pull request comment to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request
@bpg how would you name the data sources and resources here? The API is: https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/config In the UI it is: Node -> System -> Certificates [ACME] and Node -> System -> Options
I could go with the API naming, e.g. proxmox_virtual_environment_node_config.
Or with the UI naming, in which case this API would feed two data sources / resources: proxmox_virtual_environment_options or proxmox_virtual_environment_node_options and
proxmox_virtual_environment_certificates or proxmox_virtual_environment_acme_certificates?
What do you think?
Edit: I will also need to implement this API: https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/certificates/acme/certificate to order certificates from letsencrypt.
I think for ordering it would be nice to have a proxmox_virtual_environment_acme_certificate resource, which at creation, sends the POST to order a certificate and then, after the task finishes, reads the https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/certificates/info API to set its state. Unfortunately we'd then need to find the correct certificate from the /certificates/info API.
The /certificates/info API returns an array like this:
{
"data": [
{
"filename": "pve-root-ca.pem",
"pem": "-----BEGIN CERTIFICATE-----\nxxx\n-----END CERTIFICATE-----\n",
"subject": "/CN=Proxmox Virtual Environment/OU=xxx/O=PVE Cluster Manager CA",
"issuer": "/CN=Proxmox Virtual Environment/OU=xxx/O=PVE Cluster Manager CA",
"fingerprint": "xxx",
"public-key-bits": 4096,
"notbefore": 1722529819,
"public-key-type": "rsaEncryption",
"san": [],
"notafter": 2037889819
},
{
"subject": "/OU=PVE Cluster Node/O=Proxmox Virtual Environment/CN=pve.example.com",
"pem": "-----BEGIN CERTIFICATE-----\nxxx\n-----END CERTIFICATE-----\n",
"filename": "pve-ssl.pem",
"fingerprint": "xxx",
"issuer": "/CN=Proxmox Virtual Environment/OU=xxx/O=PVE Cluster Manager CA",
"notbefore": 1722529819,
"public-key-type": "rsaEncryption",
"public-key-bits": 2048,
"notafter": 1785601819,
"san": [
"127.0.0.1",
"0000:0000:0000:0000:0000:0000:0000:0001",
"localhost",
"10.66.60.2",
"pve",
]
},
{
"san": [
"pve.example.com"
],
"notafter": 1730985597,
"public-key-bits": 4096,
"notbefore": 1723209598,
"public-key-type": "rsaEncryption",
"fingerprint": "xxx",
"issuer": "/C=US/O=Let's Encrypt/CN=R10",
"pem": "-----BEGIN CERTIFICATE-----\nxxx\n-----END CERTIFICATE-----\n",
"filename": "pveproxy-ssl.pem",
"subject": "/CN=pve.example.com"
}
]
}
It is best practice to closely follow the API (https://developer.hashicorp.com/terraform/plugin/best-practices/hashicorp-provider-design-principles#resource-and-attribute-schema-should-closely-match-the-underlying-api) unless it degrades the user experience, which in this case might be true? I have also found this question on SO about a resource that is built upon multiple API entities: https://stackoverflow.com/a/75064551
Hey @ZauberNerd,
Sorry it took me a while to get back to you on this PR.
It is best practice to closely follow the API ... unless it degrades the user experience, which in this case might be true?
Yeah, I think that's true in this case, as you pointed out. It makes sense to keep *_acme_certificate and *_node_options as separate resources since they're not really related from the user's perspective. The PVE API for setting/getting options lets you work with individual parameters, so I don't see an issue with both resources using the same API as long as they only touch the parameters they need and ignore the rest.
The flow you're suggesting for ordering certificates sounds good to me. I'm guessing youβre planning to match certs with acmedomainX by parsing the CN value from the subjects?
Decided to merge this code pretty much as-is, which gives only the API client support, not TF resources.
Walkthrough
The changes introduce new functionality for managing node configurations in the proxmox/nodes package. Two methods, GetConfig and UpdateConfig, are added to handle configuration retrieval and updates, respectively. Additionally, new data structures are defined to encapsulate configuration data and facilitate JSON processing. A suite of unit tests is also introduced to validate the behavior of these new structures and methods, ensuring robust error handling and data integrity.
Changes
| File | Change Summary |
|---|---|
| proxmox/nodes/config.go | Added methods: GetConfig for retrieving node configuration and UpdateConfig for updating it. |
| proxmox/nodes/config_types.go | Introduced types: ConfigGetResponseBody, ConfigGetResponseData, ConfigUpdateRequestBody, ACMEConfig, ACMEDomainConfig, WakeOnLandConfig, with relevant JSON handling methods. |
| proxmox/nodes/config_types_test.go | Added unit tests for ACMEConfig, ACMEDomainConfig, and WakeOnLandConfig, covering JSON unmarshalling and encoding. |
Poem
π° In the land of code where rabbits play,
New configs bloom in a bright array.
With Get and Update, they hop and cheer,
Ensuring all settings are crystal clear.
So letβs code away, with joy in our hearts,
For each little change is a work of art! πΌ
π Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL
π₯ Commits
Reviewing files that changed from the base of the PR and between dd50873e2a49a3440fa85958042ec91899be63e6 and 3952aff8bac03b844f16656c08537e7c04829d2c.
π Files selected for processing (3)
proxmox/nodes/config.go(1 hunks)proxmox/nodes/config_types.go(1 hunks)proxmox/nodes/config_types_test.go(1 hunks)
π Additional comments (3)
proxmox/nodes/config.go (2)
1-15: LGTM! Clean package structure and imports.
The file has proper licensing and imports only the necessary packages.
33-41: Consider adding input validation.
The method should validate the request body before making the API call to catch invalid configurations early.
Let's check the ConfigUpdateRequestBody structure and any existing validation:
proxmox/nodes/config_types_test.go (1)
1-14: LGTM: Clean imports and proper licensing
The file header and imports are well-structured with appropriate licensing and minimal necessary imports.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
πͺ§ Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.