Skip to content

Commit 315b6b2

Browse files
grubmeshiclaude
andcommitted
refactor: scope sensitive input attrs to bb_v2 via struct embedding
Use buildingBlockV2UserInputModel (embeds buildingBlockUserInputModel) and buildingBlockV2UserInputs() so value_string_sensitive and value_code_sensitive only appear on the bb_v2 resource. The v1 buildingblock resource and its docs are unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6fcb52b commit 315b6b2

3 files changed

Lines changed: 83 additions & 37 deletions

File tree

docs/resources/buildingblock.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ Optional:
8484

8585
- `value_bool` (Boolean)
8686
- `value_code` (String) Code value.
87-
- `value_code_sensitive` (String, Sensitive) Plaintext value for a sensitive CODE user input. Stored in state but masked in output. Use this instead of `value_code` when the building block definition marks the input as sensitive.
8887
- `value_int` (Number)
8988
- `value_multi_select` (List of String) Multi-select value (list of strings).
9089
- `value_single_select` (String)
9190
- `value_string` (String)
92-
- `value_string_sensitive` (String, Sensitive) Plaintext value for a sensitive STRING user input. Stored in state but masked in output. Use this instead of `value_string` when the building block definition marks the input as sensitive.
9391

9492

9593
<a id="nestedatt--spec--parent_building_blocks"></a>

internal/provider/building_block_common.go

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ func buildingBlockUserInputs() schema.MapNestedAttribute {
5959
types.MapValueMust(
6060
types.ObjectType{
6161
AttrTypes: map[string]attr.Type{
62-
"value_string": types.StringType,
63-
"value_single_select": types.StringType,
64-
"value_multi_select": types.ListType{ElemType: types.StringType},
65-
"value_int": types.Int64Type,
66-
"value_bool": types.BoolType,
67-
"value_code": types.StringType,
68-
"value_string_sensitive": types.StringType,
69-
"value_code_sensitive": types.StringType,
62+
"value_string": types.StringType,
63+
"value_single_select": types.StringType,
64+
"value_multi_select": types.ListType{ElemType: types.StringType},
65+
"value_int": types.Int64Type,
66+
"value_bool": types.BoolType,
67+
"value_code": types.StringType,
7068
},
7169
},
7270
map[string]attr.Value{},
@@ -84,25 +82,9 @@ func buildingBlockUserInputs() schema.MapNestedAttribute {
8482
path.MatchRelative().AtParent().AtName("value_int"),
8583
path.MatchRelative().AtParent().AtName("value_bool"),
8684
path.MatchRelative().AtParent().AtName("value_code"),
87-
path.MatchRelative().AtParent().AtName("value_string_sensitive"),
88-
path.MatchRelative().AtParent().AtName("value_code_sensitive"),
8985
)},
9086
}
9187

92-
inputs.NestedObject.Attributes["value_string_sensitive"] = schema.StringAttribute{
93-
MarkdownDescription: "Plaintext value for a sensitive STRING user input. Stored in state but masked in output. " +
94-
"Use this instead of `value_string` when the building block definition marks the input as sensitive.",
95-
Optional: true,
96-
Sensitive: true,
97-
}
98-
99-
inputs.NestedObject.Attributes["value_code_sensitive"] = schema.StringAttribute{
100-
MarkdownDescription: "Plaintext value for a sensitive CODE user input. Stored in state but masked in output. " +
101-
"Use this instead of `value_code` when the building block definition marks the input as sensitive.",
102-
Optional: true,
103-
Sensitive: true,
104-
}
105-
10688
return inputs
10789
}
10890

@@ -135,14 +117,12 @@ func buildingBlockOutputs() schema.MapNestedAttribute {
135117
// Resource models and functions
136118

137119
type buildingBlockUserInputModel struct {
138-
ValueString types.String `tfsdk:"value_string"`
139-
ValueSingleSelect types.String `tfsdk:"value_single_select"`
140-
ValueMultiSelect []types.String `tfsdk:"value_multi_select"`
141-
ValueInt types.Int64 `tfsdk:"value_int"`
142-
ValueBool types.Bool `tfsdk:"value_bool"`
143-
ValueCode types.String `tfsdk:"value_code"`
144-
ValueStringSensitive types.String `tfsdk:"value_string_sensitive"`
145-
ValueCodeSensitive types.String `tfsdk:"value_code_sensitive"`
120+
ValueString types.String `tfsdk:"value_string"`
121+
ValueSingleSelect types.String `tfsdk:"value_single_select"`
122+
ValueMultiSelect []types.String `tfsdk:"value_multi_select"`
123+
ValueInt types.Int64 `tfsdk:"value_int"`
124+
ValueBool types.Bool `tfsdk:"value_bool"`
125+
ValueCode types.String `tfsdk:"value_code"`
146126
}
147127

148128
type buildingBlockOutputModel struct {

internal/provider/building_block_v2_resource.go

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/resource"
1313
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
15+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/mapdefault"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier"
1517
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
1618
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1719
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
@@ -30,6 +32,72 @@ var (
3032
_ resource.ResourceWithConfigure = &buildingBlockV2Resource{}
3133
)
3234

35+
// buildingBlockV2UserInputModel extends buildingBlockUserInputModel with sensitive input variants
36+
// specific to the BB v2 resource. Embedding flattens tfsdk tags so the framework sees all fields.
37+
type buildingBlockV2UserInputModel struct {
38+
buildingBlockUserInputModel
39+
ValueStringSensitive types.String `tfsdk:"value_string_sensitive"`
40+
ValueCodeSensitive types.String `tfsdk:"value_code_sensitive"`
41+
}
42+
43+
// buildingBlockV2UserInputs extends the base user-inputs schema with sensitive STRING and CODE
44+
// variants. Only used by the BB v2 resource; the v1 buildingblock resource uses the base schema.
45+
func buildingBlockV2UserInputs() schema.MapNestedAttribute {
46+
inputs := buildingBlockUserInputs()
47+
48+
// Replace Default with the extended object type (adds the two sensitive fields).
49+
inputs.Default = mapdefault.StaticValue(
50+
types.MapValueMust(
51+
types.ObjectType{
52+
AttrTypes: map[string]attr.Type{
53+
"value_string": types.StringType,
54+
"value_single_select": types.StringType,
55+
"value_multi_select": types.ListType{ElemType: types.StringType},
56+
"value_int": types.Int64Type,
57+
"value_bool": types.BoolType,
58+
"value_code": types.StringType,
59+
"value_string_sensitive": types.StringType,
60+
"value_code_sensitive": types.StringType,
61+
},
62+
},
63+
map[string]attr.Value{},
64+
),
65+
)
66+
inputs.PlanModifiers = []planmodifier.Map{mapplanmodifier.RequiresReplace()}
67+
68+
// Extend the ExactlyOneOf validator on value_string to include the sensitive variants.
69+
inputs.NestedObject.Attributes["value_string"] = schema.StringAttribute{
70+
Optional: true,
71+
Computed: false,
72+
Validators: []validator.String{stringvalidator.ExactlyOneOf(
73+
path.MatchRelative().AtParent().AtName("value_string"),
74+
path.MatchRelative().AtParent().AtName("value_single_select"),
75+
path.MatchRelative().AtParent().AtName("value_multi_select"),
76+
path.MatchRelative().AtParent().AtName("value_int"),
77+
path.MatchRelative().AtParent().AtName("value_bool"),
78+
path.MatchRelative().AtParent().AtName("value_code"),
79+
path.MatchRelative().AtParent().AtName("value_string_sensitive"),
80+
path.MatchRelative().AtParent().AtName("value_code_sensitive"),
81+
)},
82+
}
83+
84+
inputs.NestedObject.Attributes["value_string_sensitive"] = schema.StringAttribute{
85+
MarkdownDescription: "Plaintext value for a sensitive STRING user input. Stored in state but masked in output. " +
86+
"Use this instead of `value_string` when the building block definition marks the input as sensitive.",
87+
Optional: true,
88+
Sensitive: true,
89+
}
90+
91+
inputs.NestedObject.Attributes["value_code_sensitive"] = schema.StringAttribute{
92+
MarkdownDescription: "Plaintext value for a sensitive CODE user input. Stored in state but masked in output. " +
93+
"Use this instead of `value_code` when the building block definition marks the input as sensitive.",
94+
Optional: true,
95+
Sensitive: true,
96+
}
97+
98+
return inputs
99+
}
100+
33101
func NewBuildingBlockV2Resource() resource.Resource {
34102
return &buildingBlockV2Resource{}
35103
}
@@ -121,7 +189,7 @@ func (r *buildingBlockV2Resource) Schema(ctx context.Context, req resource.Schem
121189
},
122190
},
123191

124-
"inputs": buildingBlockUserInputs(),
192+
"inputs": buildingBlockV2UserInputs(),
125193
"combined_inputs": buildingBlockCombinedInputs(),
126194

127195
"parent_building_blocks": schema.SetNestedAttribute{
@@ -222,8 +290,8 @@ func (r *buildingBlockV2Resource) Create(ctx context.Context, req resource.Creat
222290
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("spec").AtName("parent_building_blocks"), &bb.Spec.ParentBuildingBlocks)...)
223291
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("spec").AtName("target_ref"), &bb.Spec.TargetRef)...)
224292

225-
// Set user inputs
226-
var userInputs map[string]buildingBlockUserInputModel
293+
// Set user inputs — use the v2-extended model to capture sensitive variants.
294+
var userInputs map[string]buildingBlockV2UserInputModel
227295
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("spec").AtName("inputs"), &userInputs)...)
228296

229297
for key, values := range userInputs {

0 commit comments

Comments
 (0)