-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
Hi @jonatas-lima, we typically split those kind of PRs into three commits:
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! |
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. |
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.
In the rest of the documentation code blocks are used to point out specific options:
* `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. |
"github.com/lxc/incus/v6/shared/api" | ||
"github.com/lxc/terraform-provider-incus/internal/common" |
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.
Imports should be grouped in 3 groups: stdlib, 3rd party, project internal packages:
"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(), | ||
}, |
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 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
.
}, | |
}, | |
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.
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.
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.
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.
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, |
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.
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?
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.
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.
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 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.
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.
@maveonair any idea what's going on here?
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.
@jonatas-lima is right, if we provide a default value then we must set the attribute Computed
to true.
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.
Ah, that's a bit counter-intuitive :)
|
||
"type": schema.StringAttribute{ | ||
Optional: true, | ||
Computed: true, |
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 question as for the description.
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.
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.
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 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.
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 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.
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.
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.
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.
Ok, agree on that.
Signed-off-by: Jonatas Ferreira <[email protected]>
Signed-off-by: Jonatas Ferreira <[email protected]>
Signed-off-by: Jonatas Ferreira <[email protected]>
thanks! |
Closes #122