Skip to content

Commit a2a4105

Browse files
committed
r/aws_transfer_host_key: Use 'RequiresReplaceWO' plan modifier.
1 parent 1c2591d commit a2a4105

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal/service/transfer/host_key.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
intflex "github.com/hashicorp/terraform-provider-aws/internal/flex"
2525
"github.com/hashicorp/terraform-provider-aws/internal/framework"
2626
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
27+
tfstringplanmodifier "github.com/hashicorp/terraform-provider-aws/internal/framework/planmodifiers/stringplanmodifier"
28+
"github.com/hashicorp/terraform-provider-aws/internal/framework/privatestate"
2729
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
2830
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2931
"github.com/hashicorp/terraform-provider-aws/names"
@@ -41,6 +43,10 @@ type hostKeyResource struct {
4143
framework.ResourceWithModel[hostKeyResourceModel]
4244
}
4345

46+
const (
47+
hostKeyBodyWOKey = "host_key_body_wo"
48+
)
49+
4450
func (r *hostKeyResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) {
4551
response.Schema = schema.Schema{
4652
Attributes: map[string]schema.Attribute{
@@ -74,7 +80,7 @@ func (r *hostKeyResource) Schema(ctx context.Context, request resource.SchemaReq
7480
stringvalidator.LengthBetween(0, 4096),
7581
},
7682
PlanModifiers: []planmodifier.String{
77-
stringplanmodifier.RequiresReplace(),
83+
tfstringplanmodifier.RequiresReplaceWO(hostKeyBodyWOKey),
7884
},
7985
},
8086
"host_key_fingerprint": schema.StringAttribute{
@@ -131,6 +137,15 @@ func (r *hostKeyResource) Create(ctx context.Context, request resource.CreateReq
131137
return
132138
}
133139

140+
// Store hash of write-only value.
141+
if !config.HostKeyBodyWO.IsNull() {
142+
woStore := privatestate.NewWriteOnlyValueStore(response.Private, hostKeyBodyWOKey)
143+
response.Diagnostics.Append(woStore.SetValue(ctx, config.HostKeyBodyWO)...)
144+
if response.Diagnostics.HasError() {
145+
return
146+
}
147+
}
148+
134149
hostKeyID := aws.ToString(out.HostKeyId)
135150
hostKey, err := findHostKeyByTwoPartKey(ctx, conn, serverID, hostKeyID)
136151
if err != nil {

0 commit comments

Comments
 (0)