Skip to content

Commit 8f2fa72

Browse files
feat: mark password fields as sensitive in dedicated server resources (#515)
- Add Sensitive: true to password field in dedicatedserver/credential_resource.go - Add Sensitive: true to password field in dedicatedserver/installation_resource.go - Add schema unit tests to verify password fields are marked as sensitive - Update documentation to reflect sensitive attribute Fixes #6 Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Imtiaz Ahmed <imtiazPabel@users.noreply.github.com>
1 parent 95fc469 commit 8f2fa72

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

docs/resources/dedicated_server_credential.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ resource "leaseweb_dedicated_server_credential" "example" {
2828
### Required
2929

3030
- `dedicated_server_id` (String) The ID of the dedicated server.
31-
- `password` (String) The password for the credentials
31+
- `password` (String, Sensitive) The password for the credentials
3232
- `type` (String) The type of the credential. Valid options are: "OPERATING_SYSTEM", "CONTROL_PANEL", "REMOTE_MANAGEMENT", "RESCUE_MODE", "SWITCH", "PDU", "FIREWALL", "LOAD_BALANCER"
3333
- `username` (String) The username for the credentials

docs/resources/dedicated_server_installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ resource "leaseweb_dedicated_server_installation" "example" {
4949
- `device` (String) Block devices in a disk set in which the partitions will be installed. Supported values are any disk set id, `SATA_SAS` or `NVME`.
5050
- `hostname` (String) Hostname to be used in your installation
5151
- `partitions` (Attributes List) (see [below for nested schema](#nestedatt--partitions))
52-
- `password` (String) Server root password. If not provided, it would be automatically generated
52+
- `password` (String, Sensitive) Server root password. If not provided, it would be automatically generated
5353
- `post_install_script` (String) A valid bash script to run right after the installation.
5454
- `power_cycle` (Boolean) If true, allows system reboots to happen automatically within the process. Otherwise, you should do them manually
5555
- `raid` (Attributes) (see [below for nested schema](#nestedatt--raid))

internal/provider/dedicatedserver/credential_resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (c *credentialResource) Schema(
7171
},
7272
"password": schema.StringAttribute{
7373
Required: true,
74+
Sensitive: true,
7475
Description: `The password for the credentials`,
7576
},
7677
},

internal/provider/dedicatedserver/installation_resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func (i *installationResource) Schema(
206206
"password": schema.StringAttribute{
207207
Description: "Server root password. If not provided, it would be automatically generated",
208208
Optional: true,
209+
Sensitive: true,
209210
PlanModifiers: []planmodifier.String{
210211
stringplanmodifier.RequiresReplace(),
211212
},

internal/provider/provider_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-framework/provider"
1010
"github.com/hashicorp/terraform-plugin-framework/providerserver"
11+
frameworkresource "github.com/hashicorp/terraform-plugin-framework/resource"
1112
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1213
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1314
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1415
"github.com/hashicorp/terraform-plugin-testing/terraform"
16+
"github.com/leaseweb/terraform-provider-leaseweb/internal/provider/dedicatedserver"
1517
"github.com/stretchr/testify/assert"
1618
)
1719

@@ -80,6 +82,38 @@ func TestLeasewebProvider_Schema(t *testing.T) {
8082
)
8183
}
8284

85+
func TestDedicatedServerCredentialResource_Schema(t *testing.T) {
86+
credentialResource := dedicatedserver.NewCredentialResource()
87+
schemaResponse := frameworkresource.SchemaResponse{}
88+
credentialResource.Schema(
89+
context.TODO(),
90+
frameworkresource.SchemaRequest{},
91+
&schemaResponse,
92+
)
93+
94+
assert.True(
95+
t,
96+
schemaResponse.Schema.Attributes["password"].IsSensitive(),
97+
"password is sensitive",
98+
)
99+
}
100+
101+
func TestDedicatedServerInstallationResource_Schema(t *testing.T) {
102+
installationResource := dedicatedserver.NewInstallationResource()
103+
schemaResponse := frameworkresource.SchemaResponse{}
104+
installationResource.Schema(
105+
context.TODO(),
106+
frameworkresource.SchemaRequest{},
107+
&schemaResponse,
108+
)
109+
110+
assert.True(
111+
t,
112+
schemaResponse.Schema.Attributes["password"].IsSensitive(),
113+
"password is sensitive",
114+
)
115+
}
116+
83117
func TestAccPublicCloudInstancesDataSource(t *testing.T) {
84118
resource.Test(t, resource.TestCase{
85119
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,

0 commit comments

Comments
 (0)