Skip to content

Commit d633eeb

Browse files
Use Computed flag for CNI configuration account/domain/project fields
Instead of using GetOk conditionals in the Read function to avoid drift, mark account, domain_id, and project_id as Computed: true in the schema. This is the standard Terraform pattern used throughout the codebase and allows Terraform to properly handle values returned by the API that weren't explicitly set in the configuration. Addresses review comment about using Computed instead of GetOk pattern.
1 parent de4bd12 commit d633eeb

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

cloudstack/resource_cloudstack_cni_configuration.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,23 @@ func resourceCloudStackCniConfiguration() *schema.Resource {
5555
"account": {
5656
Type: schema.TypeString,
5757
Optional: true,
58+
Computed: true,
5859
ForceNew: true,
5960
Description: "An optional account for the CNI configuration. Must be used with domain_id.",
6061
},
6162

6263
"domain_id": {
6364
Type: schema.TypeString,
6465
Optional: true,
66+
Computed: true,
6567
ForceNew: true,
6668
Description: "An optional domain ID for the CNI configuration. If the account parameter is used, domain_id must also be used.",
6769
},
6870

6971
"project_id": {
7072
Type: schema.TypeString,
7173
Optional: true,
74+
Computed: true,
7275
ForceNew: true,
7376
Description: "An optional project for the CNI configuration",
7477
},
@@ -188,18 +191,9 @@ func resourceCloudStackCniConfigurationRead(d *schema.ResourceData, meta interfa
188191

189192
d.Set("name", config.CniConfiguration[0].Name)
190193
d.Set("cni_config", config.CniConfiguration[0].Userdata)
191-
192-
// Only set account and domain_id if they were originally provided by the user
193-
// to avoid drift when CloudStack returns default values
194-
if _, ok := d.GetOk("account"); ok {
195-
d.Set("account", config.CniConfiguration[0].Account)
196-
}
197-
if _, ok := d.GetOk("domain_id"); ok {
198-
d.Set("domain_id", config.CniConfiguration[0].Domainid)
199-
}
200-
if _, ok := d.GetOk("project_id"); ok {
201-
d.Set("project_id", config.CniConfiguration[0].Projectid)
202-
}
194+
d.Set("account", config.CniConfiguration[0].Account)
195+
d.Set("domain_id", config.CniConfiguration[0].Domainid)
196+
d.Set("project_id", config.CniConfiguration[0].Projectid)
203197

204198
if config.CniConfiguration[0].Params != "" {
205199
paramsList := strings.Split(config.CniConfiguration[0].Params, ",")

0 commit comments

Comments
 (0)