Skip to content

Commit

Permalink
Fix Nullable Field of Cluster Email (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
NavisJ authored Feb 4, 2024
1 parent c922128 commit 9e750ad
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/resources/cluster_email.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ resource "powerscale_cluster_email" "test" {
}
# After the execution of above resource block, Cluster Email Settings would have been cached in terraform state file, or
# After the execution of above resource block, Cluster Email Settings would have been cached in terraform state file, and
# Cluster Email Settings would have been updated on PowerScale.
# For more information, Please check the terraform state file.
```
Expand Down Expand Up @@ -103,7 +103,7 @@ Optional:
- `smtp_auth_username` (String) Username to authenticate with if SMTP authentication is being used.
- `smtp_port` (Number) The port on the SMTP server to be used for relaying the notification messages.
- `use_smtp_auth` (Boolean) If true, this cluster will send SMTP authentication credentials to the SMTP relay server in order to send its notification emails. If false, the cluster will attempt to send its notification emails without authentication.
- `user_template` (String) Location of a custom template file that can be used to specify the layout of the notification emails.
- `user_template` (String) Location of a custom template file that can be used to specify the layout of the notification emails. If this string is empty, the default template will be used.

Read-Only:

Expand Down
2 changes: 1 addition & 1 deletion examples/resources/powerscale_cluster_email/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ resource "powerscale_cluster_email" "test" {

}

# After the execution of above resource block, Cluster Email Settings would have been cached in terraform state file, or
# After the execution of above resource block, Cluster Email Settings would have been cached in terraform state file, and
# Cluster Email Settings would have been updated on PowerScale.
# For more information, Please check the terraform state file.
3 changes: 2 additions & 1 deletion goClientZip/PowerScale_API_9.5.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -45408,7 +45408,8 @@
"user_template": {
"description": "Location of a custom template file that can be used to specify the layout of the notification emails.",
"pattern": "^/ifs$|^/ifs/",
"type": "string"
"type": "string",
"x-nullable": true
}
},
"type": "object"
Expand Down
Binary file modified goClientZip/powerscale-go-client.zip
Binary file not shown.
16 changes: 14 additions & 2 deletions powerscale/provider/cluster_email_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func (r *ClusterEmailResource) Schema(ctx context.Context, req resource.SchemaRe
Computed: true,
},
"user_template": schema.StringAttribute{
Description: "Location of a custom template file that can be used to specify the layout of the notification emails.",
MarkdownDescription: "Location of a custom template file that can be used to specify the layout of the notification emails.",
Description: "Location of a custom template file that can be used to specify the layout of the notification emails. If this string is empty, the default template will be used.",
MarkdownDescription: "Location of a custom template file that can be used to specify the layout of the notification emails. If this string is empty, the default template will be used.",
Optional: true,
Computed: true,
},
Expand Down Expand Up @@ -201,6 +201,13 @@ func (r *ClusterEmailResource) Create(ctx context.Context, req resource.CreateRe
)
return
}
// if the field is set to empty, set it to null to update back to default
// if not set, unset the field to not update it
if plan.Settings.UserTemplate.IsUnknown() {
toUpdate.UserTemplate.Unset()
} else if plan.Settings.UserTemplate.ValueString() == "" {
toUpdate.UserTemplate.Set(nil)
}
err = helper.UpdateClusterEmail(ctx, r.client, toUpdate)
if err != nil {
errStr := constants.UpdateClusterEmailSettingsErrorMsg + "with error: "
Expand Down Expand Up @@ -301,6 +308,11 @@ func (r *ClusterEmailResource) Update(ctx context.Context, req resource.UpdateRe
)
return
}
if plan.Settings.UserTemplate.IsUnknown() {
toUpdate.UserTemplate.Unset()
} else if plan.Settings.UserTemplate.ValueString() == "" {
toUpdate.UserTemplate.Set(nil)
}
err = helper.UpdateClusterEmail(ctx, r.client, toUpdate)
if err != nil {
errStr := constants.UpdateClusterEmailSettingsErrorMsg + "with error: "
Expand Down
35 changes: 35 additions & 0 deletions powerscale/provider/cluster_email_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ func TestAccClusterEmailResourceImport(t *testing.T) {
})
}

func TestAccClusterEmailResourceNullableField(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: ProviderConfig + clusterEmailResourceConfig,
},
{
Config: ProviderConfig + clusterEmailUserTemplateSetResourceConfig,
},
{
Config: ProviderConfig + clusterEmailUserTemplateEmptyResourceConfig,
},
},
})
}

func TestAccClusterEmailResourceUpdate(t *testing.T) {
var clusterEmailResourceName = "powerscale_cluster_email.test"
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -216,6 +234,23 @@ resource "powerscale_cluster_email" "test" {
}
}
`

var clusterEmailUserTemplateSetResourceConfig = `
resource "powerscale_cluster_email" "test" {
settings = {
user_template = "/ifs/README.txt"
}
}
`

var clusterEmailUserTemplateEmptyResourceConfig = `
resource "powerscale_cluster_email" "test" {
settings = {
user_template = ""
}
}
`

var clusterEmailUpdateResourceConfig = `
resource "powerscale_cluster_email" "test" {
settings = {
Expand Down

0 comments on commit 9e750ad

Please sign in to comment.