Skip to content

Commit 638ca62

Browse files
authored
feat: Adds max tier size attribute to stream workspace resource and datasource (#3871)
1 parent e8b0aea commit 638ca62

File tree

10 files changed

+84
-29
lines changed

10 files changed

+84
-29
lines changed

.changelog/3871.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
data-source/mongodbatlas_stream_workspace: Adds the `max_tier_size` attribute
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_stream_workspaces: Adds the `max_tier_size` attribute
7+
```
8+
9+
```release-note:enhancement
10+
resource/mongodbatlas_stream_workspace: Adds the `max_tier_size` attribute
11+
```

docs/resources/stream_workspace.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ resource "mongodbatlas_stream_workspace" "example" {
5959

6060
### Stream Config
6161

62-
* `tier` - (Required) Selected tier for the Stream Instance. Configures Memory / VCPU allowances. The [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Streams/operation/creategroupstreamworkspace) describes the valid values.
62+
* `max_tier_size` - (Optional) Max tier size for the Stream Workspace. Configures Memory / VCPU allowances.
63+
* `tier` - (Optional) Selected tier for the Stream Workspace. Configures Memory / VCPU allowances. The [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Streams/operation/creategroupstreamworkspace) describes the valid values.
6364

6465

6566
## Attributes Reference

internal/service/streaminstance/model_stream_instance.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ func NewTFStreamInstance(ctx context.Context, apiResp *admin.StreamsTenant) (*TF
6161
}
6262
var streamConfig = types.ObjectNull(StreamConfigObjectType.AttrTypes)
6363
apiStreamConfig := apiResp.StreamConfig
64-
if apiStreamConfig != nil && apiStreamConfig.Tier != nil {
64+
if apiStreamConfig != nil {
6565
returnedStreamConfig, diagsStreamConfig := types.ObjectValueFrom(ctx, StreamConfigObjectType.AttrTypes, TFInstanceStreamConfigSpecModel{
66-
Tier: types.StringPointerValue(apiStreamConfig.Tier),
66+
MaxTierSize: types.StringPointerValue(apiStreamConfig.MaxTierSize),
67+
Tier: types.StringPointerValue(apiStreamConfig.Tier),
6768
})
6869
streamConfig = returnedStreamConfig
6970
diags.Append(diagsStreamConfig...)

internal/service/streaminstance/resource_schema.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func ResourceSchema(ctx context.Context) schema.Schema {
5050
Optional: true,
5151
Computed: true,
5252
Attributes: map[string]schema.Attribute{
53+
"max_tier_size": schema.StringAttribute{
54+
Optional: true,
55+
Computed: true,
56+
},
5357
"tier": schema.StringAttribute{
5458
Optional: true,
5559
Computed: true,
@@ -75,7 +79,8 @@ type TFInstanceProcessRegionSpecModel struct {
7579
}
7680

7781
type TFInstanceStreamConfigSpecModel struct {
78-
Tier types.String `tfsdk:"tier"`
82+
MaxTierSize types.String `tfsdk:"max_tier_size"`
83+
Tier types.String `tfsdk:"tier"`
7984
}
8085

8186
var ProcessRegionObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{
@@ -84,5 +89,6 @@ var ProcessRegionObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{
8489
}}
8590

8691
var StreamConfigObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{
87-
"tier": types.StringType,
92+
"max_tier_size": types.StringType,
93+
"tier": types.StringType,
8894
}}

internal/service/streamworkspace/data_source_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func TestAccStreamsWorkspaceDS_basic(t *testing.T) {
2929
Config: streamsWorkspaceDataSourceConfig(projectID, workspaceName, region, cloudProvider),
3030
Check: resource.ComposeAggregateTestCheckFunc(
3131
streamsWorkspaceAttributeChecks(dataSourceName, workspaceName, region, cloudProvider),
32-
resource.TestCheckResourceAttr(dataSourceName, "stream_config.tier", "SP30"),
32+
resource.TestCheckResourceAttr(dataSourceName, "stream_config.max_tier_size", "SP30"),
33+
resource.TestCheckResourceAttr(dataSourceName, "stream_config.tier", "SP10"),
3334
),
3435
},
3536
},

internal/service/streamworkspace/model.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package streamworkspace
33
import (
44
"context"
55

6+
"github.com/hashicorp/terraform-plugin-framework/attr"
67
"github.com/hashicorp/terraform-plugin-framework/diag"
8+
"github.com/hashicorp/terraform-plugin-framework/types"
79
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
810
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streaminstance"
911
"go.mongodb.org/atlas-sdk/v20250312009/admin"
@@ -28,8 +30,18 @@ func newStreamWorkspaceCreateReq(ctx context.Context, plan *TFModel) (*admin.Str
2830
if diags := plan.StreamConfig.As(ctx, streamConfig, basetypes.ObjectAsOptions{}); diags.HasError() {
2931
return nil, diags
3032
}
33+
var maxTierSize *string
34+
if streamConfig.MaxTierSize.ValueString() != "" {
35+
maxTierSize = streamConfig.MaxTierSize.ValueStringPointer()
36+
}
37+
38+
var tier *string
39+
if streamConfig.Tier.ValueString() != "" {
40+
tier = streamConfig.Tier.ValueStringPointer()
41+
}
3142
streamTenant.StreamConfig = &admin.StreamConfig{
32-
Tier: streamConfig.Tier.ValueStringPointer(),
43+
MaxTierSize: maxTierSize,
44+
Tier: tier,
3345
}
3446
}
3547
return streamTenant, nil
@@ -54,6 +66,26 @@ func (m *TFModel) FromInstanceModel(instanceModel *streaminstance.TFStreamInstan
5466
m.WorkspaceName = instanceModel.InstanceName
5567
m.ProjectID = instanceModel.ProjectID
5668
m.DataProcessRegion = instanceModel.DataProcessRegion
57-
m.StreamConfig = instanceModel.StreamConfig
69+
if instanceModel.StreamConfig.IsNull() {
70+
m.StreamConfig = types.ObjectNull(map[string]attr.Type{
71+
"max_tier_size": types.StringType,
72+
"tier": types.StringType,
73+
})
74+
} else {
75+
instanceStreamConfigAttrs := instanceModel.StreamConfig.Attributes()
76+
tierValue := instanceStreamConfigAttrs["tier"]
77+
78+
workspaceStreamConfig, _ := types.ObjectValue(
79+
map[string]attr.Type{
80+
"max_tier_size": types.StringType,
81+
"tier": types.StringType,
82+
},
83+
map[string]attr.Value{
84+
"max_tier_size": types.StringNull(),
85+
"tier": tierValue,
86+
},
87+
)
88+
m.StreamConfig = workspaceStreamConfig
89+
}
5890
m.Hostnames = instanceModel.Hostnames
5991
}

internal/service/streamworkspace/move_state.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ func stateMover(ctx context.Context, req resource.MoveStateRequest, resp *resour
108108
tier := schemafunc.GetAttrFromStateObj[string](configObj, "tier")
109109

110110
objValue, diags := types.ObjectValue(map[string]attr.Type{
111-
"tier": types.StringType,
111+
"max_tier_size": types.StringType,
112+
"tier": types.StringType,
112113
}, map[string]attr.Value{
113-
"tier": types.StringPointerValue(tier),
114+
"max_tier_size": types.StringNull(),
115+
"tier": types.StringPointerValue(tier),
114116
})
115117
if !diags.HasError() {
116118
model.StreamConfig = objValue
@@ -119,7 +121,8 @@ func stateMover(ctx context.Context, req resource.MoveStateRequest, resp *resour
119121
}
120122
if model.StreamConfig.IsNull() {
121123
model.StreamConfig = types.ObjectNull(map[string]attr.Type{
122-
"tier": types.StringType,
124+
"max_tier_size": types.StringType,
125+
"tier": types.StringType,
123126
})
124127
}
125128

internal/service/streamworkspace/plural_data_source_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestAccStreamsWorkspacesDS_basic(t *testing.T) {
2222
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.data_process_region.region"),
2323
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.data_process_region.cloud_provider"),
2424
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.hostnames.#"),
25+
resource.TestCheckResourceAttr(dataSourceName, "results.0.stream_config.max_tier_size", "SP30"),
26+
resource.TestCheckResourceAttr(dataSourceName, "results.0.stream_config.tier", "SP10"),
2527
}
2628

2729
resource.ParallelTest(t, resource.TestCase{

internal/service/streamworkspace/resource_schema.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ func ResourceSchema(ctx context.Context) schema.Schema {
4646
Optional: true,
4747
Computed: true,
4848
Attributes: map[string]schema.Attribute{
49+
"max_tier_size": schema.StringAttribute{
50+
Optional: true,
51+
Computed: true,
52+
PlanModifiers: []planmodifier.String{
53+
stringplanmodifier.UseStateForUnknown(),
54+
},
55+
},
4956
"tier": schema.StringAttribute{
5057
Optional: true,
5158
Computed: true,
@@ -71,5 +78,6 @@ type TFWorkspaceProcessRegionSpecModel struct {
7178
}
7279

7380
type TFWorkspaceStreamConfigModel struct {
74-
Tier types.String `tfsdk:"tier"`
81+
MaxTierSize types.String `tfsdk:"max_tier_size"`
82+
Tier types.String `tfsdk:"tier"`
7583
}

internal/service/streamworkspace/resource_test.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func TestAccStreamWorkspaceRS_basic(t *testing.T) {
2525
Config: streamsWorkspaceConfig(projectID, workspaceName, region, cloudProvider),
2626
Check: resource.ComposeAggregateTestCheckFunc(
2727
streamsWorkspaceAttributeChecks(resourceName, workspaceName, region, cloudProvider),
28-
resource.TestCheckResourceAttr(resourceName, "stream_config.tier", "SP30"),
28+
resource.TestCheckResourceAttr(resourceName, "stream_config.max_tier_size", "SP30"),
29+
resource.TestCheckResourceAttr(resourceName, "stream_config.tier", "SP10"),
2930
),
3031
},
3132
{
@@ -50,10 +51,11 @@ func TestAccStreamWorkspaceRS_withStreamConfig(t *testing.T) {
5051
CheckDestroy: acc.CheckDestroyStreamInstance, // Reuse the same destroy check
5152
Steps: []resource.TestStep{
5253
{
53-
Config: streamsWorkspaceConfigWithStreamConfig(projectID, workspaceName, region, cloudProvider),
54+
Config: streamsWorkspaceConfig(projectID, workspaceName, region, cloudProvider),
5455
Check: resource.ComposeAggregateTestCheckFunc(
5556
streamsWorkspaceAttributeChecks(resourceName, workspaceName, region, cloudProvider),
56-
resource.TestCheckResourceAttr(resourceName, "stream_config.tier", "SP30"),
57+
resource.TestCheckResourceAttr(resourceName, "stream_config.max_tier_size", "SP30"),
58+
resource.TestCheckResourceAttr(resourceName, "stream_config.tier", "SP10"),
5759
),
5860
},
5961
},
@@ -101,19 +103,6 @@ func checkStreamsWorkspaceImportStateIDFunc(resourceName string) resource.Import
101103
}
102104

103105
func streamsWorkspaceConfig(projectID, workspaceName, region, cloudProvider string) string {
104-
return fmt.Sprintf(`
105-
resource "mongodbatlas_stream_workspace" "test" {
106-
project_id = %[1]q
107-
workspace_name = %[2]q
108-
data_process_region = {
109-
region = %[3]q
110-
cloud_provider = %[4]q
111-
}
112-
}
113-
`, projectID, workspaceName, region, cloudProvider)
114-
}
115-
116-
func streamsWorkspaceConfigWithStreamConfig(projectID, workspaceName, region, cloudProvider string) string {
117106
return fmt.Sprintf(`
118107
resource "mongodbatlas_stream_workspace" "test" {
119108
project_id = %[1]q
@@ -123,7 +112,8 @@ func streamsWorkspaceConfigWithStreamConfig(projectID, workspaceName, region, cl
123112
cloud_provider = %[4]q
124113
}
125114
stream_config = {
126-
tier = "SP30"
115+
max_tier_size = "SP30"
116+
tier = "SP10"
127117
}
128118
}
129119
`, projectID, workspaceName, region, cloudProvider)

0 commit comments

Comments
 (0)