Skip to content

Commit c7d23b4

Browse files
authored
chore: Uses blocks for Tags and Labels in TPF (#2901)
* move labels and tags from attrs to blocks * don't convert labels and tags * allow null value in Labels and Tags * fix TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate
1 parent 586dfc5 commit c7d23b4

File tree

5 files changed

+58
-62
lines changed

5 files changed

+58
-62
lines changed

internal/service/advancedclustertpf/model_to_ClusterDescription20240805.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newBiConnector(ctx context.Context, input types.Object, diags *diag.Diagnos
6161
}
6262
}
6363
func newComponentLabel(ctx context.Context, input types.Set, diags *diag.Diagnostics) *[]admin.ComponentLabel {
64-
if input.IsUnknown() || input.IsNull() {
64+
if input.IsUnknown() {
6565
return nil
6666
}
6767
elements := make([]TFLabelsModel, len(input.Elements()))
@@ -110,7 +110,7 @@ func resolveZoneNameOrUseDefault(item *TFReplicationSpecsModel) string {
110110
}
111111

112112
func newResourceTag(ctx context.Context, input types.Set, diags *diag.Diagnostics) *[]admin.ResourceTag {
113-
if input.IsUnknown() || input.IsNull() {
113+
if input.IsUnknown() {
114114
return nil
115115
}
116116
elements := make([]TFTagsModel, len(input.Elements()))

internal/service/advancedclustertpf/resource_test_cases_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ func replicasetAdvConfigUpdate(t *testing.T) *resource.TestCase {
337337
enabled = true
338338
}
339339
# config_server_management_mode = "ATLAS_MANAGED" UNSTABLE: After applying this test step, the non-refresh plan was not empty
340-
labels = [{
340+
labels {
341341
key = "env"
342342
value = "test"
343-
}]
344-
tags = [{
343+
}
344+
tags {
345345
key = "env"
346346
value = "test"
347-
}]
347+
}
348348
mongo_db_major_version = "8.0"
349349
pit_enabled = true
350350
redact_client_log_data = true

internal/service/advancedclustertpf/schema.go

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1313
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
15-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
1615
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1716
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1817
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -155,24 +154,6 @@ func resourceSchema(ctx context.Context) schema.Schema {
155154
Computed: true,
156155
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the cluster.",
157156
},
158-
"labels": schema.SetNestedAttribute{
159-
Computed: true,
160-
Optional: true,
161-
Default: setdefault.StaticValue(types.SetValueMust(LabelsObjType, nil)),
162-
MarkdownDescription: "Collection of key-value pairs between 1 to 255 characters in length that tag and categorize the cluster. The MongoDB Cloud console doesn't display your labels.\n\nCluster labels are deprecated and will be removed in a future release. We strongly recommend that you use [resource tags](https://dochub.mongodb.org/core/add-cluster-tag-atlas) instead.",
163-
NestedObject: schema.NestedAttributeObject{
164-
Attributes: map[string]schema.Attribute{
165-
"key": schema.StringAttribute{
166-
Required: true,
167-
MarkdownDescription: "Key applied to tag and categorize this component.",
168-
},
169-
"value": schema.StringAttribute{
170-
Required: true,
171-
MarkdownDescription: "Value set to the Key applied to tag and categorize this component.",
172-
},
173-
},
174-
},
175-
},
176157
"mongo_db_major_version": schema.StringAttribute{
177158
Computed: true,
178159
Optional: true,
@@ -291,24 +272,6 @@ func resourceSchema(ctx context.Context) schema.Schema {
291272
Computed: true,
292273
MarkdownDescription: "Human-readable label that indicates the current operating condition of this cluster.",
293274
},
294-
"tags": schema.SetNestedAttribute{
295-
Computed: true,
296-
Optional: true,
297-
Default: setdefault.StaticValue(types.SetValueMust(TagsObjType, nil)),
298-
MarkdownDescription: "List that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster.",
299-
NestedObject: schema.NestedAttributeObject{
300-
Attributes: map[string]schema.Attribute{
301-
"key": schema.StringAttribute{
302-
Required: true,
303-
MarkdownDescription: "Constant that defines the set of the tag. For example, `environment` in the `environment : production` tag.",
304-
},
305-
"value": schema.StringAttribute{
306-
Required: true,
307-
MarkdownDescription: "Variable that belongs to the set of the tag. For example, `production` in the `environment : production` tag.",
308-
},
309-
},
310-
},
311-
},
312275
"termination_protection_enabled": schema.BoolAttribute{
313276
Computed: true,
314277
Optional: true,
@@ -350,6 +313,38 @@ func resourceSchema(ctx context.Context) schema.Schema {
350313
Delete: true,
351314
}),
352315
},
316+
Blocks: map[string]schema.Block{
317+
"labels": schema.SetNestedBlock{
318+
MarkdownDescription: "Collection of key-value pairs between 1 to 255 characters in length that tag and categorize the cluster. The MongoDB Cloud console doesn't display your labels.\n\nCluster labels are deprecated and will be removed in a future release. We strongly recommend that you use [resource tags](https://dochub.mongodb.org/core/add-cluster-tag-atlas) instead.",
319+
NestedObject: schema.NestedBlockObject{
320+
Attributes: map[string]schema.Attribute{
321+
"key": schema.StringAttribute{
322+
Required: true,
323+
MarkdownDescription: "Key applied to tag and categorize this component.",
324+
},
325+
"value": schema.StringAttribute{
326+
Required: true,
327+
MarkdownDescription: "Value set to the Key applied to tag and categorize this component.",
328+
},
329+
},
330+
},
331+
},
332+
"tags": schema.SetNestedBlock{
333+
MarkdownDescription: "List that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster.",
334+
NestedObject: schema.NestedBlockObject{
335+
Attributes: map[string]schema.Attribute{
336+
"key": schema.StringAttribute{
337+
Required: true,
338+
MarkdownDescription: "Constant that defines the set of the tag. For example, `environment` in the `environment : production` tag.",
339+
},
340+
"value": schema.StringAttribute{
341+
Required: true,
342+
MarkdownDescription: "Variable that belongs to the set of the tag. For example, `production` in the `environment : production` tag.",
343+
},
344+
},
345+
},
346+
},
347+
},
353348
}
354349
}
355350

internal/testutil/acc/advanced_cluster_schema_v2.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ func ConvertAdvancedClusterToSchemaV2(t *testing.T, isAcc bool, def string) stri
9797
continue
9898
}
9999
writeBody := resource.Body()
100-
convertAttrs(t, "labels", writeBody, true, hcl.GetAttrVal)
101-
convertAttrs(t, "tags", writeBody, true, hcl.GetAttrVal)
102100
convertAttrs(t, "replication_specs", writeBody, true, getReplicationSpecs)
103101
convertAttrs(t, "advanced_configuration", writeBody, false, hcl.GetAttrVal)
104102
convertAttrs(t, "bi_connector_config", writeBody, false, hcl.GetAttrVal)

internal/testutil/acc/advanced_cluster_schema_v2_test.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,33 @@ func TestConvertAdvancedClusterToSchemaV2(t *testing.T) {
152152
cluster_type = "SHARDED"
153153
154154
155-
156-
157-
158-
159-
160-
161155
162-
labels = [{
156+
tags {
157+
key = "Key Tag 2"
158+
value = "Value Tag 2"
159+
}
160+
161+
labels {
163162
key = "Key Label 1"
164163
value = "Value Label 1"
165-
}, {
164+
}
165+
166+
tags {
167+
key = "Key Tag 1"
168+
value = "Value Tag 1"
169+
}
170+
171+
labels {
166172
key = "Key Label 2"
167173
value = "Value Label 2"
168-
}, {
174+
}
175+
176+
labels {
169177
key = "Key Label 3"
170178
value = "Value Label 3"
171-
}]
172-
tags = [{
173-
key = "Key Tag 2"
174-
value = "Value Tag 2"
175-
}, {
176-
key = "Key Tag 1"
177-
value = "Value Tag 1"
178-
}]
179+
}
180+
181+
179182
replication_specs = [{
180183
region_configs = [{
181184
analytics_specs = {

0 commit comments

Comments
 (0)