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

network_integration: add network_integration resource #173

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

jonatas-lima
Copy link
Contributor

Closes #122

@stgraber
Copy link
Member

Hi @jonatas-lima, we typically split those kind of PRs into three commits:

  • docs
  • config
  • tests

Any chance you can edit your PR to split your change into those three chunks?

https://github.com/lxc/terraform-provider-incus/pull/155/commits for an example of the usual structure.

Thanks!

@jonatas-lima
Copy link
Contributor Author

Hi @stgraber! Could you review again?


* `description` *Optional* - Description of the network integration.

* `type` *Optional* - The type of the network integration. Currently, only supports **ovn** type. If empty, an OVN integration will be created.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the rest of the documentation code blocks are used to point out specific options:

Suggested change
* `type` *Optional* - The type of the network integration. Currently, only supports **ovn** type. If empty, an OVN integration will be created.
* `type` *Optional* - The type of the network integration. Currently, only supports `ovn` type. If empty, an OVN integration will be created.

Comment on lines 20 to 22
"github.com/lxc/incus/v6/shared/api"
"github.com/lxc/terraform-provider-incus/internal/common"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Imports should be grouped in 3 groups: stdlib, 3rd party, project internal packages:

Suggested change
"github.com/lxc/incus/v6/shared/api"
"github.com/lxc/terraform-provider-incus/internal/common"
"github.com/lxc/incus/v6/shared/api"
"github.com/lxc/terraform-provider-incus/internal/common"

Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, we need an additional check here to make sure, that the user does not provide the empty string "" as name, since this causes an error on Incus side while Terraform does accept it "" != null.

Suggested change
},
},
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},

@maveonair, @stgraber this is maybe a general question, since I see this to be missing also for other resources on the name attribute.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah, empty names are usually not allowed in the API.

The one exception there being for instances where an empty name is allowed but leads to Incus generating a random instance name for you, which may by itself cause issues with Terraform.

I think it'd make sense for all name properties to be required to be at least 1 character long, then leave the more detailed validation after that to Incus.

Copy link
Member

Choose a reason for hiding this comment

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

100%, we should make the name mandatory if we need it.... I have to say I've never tried using an empty string before. Great catch!


"description": schema.StringAttribute{
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.

Why is description Computed? It is provided in the Terraform config, persisted in Incus and returned by the API, so this is a regular attribute in my opinion. Do I miss something?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, you're correct, this isn't a field which Incus computes for you, so what's pushed by Terraform is what's stored, therefore it shouldn't be marked as computed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't use a default value if the field is not Computed:

$ TF_ACC=1 go test -v internal/network/resource_network_integration_test.go

- Schema Using Attribute Default For Non-Computed Attribute: Attribute
        "description" must be computed when using default. This is an issue with the
        provider and should be reported to the provider developers.

Copy link
Member

Choose a reason for hiding this comment

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

@maveonair any idea what's going on here?

Copy link
Member

Choose a reason for hiding this comment

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

@jonatas-lima is right, if we provide a default value then we must set the attribute Computed to true.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that's a bit counter-intuitive :)


"type": schema.StringAttribute{
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.

Same question as for the description.

Copy link
Member

Choose a reason for hiding this comment

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

The network integration type is both required and not computed on our end.
So this indeed looks wrong, it should be false on both counts.

Copy link
Contributor Author

@jonatas-lima jonatas-lima Dec 2, 2024

Choose a reason for hiding this comment

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

I can't use a default value if the field is not Computed:

$ TF_ACC=1 go test -v internal/network/resource_network_integration_test.go

- Schema Using Attribute Default For Non-Computed Attribute: Attribute
        "type" must be computed when using default. This is an issue with the
        provider and should be reported to the provider developers.

Copy link
Contributor Author

@jonatas-lima jonatas-lima Dec 2, 2024

Choose a reason for hiding this comment

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

I like the idea of this field being optional because it behaves like an "enum", with "ovn" as the default value (currently the only supported network integration type). This simplifies the configuration by removing the need to always specify the type explicitly.

Copy link
Member

Choose a reason for hiding this comment

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

It just feels a bit odd to have the terraform provider have it use ovn as default when at the API and CLI level there is no such default and the user is required to pick the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, agree on that.

@stgraber stgraber merged commit ed45143 into lxc:main Dec 3, 2024
7 of 10 checks passed
@stgraber
Copy link
Member

stgraber commented Dec 3, 2024

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add new network_integration resource
4 participants