Skip to content

Commit 224cc75

Browse files
committed
Add support for IPv6 to DocumentDB
This adds a network_type argument to resource/aws_docdb_cluster and a supported_network_types attribute to resource/aws_docdb_subnet_group.
1 parent 8a36c64 commit 224cc75

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

internal/service/docdb/cluster.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ func resourceCluster() *schema.Resource {
236236
Computed: true,
237237
ForceNew: true,
238238
},
239+
"network_type": {
240+
Type: schema.TypeString,
241+
Optional: true,
242+
Computed: true,
243+
ValidateFunc: validation.StringInSlice(networkType_Values(), false),
244+
},
239245
names.AttrPort: {
240246
Type: schema.TypeInt,
241247
Optional: true,
@@ -486,6 +492,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta any
486492
requiresModifyDbCluster = true
487493
}
488494

495+
if v, ok := d.GetOk("network_type"); ok {
496+
input.NetworkType = aws.String(v.(string))
497+
}
498+
489499
if v, ok := d.GetOk(names.AttrPort); ok {
490500
input.Port = aws.Int32(int32(v.(int)))
491501
}
@@ -557,6 +567,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta any
557567
input.KmsKeyId = aws.String(v.(string))
558568
}
559569

570+
if v, ok := d.GetOk("network_type"); ok {
571+
input.NetworkType = aws.String(v.(string))
572+
}
573+
560574
if v, ok := d.GetOk(names.AttrPort); ok {
561575
input.Port = aws.Int32(int32(v.(int)))
562576
}
@@ -649,6 +663,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta any
649663
}
650664
}
651665

666+
if v, ok := d.GetOk("network_type"); ok {
667+
input.NetworkType = aws.String(v.(string))
668+
}
669+
652670
if v, ok := d.GetOk(names.AttrPort); ok {
653671
input.Port = aws.Int32(int32(v.(int)))
654672
}
@@ -768,6 +786,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta any)
768786
d.Set("master_user_secret", nil)
769787
}
770788
d.Set("master_username", dbc.MasterUsername)
789+
d.Set("network_type", dbc.NetworkType)
771790
d.Set(names.AttrPort, dbc.Port)
772791
d.Set("preferred_backup_window", dbc.PreferredBackupWindow)
773792
d.Set(names.AttrPreferredMaintenanceWindow, dbc.PreferredMaintenanceWindow)

internal/service/docdb/cluster_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ func TestAccDocDBCluster_basic(t *testing.T) {
106106
})
107107
}
108108

109+
func TestAccRDSInstance_networkType(t *testing.T) {
110+
ctx := acctest.Context(t)
111+
var dbCluster awstypes.DBCluster
112+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
113+
resourceName := "aws_docdb_cluster.test"
114+
115+
resource.ParallelTest(t, resource.TestCase{
116+
PreCheck: func() { acctest.PreCheck(ctx, t) },
117+
ErrorCheck: acctest.ErrorCheck(t, names.DocDBServiceID),
118+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
119+
CheckDestroy: testAccCheckClusterDestroy(ctx),
120+
Steps: []resource.TestStep{
121+
{
122+
Config: testAccClusterConfig_networkType(rName, "IPV4"),
123+
Check: resource.ComposeAggregateTestCheckFunc(
124+
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
125+
resource.TestCheckResourceAttr(resourceName, "network_type", "IPV4"),
126+
),
127+
},
128+
{
129+
Config: testAccInstanceConfig_networkType(rName, "DUAL"),
130+
Check: resource.ComposeAggregateTestCheckFunc(
131+
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
132+
resource.TestCheckResourceAttr(resourceName, "network_type", "DUAL"),
133+
),
134+
},
135+
},
136+
})
137+
}
138+
109139
func TestAccDocDBCluster_disappears(t *testing.T) {
110140
ctx := acctest.Context(t)
111141
var v awstypes.DBCluster
@@ -1733,6 +1763,29 @@ resource "aws_docdb_cluster" "test" {
17331763
`, rName, passwordConfig))
17341764
}
17351765

1766+
func testAccClusterConfig_networkType(rName string, networkType string) string {
1767+
return acctest.ConfigCompose(
1768+
acctest.ConfigRandomPassword(),
1769+
testAccInstanceConfig_orderableClassMySQL(),
1770+
acctest.ConfigVPCWithSubnetsIPv6(rName, 2),
1771+
fmt.Sprintf(`
1772+
resource "aws_docdb_subnet_group" "test" {
1773+
name = %[1]q
1774+
subnet_ids = aws_subnet.test[*].id
1775+
}
1776+
1777+
resource "aws_docdb_cluster" "test" {
1778+
cluster_identifier = %[1]q
1779+
db_subnet_group_name = aws_docdb_subnet_group.test.name
1780+
master_password = "avoid-plaintext-passwords"
1781+
master_username = "tfacctest"
1782+
skip_final_snapshot = true
1783+
network_type = %[2]q
1784+
apply_immediately = true
1785+
}
1786+
`, rName, networkType))
1787+
}
1788+
17361789
func testAccClusterConfig_serverless(rName string, minCapacity, maxCapacity float64) string {
17371790
return acctest.ConfigCompose(fmt.Sprintf(`
17381791
resource "aws_docdb_cluster" "test" {

internal/service/docdb/consts.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ const (
5858
globalClusterStatusUpgrading = "upgrading"
5959
)
6060

61+
const (
62+
networkTypeDual = "DUAL"
63+
networkTypeIPv4 = "IPV4"
64+
)
65+
66+
func networkType_Values() []string {
67+
return []string{
68+
networkTypeDual,
69+
networkTypeIPv4,
70+
}
71+
}
72+
6173
const (
6274
storageTypeIOpt1 = "iopt1"
6375
storageTypeStandard = "standard"

internal/service/docdb/subnet_group.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func resourceSubnetGroup() *schema.Resource {
6969
MinItems: 1,
7070
Elem: &schema.Schema{Type: schema.TypeString},
7171
},
72+
"supported_network_types": {
73+
Type: schema.TypeSet,
74+
Computed: true,
75+
Elem: &schema.Schema{Type: schema.TypeString},
76+
},
7277
names.AttrTags: tftags.TagsSchema(),
7378
names.AttrTagsAll: tftags.TagsSchemaComputed(),
7479
},
@@ -123,6 +128,7 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta a
123128
subnetIDs = append(subnetIDs, aws.ToString(v.SubnetIdentifier))
124129
}
125130
d.Set(names.AttrSubnetIDs, subnetIDs)
131+
d.Set("supported_network_types", subnetGroup.SupportedNetworkTypes)
126132

127133
return diags
128134
}

internal/service/docdb/subnet_group_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func TestAccDocDBSubnetGroup_basic(t *testing.T) {
4141
resource.TestCheckResourceAttrPair(resourceName, names.AttrID, resourceName, names.AttrName),
4242
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
4343
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "2"),
44+
resource.TestCheckResourceAttr(resourceName, "supported_network_types.#", "1"),
45+
resource.TestCheckTypeSetElemAttr(resourceName, "supported_network_types.*", "IPV4"),
4446
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
4547
),
4648
},
@@ -251,6 +253,32 @@ func TestAccDocDBSubnetGroup_tags(t *testing.T) {
251253
})
252254
}
253255

256+
func TestAccRDSSubnetGroup_dualStack(t *testing.T) {
257+
ctx := acctest.Context(t)
258+
var v awstypes.DBSubnetGroup
259+
260+
resourceName := "aws_docdb_subnet_group.test"
261+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
262+
263+
resource.ParallelTest(t, resource.TestCase{
264+
PreCheck: func() { acctest.PreCheck(ctx, t) },
265+
ErrorCheck: acctest.ErrorCheck(t, names.DocDBServiceID),
266+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
267+
CheckDestroy: testAccCheckSubnetGroupDestroy(ctx),
268+
Steps: []resource.TestStep{
269+
{
270+
Config: testAccSubnetGroupConfig_dualStack(rName),
271+
Check: resource.ComposeTestCheckFunc(
272+
testAccCheckSubnetGroupExists(ctx, resourceName, &v),
273+
resource.TestCheckResourceAttr(resourceName, "supported_network_types.#", "2"),
274+
resource.TestCheckTypeSetElemAttr(resourceName, "supported_network_types.*", "IPV4"),
275+
resource.TestCheckTypeSetElemAttr(resourceName, "supported_network_types.*", "DUAL"),
276+
),
277+
},
278+
},
279+
})
280+
}
281+
254282
func testAccCheckSubnetGroupDestroy(ctx context.Context) resource.TestCheckFunc {
255283
return func(s *terraform.State) error {
256284
conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx)
@@ -369,3 +397,12 @@ resource "aws_docdb_subnet_group" "test" {
369397
}
370398
`, rName, tagKey1, tagValue1, tagKey2, tagValue2))
371399
}
400+
401+
func testAccSubnetGroupConfig_dualStack(rName string) string {
402+
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnetsIPv6(rName, 2), fmt.Sprintf(`
403+
resource "aws_docdb_subnet_group" "test" {
404+
name = %[1]q
405+
subnet_ids = aws_subnet.test[*].id
406+
}
407+
`, rName))
408+
}

0 commit comments

Comments
 (0)