Skip to content

Commit 4e5829c

Browse files
committed
Added default namespace for search attribute data source
1 parent 8eb9743 commit 4e5829c

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

internal/provider/search_attribute_data_source.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func (d *SearchAttributeDataSource) Schema(ctx context.Context, req datasource.S
5959
Computed: true,
6060
},
6161
"namespace": schema.StringAttribute{
62-
MarkdownDescription: "Namespace with which the Search Attribute is associated",
63-
Required: true,
62+
MarkdownDescription: "Namespace with which the Search Attribute is associated. If this is not provided, 'default' will be used",
63+
Optional: true,
6464
},
6565
},
6666
}
@@ -94,7 +94,8 @@ func (d *SearchAttributeDataSource) Configure(ctx context.Context, req datasourc
9494
func (d *SearchAttributeDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
9595
tflog.Info(ctx, "Reading Temporal Search Attribute")
9696

97-
var name, namespace string
97+
var name string
98+
var namespace types.String
9899

99100
// Get the 'name' and 'namespace' attributes from the configuration
100101
diags := req.Config.GetAttribute(ctx, path.Root("name"), &name)
@@ -109,8 +110,13 @@ func (d *SearchAttributeDataSource) Read(ctx context.Context, req datasource.Rea
109110
return
110111
}
111112

113+
// If the user has not provided a namespace for the data source, use 'default'
114+
if namespace.IsNull() {
115+
namespace = types.StringValue("default")
116+
}
117+
112118
request := &operatorservice.ListSearchAttributesRequest{
113-
Namespace: namespace,
119+
Namespace: namespace.ValueString(),
114120
}
115121

116122
// Calling API for existing attribute details
@@ -133,7 +139,7 @@ func (d *SearchAttributeDataSource) Read(ctx context.Context, req datasource.Rea
133139
data := &SearchAttributeDataSourceModel{
134140
Name: types.StringValue(name),
135141
Type: types.StringValue(attributeType.String()),
136-
Namespace: types.StringValue(namespace),
142+
Namespace: namespace,
137143
}
138144

139145
// Save the fetched data into Terraform state

internal/provider/search_attribute_data_source_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ func TestAccSearchAttributeDataSource(t *testing.T) {
1212

1313
Steps: []resource.TestStep{
1414
// Test reading from the server and setting data source attributes
15+
16+
// Test reading data source without explicitly proving namespace, should use 'default'
1517
{
1618
Config: providerConfig + `
1719
data "temporal_search_attribute" "example" {
1820
name = "RunId"
19-
namespace = "default"
2021
}`,
2122

2223
Check: resource.ComposeAggregateTestCheckFunc(
@@ -25,6 +26,21 @@ func TestAccSearchAttributeDataSource(t *testing.T) {
2526
resource.TestCheckResourceAttr("data.temporal_search_attribute.example", "namespace", "default"),
2627
),
2728
},
29+
30+
// Test reading with provided namespace
31+
{
32+
Config: providerConfig + `
33+
data "temporal_search_attribute" "example" {
34+
name = "HistoryLength"
35+
namespace = "default"
36+
}`,
37+
38+
Check: resource.ComposeAggregateTestCheckFunc(
39+
resource.TestCheckResourceAttr("data.temporal_search_attribute.example", "name", "HistoryLength"),
40+
resource.TestCheckResourceAttr("data.temporal_search_attribute.example", "type", "Int"), // Verify that the type was read correctly from the server
41+
resource.TestCheckResourceAttr("data.temporal_search_attribute.example", "namespace", "default"),
42+
),
43+
},
2844
},
2945
})
3046
}

0 commit comments

Comments
 (0)