Skip to content

Commit 4c1cefb

Browse files
jaymclaude
authored andcommitted
Switch condition and rule from ListNestedAttribute to ListNestedBlock
Fixes "Unsupported block type" error by using schema.ListNestedBlock for rule and condition, which supports the natural HCL block syntax. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8595e46 commit 4c1cefb

3 files changed

Lines changed: 34 additions & 36 deletions

File tree

internal/provider/asset_routing_common.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,31 @@ type AssetRoutingConditionModel struct {
1818
Key types.String `tfsdk:"key"`
1919
}
2020

21-
// assetRoutingConditionSchemaAttributes returns the schema attributes for a routing condition,
21+
// assetRoutingConditionSchemaBlock returns a ListNestedBlock for routing conditions,
2222
// reusable by both the table and rule resources.
23-
func assetRoutingConditionSchemaAttributes() map[string]schema.Attribute {
24-
return map[string]schema.Attribute{
25-
"field": schema.StringAttribute{
26-
MarkdownDescription: "The field to match on. Valid values: `HOSTNAME`, `PLATFORM`, `LABEL`.",
27-
Required: true,
28-
},
29-
"operator": schema.StringAttribute{
30-
MarkdownDescription: "The comparison operator. Valid values: `EQUAL`, `NOT_EQUAL`, `CONTAINS`, `MATCHES`.",
31-
Required: true,
32-
},
33-
"values": schema.ListAttribute{
34-
MarkdownDescription: "List of values to match against. A condition matches if the field matches any of the listed values (OR logic).",
35-
Required: true,
36-
ElementType: types.StringType,
37-
},
38-
"key": schema.StringAttribute{
39-
MarkdownDescription: "The label key to match on. Required when `field` is `LABEL`.",
40-
Optional: true,
23+
func assetRoutingConditionSchemaBlock() schema.ListNestedBlock {
24+
return schema.ListNestedBlock{
25+
MarkdownDescription: "Conditions that must all match for this rule to apply (AND logic). If empty, the rule matches all assets (catch-all).",
26+
NestedObject: schema.NestedBlockObject{
27+
Attributes: map[string]schema.Attribute{
28+
"field": schema.StringAttribute{
29+
MarkdownDescription: "The field to match on. Valid values: `HOSTNAME`, `PLATFORM`, `LABEL`.",
30+
Required: true,
31+
},
32+
"operator": schema.StringAttribute{
33+
MarkdownDescription: "The comparison operator. Valid values: `EQUAL`, `NOT_EQUAL`, `CONTAINS`, `MATCHES`.",
34+
Required: true,
35+
},
36+
"values": schema.ListAttribute{
37+
MarkdownDescription: "List of values to match against. A condition matches if the field matches any of the listed values (OR logic).",
38+
Required: true,
39+
ElementType: types.StringType,
40+
},
41+
"key": schema.StringAttribute{
42+
MarkdownDescription: "The label key to match on. Required when `field` is `LABEL`.",
43+
Optional: true,
44+
},
45+
},
4146
},
4247
}
4348
}

internal/provider/asset_routing_rule_resource.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,9 @@ func (r *AssetRoutingRuleResource) Schema(_ context.Context, _ resource.SchemaRe
7171
int64planmodifier.UseStateForUnknown(),
7272
},
7373
},
74-
"condition": schema.ListNestedAttribute{
75-
MarkdownDescription: "Conditions that must all match for this rule to apply (AND logic). If empty, the rule matches all assets (catch-all).",
76-
Optional: true,
77-
NestedObject: schema.NestedAttributeObject{
78-
Attributes: assetRoutingConditionSchemaAttributes(),
79-
},
80-
},
74+
},
75+
Blocks: map[string]schema.Block{
76+
"condition": assetRoutingConditionSchemaBlock(),
8177
},
8278
}
8379
}

internal/provider/asset_routing_table_resource.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,19 @@ func (r *AssetRoutingTableResource) Schema(_ context.Context, _ resource.SchemaR
5454
stringplanmodifier.RequiresReplace(),
5555
},
5656
},
57-
"rule": schema.ListNestedAttribute{
57+
},
58+
Blocks: map[string]schema.Block{
59+
"rule": schema.ListNestedBlock{
5860
MarkdownDescription: "Ordered list of routing rules. Priority is determined by position (first = highest priority). A rule with no conditions acts as a catch-all.",
59-
Required: true,
60-
NestedObject: schema.NestedAttributeObject{
61+
NestedObject: schema.NestedBlockObject{
6162
Attributes: map[string]schema.Attribute{
6263
"target_space_mrn": schema.StringAttribute{
6364
MarkdownDescription: "The MRN of the space where matching assets will be routed.",
6465
Required: true,
6566
},
66-
"condition": schema.ListNestedAttribute{
67-
MarkdownDescription: "Conditions that must all match for this rule to apply (AND logic). If empty, the rule matches all assets (catch-all).",
68-
Optional: true,
69-
NestedObject: schema.NestedAttributeObject{
70-
Attributes: assetRoutingConditionSchemaAttributes(),
71-
},
72-
},
67+
},
68+
Blocks: map[string]schema.Block{
69+
"condition": assetRoutingConditionSchemaBlock(),
7370
},
7471
},
7572
},

0 commit comments

Comments
 (0)