@@ -437,6 +437,14 @@ func TestServerPlanResourceChange(t *testing.T) {
437
437
},
438
438
}
439
439
440
+ testSchemaTypeWriteOnly := tftypes.Object {
441
+ AttributeTypes : map [string ]tftypes.Type {
442
+ "test_computed" : tftypes .String ,
443
+ "test_required" : tftypes .String ,
444
+ "test_write_only" : tftypes .String ,
445
+ },
446
+ }
447
+
440
448
testSchemaTypeDefault := tftypes.Object {
441
449
AttributeTypes : map [string ]tftypes.Type {
442
450
"test_computed_bool" : tftypes .Bool ,
@@ -566,6 +574,21 @@ func TestServerPlanResourceChange(t *testing.T) {
566
574
},
567
575
}
568
576
577
+ testSchemaWriteOnly := schema.Schema {
578
+ Attributes : map [string ]schema.Attribute {
579
+ "test_computed" : schema.StringAttribute {
580
+ Computed : true ,
581
+ },
582
+ "test_required" : schema.StringAttribute {
583
+ Required : true ,
584
+ },
585
+ "test_write_only" : schema.StringAttribute {
586
+ Optional : true ,
587
+ WriteOnly : true ,
588
+ },
589
+ },
590
+ }
591
+
569
592
testSchemaDefault := schema.Schema {
570
593
Attributes : map [string ]schema.Attribute {
571
594
"test_computed_bool" : schema.BoolAttribute {
@@ -1069,6 +1092,11 @@ func TestServerPlanResourceChange(t *testing.T) {
1069
1092
Schema : testSchema ,
1070
1093
}
1071
1094
1095
+ testEmptyStateWriteOnly := & tfsdk.State {
1096
+ Raw : tftypes .NewValue (testSchemaType , nil ),
1097
+ Schema : testSchemaWriteOnly ,
1098
+ }
1099
+
1072
1100
testEmptyStateDefault := & tfsdk.State {
1073
1101
Raw : tftypes .NewValue (testSchemaTypeDefault , nil ),
1074
1102
Schema : testSchemaDefault ,
@@ -1367,6 +1395,43 @@ func TestServerPlanResourceChange(t *testing.T) {
1367
1395
PlannedPrivate : testEmptyPrivate ,
1368
1396
},
1369
1397
},
1398
+ "create-mark-computed-config-nils-as-unknown-write-only" : {
1399
+ server : & fwserver.Server {
1400
+ Provider : & testprovider.Provider {},
1401
+ },
1402
+ request : & fwserver.PlanResourceChangeRequest {
1403
+ Config : & tfsdk.Config {
1404
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
1405
+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
1406
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
1407
+ "test_write_only" : tftypes .NewValue (tftypes .String , "test-write-only-value" ),
1408
+ }),
1409
+ Schema : testSchemaWriteOnly ,
1410
+ },
1411
+ ProposedNewState : & tfsdk.Plan {
1412
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
1413
+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
1414
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
1415
+ "test_write_only" : tftypes .NewValue (tftypes .String , "test-write-only-value" ),
1416
+ }),
1417
+ Schema : testSchemaWriteOnly ,
1418
+ },
1419
+ PriorState : testEmptyStateWriteOnly ,
1420
+ ResourceSchema : testSchemaWriteOnly ,
1421
+ Resource : & testprovider.Resource {},
1422
+ },
1423
+ expectedResponse : & fwserver.PlanResourceChangeResponse {
1424
+ PlannedState : & tfsdk.State {
1425
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
1426
+ "test_computed" : tftypes .NewValue (tftypes .String , tftypes .UnknownValue ),
1427
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
1428
+ "test_write_only" : tftypes .NewValue (tftypes .String , nil ),
1429
+ }),
1430
+ Schema : testSchemaWriteOnly ,
1431
+ },
1432
+ PlannedPrivate : testEmptyPrivate ,
1433
+ },
1434
+ },
1370
1435
"create-set-default-values" : {
1371
1436
server : & fwserver.Server {
1372
1437
Provider : & testprovider.Provider {},
@@ -3883,6 +3948,50 @@ func TestServerPlanResourceChange(t *testing.T) {
3883
3948
PlannedPrivate : testEmptyPrivate ,
3884
3949
},
3885
3950
},
3951
+ "update-mark-computed-config-nils-as-unknown-write-only" : {
3952
+ server : & fwserver.Server {
3953
+ Provider : & testprovider.Provider {},
3954
+ },
3955
+ request : & fwserver.PlanResourceChangeRequest {
3956
+ Config : & tfsdk.Config {
3957
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
3958
+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
3959
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
3960
+ "test_write_only" : tftypes .NewValue (tftypes .String , "test-write-only-value" ),
3961
+ }),
3962
+ Schema : testSchemaWriteOnly ,
3963
+ },
3964
+ ProposedNewState : & tfsdk.Plan {
3965
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
3966
+ "test_computed" : tftypes .NewValue (tftypes .String , "prior-state-val" ),
3967
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
3968
+ "test_write_only" : tftypes .NewValue (tftypes .String , "test-write-only-value" ),
3969
+ }),
3970
+ Schema : testSchemaWriteOnly ,
3971
+ },
3972
+ PriorState : & tfsdk.State {
3973
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
3974
+ "test_computed" : tftypes .NewValue (tftypes .String , "prior-state-val" ),
3975
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
3976
+ "test_write_only" : tftypes .NewValue (tftypes .String , nil ),
3977
+ }),
3978
+ Schema : testSchemaWriteOnly ,
3979
+ },
3980
+ ResourceSchema : testSchemaWriteOnly ,
3981
+ Resource : & testprovider.Resource {},
3982
+ },
3983
+ expectedResponse : & fwserver.PlanResourceChangeResponse {
3984
+ PlannedState : & tfsdk.State {
3985
+ Raw : tftypes .NewValue (testSchemaTypeWriteOnly , map [string ]tftypes.Value {
3986
+ "test_computed" : tftypes .NewValue (tftypes .String , "prior-state-val" ),
3987
+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
3988
+ "test_write_only" : tftypes .NewValue (tftypes .String , nil ),
3989
+ }),
3990
+ Schema : testSchemaWriteOnly ,
3991
+ },
3992
+ PlannedPrivate : testEmptyPrivate ,
3993
+ },
3994
+ },
3886
3995
"update-set-default-values" : {
3887
3996
server : & fwserver.Server {
3888
3997
Provider : & testprovider.Provider {},
0 commit comments