Skip to content

Commit a08e34d

Browse files
pryan-ryangregito
authored andcommitted
allow subnetIds in Instance Group Definition
1 parent 4d34980 commit a08e34d

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

docs/resources/datahub_aws_cluster.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ Optional:
324324

325325
- `availability_zones` (Set of String) The set of availability zones that are going to be used for cluster creation on the given instance group.
326326
- `recipes` (Set of String) The set of recipe names that are going to be applied on the given instance group.
327+
- `subnet_ids` (Set of String) The set of subnet ids that are going to be applied on the given instance group in case of multi-availability zone setup
327328

328329
<a id="nestedatt--instance_group--attached_volume_configuration"></a>
329330
### Nested Schema for `instance_group.attached_volume_configuration`

resources/datahub/common_schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ var instanceGroupSchemaAttributes = map[string]schema.Attribute{
160160
ElementType: types.StringType,
161161
Optional: true,
162162
},
163+
"subnet_ids": schema.SetAttribute{
164+
MarkdownDescription: "The set of subnet ids that are going to be applied on the given instance group in case of multi-availability zone setup",
165+
ElementType: types.StringType,
166+
Optional: true,
167+
},
163168
"availability_zones": schema.SetAttribute{
164169
MarkdownDescription: "The set of availability zones that are going to be used for cluster creation on the given instance group.",
165170
ElementType: types.StringType,

resources/datahub/converter.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,26 @@ func fromModelToAwsRequest(model awsDatahubResourceModel, ctx context.Context) *
3939
tflog.Debug(ctx, fmt.Sprintf("Converting AttachedVolumeConfiguration: %+v.", vrs))
4040
volReqs = append(volReqs, createAttachedVolumeRequest(vrs))
4141
}
42+
var igRecipes []string
43+
if len(group.Recipes) > 0 {
44+
for _, recipe := range group.Recipes {
45+
igRecipes = append(igRecipes, recipe.ValueString())
46+
}
47+
}
48+
var igSubnetIds []string
49+
if len(group.SubnetIds) > 0 {
50+
for _, subnetId := range group.SubnetIds {
51+
igSubnetIds = append(igSubnetIds, subnetId.ValueString())
52+
}
53+
}
4254
ig := &datahubmodels.InstanceGroupRequest{
4355
AttachedVolumeConfiguration: volReqs,
4456
InstanceGroupName: group.InstanceGroupName.ValueStringPointer(),
4557
InstanceGroupType: group.InstanceGroupType.ValueStringPointer(),
4658
InstanceType: group.InstanceType.ValueStringPointer(),
4759
NodeCount: group.NodeCount.ValueInt32Pointer(),
48-
RecipeNames: utils.StringArrayToSlice(group.Recipes),
60+
RecipeNames: igRecipes,
61+
SubnetIds: igSubnetIds,
4962
RecoveryMode: group.RecoveryMode.ValueString(),
5063
RootVolumeSize: group.RootVolumeSize.ValueInt32(),
5164
VolumeEncryption: &datahubmodels.VolumeEncryptionRequest{

resources/datahub/converter_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ func TestFromModelToRequestRecipe(t *testing.T) {
9696
}
9797
}
9898

99+
func TestFromModelToRequestSubnetId(t *testing.T) {
100+
subnetIds := []types.String{types.StringValue("subnet1"), types.StringValue("subnet2")}
101+
igs := []InstanceGroup{{SubnetIds: subnetIds}}
102+
input := awsDatahubResourceModel{InstanceGroup: igs}
103+
104+
got := fromModelToAwsRequest(input, context.TODO())
105+
test.CompareInts(len(got.InstanceGroups), len(input.InstanceGroup), t)
106+
test.CompareInts(len(got.InstanceGroups[0].SubnetIds), len(input.InstanceGroup[0].SubnetIds), t)
107+
108+
for _, convertedSubnetId := range got.InstanceGroups[0].SubnetIds {
109+
var contains bool
110+
for _, originalSubnetId := range input.InstanceGroup[0].SubnetIds {
111+
if originalSubnetId.ValueString() == convertedSubnetId {
112+
contains = true
113+
}
114+
}
115+
if !contains {
116+
t.Errorf("Instance group does not contain subnetId: %s", convertedSubnetId)
117+
}
118+
}
119+
}
99120
func TestFromModelToRequestAttachedVolumeConfiguration(t *testing.T) {
100121
avcs := []AttachedVolumeConfiguration{{
101122
VolumeSize: types.Int32Value(100),

resources/datahub/model_datahub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type InstanceGroup struct {
2424
RecoveryMode types.String `tfsdk:"recovery_mode"`
2525
VolumeEncryption VolumeEncryption `tfsdk:"volume_encryption"`
2626
Recipes []types.String `tfsdk:"recipes"`
27+
SubnetIds []types.String `tfsdk:"subnet_ids"`
2728
AvailabilityZones []types.String `tfsdk:"availability_zones"`
2829
}
2930

0 commit comments

Comments
 (0)