Skip to content

Commit e2afe00

Browse files
authored
Merge pull request #38456 from acwwat/f-aws_opensearch_domain-add_endpoint_v2_attrs
feat: Add attrs related to endpoint v2 for aws_opensearch_domain
2 parents e9713db + 6ae0eff commit e2afe00

File tree

6 files changed

+189
-18
lines changed

6 files changed

+189
-18
lines changed

.changelog/38456.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_opensearch_domain: Add `dashboard_endpoint_v2`, `domain_endpoint_v2_hosted_zone_id`, and `endpoint_v2` attributes
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_opensearch_domain: Add `dashboard_endpoint_v2`, `domain_endpoint_v2_hosted_zone_id`, and `endpoint_v2` attributes
7+
```

internal/service/opensearch/domain.go

+32-8
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ func resourceDomain() *schema.Resource {
354354
Type: schema.TypeString,
355355
Computed: true,
356356
},
357+
"dashboard_endpoint_v2": {
358+
Type: schema.TypeString,
359+
Computed: true,
360+
},
357361
"domain_endpoint_options": {
358362
Type: schema.TypeList,
359363
Optional: true,
@@ -391,6 +395,10 @@ func resourceDomain() *schema.Resource {
391395
},
392396
},
393397
},
398+
"domain_endpoint_v2_hosted_zone_id": {
399+
Type: schema.TypeString,
400+
Computed: true,
401+
},
394402
"domain_id": {
395403
Type: schema.TypeString,
396404
Computed: true,
@@ -463,6 +471,10 @@ func resourceDomain() *schema.Resource {
463471
Type: schema.TypeString,
464472
Computed: true,
465473
},
474+
"endpoint_v2": {
475+
Type: schema.TypeString,
476+
Computed: true,
477+
},
466478
names.AttrEngineVersion: {
467479
Type: schema.TypeString,
468480
Optional: true,
@@ -863,6 +875,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
863875

864876
d.SetId(aws.ToString(ds.ARN))
865877
d.Set(names.AttrARN, ds.ARN)
878+
d.Set("domain_endpoint_v2_hosted_zone_id", ds.DomainEndpointV2HostedZoneId)
866879
d.Set("domain_id", ds.DomainId)
867880
d.Set(names.AttrDomainName, ds.DomainName)
868881
d.Set(names.AttrEngineVersion, ds.EngineVersion)
@@ -922,16 +935,27 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
922935

923936
endpoints := flex.FlattenStringValueMap(ds.Endpoints)
924937
d.Set(names.AttrEndpoint, endpoints["vpc"])
925-
d.Set("dashboard_endpoint", getDashboardEndpoint(d))
926-
d.Set("kibana_endpoint", getKibanaEndpoint(d))
938+
d.Set("dashboard_endpoint", getDashboardEndpoint(d.Get(names.AttrEndpoint).(string)))
939+
d.Set("kibana_endpoint", getKibanaEndpoint(d.Get(names.AttrEndpoint).(string)))
940+
if endpoints["vpcv2"] != nil {
941+
d.Set("endpoint_v2", endpoints["vpcv2"])
942+
d.Set("dashboard_endpoint_v2", getDashboardEndpoint(d.Get("endpoint_v2").(string)))
943+
}
927944
if ds.Endpoint != nil {
928945
return sdkdiag.AppendErrorf(diags, "%q: OpenSearch Domain in VPC expected to have null Endpoint value", d.Id())
929946
}
947+
if ds.EndpointV2 != nil {
948+
return sdkdiag.AppendErrorf(diags, "%q: OpenSearch Domain in VPC expected to have null EndpointV2 value", d.Id())
949+
}
930950
} else {
931951
if ds.Endpoint != nil {
932952
d.Set(names.AttrEndpoint, ds.Endpoint)
933-
d.Set("dashboard_endpoint", getDashboardEndpoint(d))
934-
d.Set("kibana_endpoint", getKibanaEndpoint(d))
953+
d.Set("dashboard_endpoint", getDashboardEndpoint(d.Get(names.AttrEndpoint).(string)))
954+
d.Set("kibana_endpoint", getKibanaEndpoint(d.Get(names.AttrEndpoint).(string)))
955+
}
956+
if ds.EndpointV2 != nil {
957+
d.Set("endpoint_v2", ds.EndpointV2)
958+
d.Set("dashboard_endpoint_v2", getDashboardEndpoint(d.Get("endpoint_v2").(string)))
935959
}
936960
if ds.Endpoints != nil {
937961
return sdkdiag.AppendErrorf(diags, "%q: OpenSearch Domain not in VPC expected to have null Endpoints value", d.Id())
@@ -1197,12 +1221,12 @@ func suppressEquivalentKMSKeyIDs(k, old, new string, d *schema.ResourceData) boo
11971221
return strings.Contains(old, new)
11981222
}
11991223

1200-
func getDashboardEndpoint(d *schema.ResourceData) string {
1201-
return d.Get(names.AttrEndpoint).(string) + "/_dashboards"
1224+
func getDashboardEndpoint(endpoint string) string {
1225+
return endpoint + "/_dashboards"
12021226
}
12031227

1204-
func getKibanaEndpoint(d *schema.ResourceData) string {
1205-
return d.Get(names.AttrEndpoint).(string) + "/_plugin/kibana/"
1228+
func getKibanaEndpoint(endpoint string) string {
1229+
return endpoint + "/_plugin/kibana/"
12061230
}
12071231

12081232
func suppressComputedDedicatedMaster(k, old, new string, d *schema.ResourceData) bool {

internal/service/opensearch/domain_data_source.go

+30-6
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,18 @@ func dataSourceDomain() *schema.Resource {
213213
Type: schema.TypeString,
214214
Computed: true,
215215
},
216+
"dashboard_endpoint_v2": {
217+
Type: schema.TypeString,
218+
Computed: true,
219+
},
216220
"deleted": {
217221
Type: schema.TypeBool,
218222
Computed: true,
219223
},
224+
"domain_endpoint_v2_hosted_zone_id": {
225+
Type: schema.TypeString,
226+
Computed: true,
227+
},
220228
"domain_id": {
221229
Type: schema.TypeString,
222230
Computed: true,
@@ -273,6 +281,10 @@ func dataSourceDomain() *schema.Resource {
273281
Type: schema.TypeString,
274282
Computed: true,
275283
},
284+
"endpoint_v2": {
285+
Type: schema.TypeString,
286+
Computed: true,
287+
},
276288
names.AttrEngineVersion: {
277289
Type: schema.TypeString,
278290
Computed: true,
@@ -455,10 +467,11 @@ func dataSourceDomainRead(ctx context.Context, d *schema.ResourceData, meta inte
455467
}
456468

457469
d.Set(names.AttrARN, ds.ARN)
470+
d.Set("domain_endpoint_v2_hosted_zone_id", ds.DomainEndpointV2HostedZoneId)
458471
d.Set("domain_id", ds.DomainId)
459472
d.Set(names.AttrEndpoint, ds.Endpoint)
460-
d.Set("dashboard_endpoint", getDashboardEndpoint(d))
461-
d.Set("kibana_endpoint", getKibanaEndpoint(d))
473+
d.Set("dashboard_endpoint", getDashboardEndpoint(d.Get(names.AttrEndpoint).(string)))
474+
d.Set("kibana_endpoint", getKibanaEndpoint(d.Get(names.AttrEndpoint).(string)))
462475

463476
if err := d.Set("advanced_security_options", flattenAdvancedSecurityOptions(ds.AdvancedSecurityOptions)); err != nil {
464477
return sdkdiag.AppendErrorf(diags, "setting advanced_security_options: %s", err)
@@ -503,16 +516,27 @@ func dataSourceDomainRead(ctx context.Context, d *schema.ResourceData, meta inte
503516
if err := d.Set(names.AttrEndpoint, endpoints["vpc"]); err != nil {
504517
return sdkdiag.AppendErrorf(diags, "setting endpoint: %s", err)
505518
}
506-
d.Set("dashboard_endpoint", getDashboardEndpoint(d))
507-
d.Set("kibana_endpoint", getKibanaEndpoint(d))
519+
d.Set("dashboard_endpoint", getDashboardEndpoint(d.Get(names.AttrEndpoint).(string)))
520+
d.Set("kibana_endpoint", getKibanaEndpoint(d.Get(names.AttrEndpoint).(string)))
521+
if endpoints["vpcv2"] != nil {
522+
d.Set("endpoint_v2", endpoints["vpcv2"])
523+
d.Set("dashboard_endpoint_v2", getDashboardEndpoint(d.Get("endpoint_v2").(string)))
524+
}
508525
if ds.Endpoint != nil {
509526
return sdkdiag.AppendErrorf(diags, "%q: OpenSearch domain in VPC expected to have null Endpoint value", d.Id())
510527
}
528+
if ds.EndpointV2 != nil {
529+
return sdkdiag.AppendErrorf(diags, "%q: OpenSearch Domain in VPC expected to have null EndpointV2 value", d.Id())
530+
}
511531
} else {
512532
if ds.Endpoint != nil {
513533
d.Set(names.AttrEndpoint, ds.Endpoint)
514-
d.Set("dashboard_endpoint", getDashboardEndpoint(d))
515-
d.Set("kibana_endpoint", getKibanaEndpoint(d))
534+
d.Set("dashboard_endpoint", getDashboardEndpoint(d.Get(names.AttrEndpoint).(string)))
535+
d.Set("kibana_endpoint", getKibanaEndpoint(d.Get(names.AttrEndpoint).(string)))
536+
}
537+
if ds.EndpointV2 != nil {
538+
d.Set("endpoint_v2", ds.EndpointV2)
539+
d.Set("dashboard_endpoint_v2", getDashboardEndpoint(d.Get("endpoint_v2").(string)))
516540
}
517541
if ds.Endpoints != nil {
518542
return sdkdiag.AppendErrorf(diags, "%q: OpenSearch domain not in VPC expected to have null Endpoints value", d.Id())

internal/service/opensearch/domain_test.go

+114-4
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,50 @@ func TestAccOpenSearchDomain_VPC_internetToVPCEndpoint(t *testing.T) {
764764
})
765765
}
766766

767+
func TestAccOpenSearchDomain_VPC_ipAddressType(t *testing.T) {
768+
ctx := acctest.Context(t)
769+
if testing.Short() {
770+
t.Skip("skipping long-running test in short mode")
771+
}
772+
773+
var domain awstypes.DomainStatus
774+
rName := testAccRandomDomainName()
775+
resourceName := "aws_opensearch_domain.test"
776+
777+
resource.ParallelTest(t, resource.TestCase{
778+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIAMServiceLinkedRole(ctx, t) },
779+
ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServiceID),
780+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
781+
CheckDestroy: testAccCheckDomainDestroy(ctx),
782+
Steps: []resource.TestStep{
783+
{
784+
Config: testAccDomainConfig_vpcIPAddressType(rName, "dualstack"),
785+
Check: resource.ComposeTestCheckFunc(
786+
testAccCheckDomainExists(ctx, resourceName, &domain),
787+
resource.TestMatchResourceAttr(resourceName, "dashboard_endpoint_v2", regexache.MustCompile(`.+?\.on\.aws\/_dashboards`)),
788+
resource.TestMatchResourceAttr(resourceName, "endpoint_v2", regexache.MustCompile(`.+?\.on\.aws`)),
789+
resource.TestCheckResourceAttr(resourceName, names.AttrIPAddressType, "dualstack"),
790+
),
791+
},
792+
{
793+
ResourceName: resourceName,
794+
ImportState: true,
795+
ImportStateId: rName,
796+
ImportStateVerify: true,
797+
},
798+
{
799+
Config: testAccDomainConfig_vpcIPAddressType(rName, "ipv4"),
800+
Check: resource.ComposeTestCheckFunc(
801+
testAccCheckDomainExists(ctx, resourceName, &domain),
802+
resource.TestCheckNoResourceAttr(resourceName, "dashboard_endpoint_v2"),
803+
resource.TestCheckNoResourceAttr(resourceName, "endpoint_v2"),
804+
resource.TestCheckResourceAttr(resourceName, names.AttrIPAddressType, "ipv4"),
805+
),
806+
},
807+
},
808+
})
809+
}
810+
767811
func TestAccOpenSearchDomain_ipAddressType(t *testing.T) {
768812
ctx := acctest.Context(t)
769813
if testing.Short() {
@@ -784,8 +828,8 @@ func TestAccOpenSearchDomain_ipAddressType(t *testing.T) {
784828
Config: testAccDomainConfig_ipAddressType(rName, "dualstack"),
785829
Check: resource.ComposeTestCheckFunc(
786830
testAccCheckDomainExists(ctx, resourceName, &domain),
787-
resource.TestMatchResourceAttr(resourceName, "dashboard_endpoint", regexache.MustCompile(`.*(opensearch|es)\..*/_dashboards`)),
788-
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngineVersion),
831+
resource.TestMatchResourceAttr(resourceName, "dashboard_endpoint_v2", regexache.MustCompile(`.+?\.on\.aws\/_dashboards`)),
832+
resource.TestMatchResourceAttr(resourceName, "endpoint_v2", regexache.MustCompile(`.+?\.on\.aws`)),
789833
resource.TestCheckResourceAttr(resourceName, names.AttrIPAddressType, "dualstack"),
790834
),
791835
},
@@ -799,8 +843,8 @@ func TestAccOpenSearchDomain_ipAddressType(t *testing.T) {
799843
Config: testAccDomainConfig_ipAddressType(rName, "ipv4"),
800844
Check: resource.ComposeTestCheckFunc(
801845
testAccCheckDomainExists(ctx, resourceName, &domain),
802-
resource.TestMatchResourceAttr(resourceName, "dashboard_endpoint", regexache.MustCompile(`.*(opensearch|es)\..*/_dashboards`)),
803-
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngineVersion),
846+
resource.TestCheckNoResourceAttr(resourceName, "dashboard_endpoint_v2"),
847+
resource.TestCheckNoResourceAttr(resourceName, "endpoint_v2"),
804848
resource.TestCheckResourceAttr(resourceName, names.AttrIPAddressType, "ipv4"),
805849
),
806850
},
@@ -3138,6 +3182,72 @@ resource "aws_opensearch_domain" "test" {
31383182
`, rName))
31393183
}
31403184

3185+
func testAccDomainConfig_vpcIPAddressType(rName, ipAddressType string) string {
3186+
return acctest.ConfigCompose(
3187+
acctest.ConfigAvailableAZsNoOptIn(),
3188+
fmt.Sprintf(`
3189+
resource "aws_vpc" "test" {
3190+
cidr_block = "192.168.0.0/22"
3191+
assign_generated_ipv6_cidr_block = true
3192+
3193+
tags = {
3194+
Name = %[1]q
3195+
}
3196+
}
3197+
3198+
resource "aws_subnet" "test" {
3199+
vpc_id = aws_vpc.test.id
3200+
availability_zone = data.aws_availability_zones.available.names[0]
3201+
cidr_block = "192.168.0.0/24"
3202+
ipv6_cidr_block = cidrsubnet(aws_vpc.test.ipv6_cidr_block, 4, 0)
3203+
3204+
tags = {
3205+
Name = %[1]q
3206+
}
3207+
}
3208+
3209+
resource "aws_subnet" "test2" {
3210+
vpc_id = aws_vpc.test.id
3211+
availability_zone = data.aws_availability_zones.available.names[1]
3212+
cidr_block = "192.168.1.0/24"
3213+
ipv6_cidr_block = cidrsubnet(aws_vpc.test.ipv6_cidr_block, 4, 1)
3214+
3215+
tags = {
3216+
Name = %[1]q
3217+
}
3218+
}
3219+
3220+
resource "aws_security_group" "test" {
3221+
vpc_id = aws_vpc.test.id
3222+
}
3223+
3224+
resource "aws_security_group" "test2" {
3225+
vpc_id = aws_vpc.test.id
3226+
}
3227+
3228+
resource "aws_opensearch_domain" "test" {
3229+
domain_name = %[1]q
3230+
ip_address_type = %[2]q
3231+
3232+
ebs_options {
3233+
ebs_enabled = true
3234+
volume_size = 10
3235+
}
3236+
3237+
cluster_config {
3238+
instance_count = 2
3239+
zone_awareness_enabled = true
3240+
instance_type = "t2.small.search"
3241+
}
3242+
3243+
vpc_options {
3244+
security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id]
3245+
subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id]
3246+
}
3247+
}
3248+
`, rName, ipAddressType))
3249+
}
3250+
31413251
func testAccDomainConfig_vpcUpdate1(rName string) string {
31423252
return acctest.ConfigCompose(
31433253
acctest.ConfigAvailableAZsNoOptIn(),

website/docs/d/opensearch_domain.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ This data source exports the following attributes in addition to the arguments a
6666
* `role_arn` - IAM Role with the AmazonOpenSearchServiceCognitoAccess policy attached.
6767
* `created` – Status of the creation of the domain.
6868
* `dashboard_endpoint` - Domain-specific endpoint used to access the [Dashboard application](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/dashboards.html).
69+
* `dashboard_endpoint_v2` - V2 domain-specific endpoint used to access the [Dashboard application](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/dashboards.html)
6970
* `deleted` – Status of the deletion of the domain.
71+
* `domain_endpoint_v2_hosted_zone_id` - Dual stack hosted zone ID for the domain.
7072
* `domain_id` – Unique identifier for the domain.
7173
* `ebs_options` - EBS Options for the instances in the domain.
7274
* `ebs_enabled` - Whether EBS volumes are attached to data nodes in the domain.
@@ -79,6 +81,7 @@ This data source exports the following attributes in addition to the arguments a
7981
* `enabled` - Whether encryption at rest is enabled in the domain.
8082
* `kms_key_id` - KMS key id used to encrypt data at rest.
8183
* `endpoint` – Domain-specific endpoint used to submit index, search, and data upload requests.
84+
* `endpoint_v2` - V2 domain-specific endpoint that works with both IPv4 and IPv6 addresses, used to submit index, search, and data upload requests.
8285
* `ip_address_type` - Type of IP addresses supported by the endpoint for the domain.
8386
* `kibana_endpoint` - (**Deprecated**) Domain-specific endpoint for kibana without https scheme. Use the `dashboard_endpoint` attribute instead.
8487
* `log_publishing_options` - Domain log publishing related options.

website/docs/r/opensearch_domain.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,13 @@ AWS documentation: [Off Peak Hours Support for Amazon OpenSearch Service Domains
475475
This resource exports the following attributes in addition to the arguments above:
476476

477477
* `arn` - ARN of the domain.
478+
* `domain_endpoint_v2_hosted_zone_id` - Dual stack hosted zone ID for the domain.
478479
* `domain_id` - Unique identifier for the domain.
479480
* `domain_name` - Name of the OpenSearch domain.
480481
* `endpoint` - Domain-specific endpoint used to submit index, search, and data upload requests.
482+
* `endpoint_v2` - V2 domain endpoint that works with both IPv4 and IPv6 addresses, used to submit index, search, and data upload requests.
481483
* `dashboard_endpoint` - Domain-specific endpoint for Dashboard without https scheme.
484+
* `dashboard_endpoint_v2` - V2 domain endpoint for Dashboard that works with both IPv4 and IPv6 addresses, without https scheme.
482485
* `kibana_endpoint` - (**Deprecated**) Domain-specific endpoint for kibana without https scheme. Use the `dashboard_endpoint` attribute instead.
483486
* `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).
484487
* `vpc_options.0.availability_zones` - If the domain was created inside a VPC, the names of the availability zones the configured `subnet_ids` were created inside.

0 commit comments

Comments
 (0)