From 48337faed244a7d1b0e61e44f2b0f6c0a3ae6688 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Mon, 10 Jul 2023 10:35:58 +0100 Subject: [PATCH 01/46] implemented new resource aws opensearch vpc endpoint connection --- .../service/opensearch/service_package_gen.go | 4 + .../opensearch/vpc_endpoint_connection.go | 264 ++++++++++++++++++ .../vpc_endpoint_connection_test.go | 256 +++++++++++++++++ 3 files changed, 524 insertions(+) create mode 100644 internal/service/opensearch/vpc_endpoint_connection.go create mode 100644 internal/service/opensearch/vpc_endpoint_connection_test.go diff --git a/internal/service/opensearch/service_package_gen.go b/internal/service/opensearch/service_package_gen.go index 96f66fa6e58a..213140cd6909 100644 --- a/internal/service/opensearch/service_package_gen.go +++ b/internal/service/opensearch/service_package_gen.go @@ -58,6 +58,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka Factory: ResourceOutboundConnection, TypeName: "aws_opensearch_outbound_connection", }, + { + Factory: ResourceVPCEndpoint, + TypeName: "aws_opensearch_vpc_endpoint_connection", + }, } } diff --git a/internal/service/opensearch/vpc_endpoint_connection.go b/internal/service/opensearch/vpc_endpoint_connection.go new file mode 100644 index 000000000000..f4ef713deda3 --- /dev/null +++ b/internal/service/opensearch/vpc_endpoint_connection.go @@ -0,0 +1,264 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package opensearch + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/opensearchservice" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/verify" +) + +// @SDKResource("aws_opensearch_vpc_endpoint_connection") +func ResourceVPCEndpoint() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceVPCEndpointCreate, + ReadWithoutTimeout: resourceVPCEndpointRead, + UpdateWithoutTimeout: resourceVPCEndpointPut, + DeleteWithoutTimeout: resourceVPCEndpointDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(60 * time.Minute), + Update: schema.DefaultTimeout(60 * time.Minute), + Delete: schema.DefaultTimeout(90 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "domain_arn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: verify.ValidARN, + }, + "vpc_options": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "availability_zones": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + "security_group_ids": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + "subnet_ids": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + "vpc_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "connection_status": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) + + // Create the VPC Endpoint + input := &opensearchservice.CreateVpcEndpointInput{ + DomainArn: aws.String(d.Get("domain_arn").(string)), + } + + if v, ok := d.GetOk("vpc_options"); ok { + options := v.([]interface{}) + if options[0] == nil { + return sdkdiag.AppendErrorf(diags, "At least one field is expected inside vpc_options") + } + + s := options[0].(map[string]interface{}) + input.VpcOptions = expandVPCOptions(s) + } + + log.Printf("[DEBUG] Create VPC Endpoint options: %#v", input) + + resp, err := conn.CreateVpcEndpointWithContext(ctx, input) + if err != nil { + return diag.Errorf("creating vpc endpoint : %s", err) + } + + // Get the ID and store it + d.SetId(aws.StringValue(resp.VpcEndpoint.VpcEndpointId)) + log.Printf("[INFO] open search vpc endpoint ID: %s", d.Id()) + + err = vpcEndpointConnectionWaitUntilActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) + if err != nil { + return diag.Errorf("waiting for vpc endpoint to become active: %s", err) + } + + return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) +} + +func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) + + endpointRaw, status, err := vpcEndpointConnectionRefreshState(ctx, conn, d.Id())() + + if err != nil { + return diag.Errorf("reading vpc endpoint Connection: %s", err) + } + + endpoint := endpointRaw.(*opensearchservice.VpcEndpoint) + log.Printf("[DEBUG] vpc endpoint Connection response: %#v", endpoint) + + d.Set("connection_status", status) + d.Set("domain_arn", endpoint.DomainArn) + + if endpoint.VpcOptions == nil { + return diag.Errorf("reading vpc endpoint Connection vpc options ") + } + + d.Set("vpc_options", flattenVPCDerivedInfo(endpoint.VpcOptions)) + return nil +} + +func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) + + // Update the VPC Endpoint + input := &opensearchservice.UpdateVpcEndpointInput{ + VpcEndpointId: aws.String(d.Id()), + } + + if v, ok := d.GetOk("vpc_options"); ok { + options := v.([]interface{}) + if options[0] == nil { + return sdkdiag.AppendErrorf(diags, "At least one field is expected inside vpc_options") + } + + s := options[0].(map[string]interface{}) + input.VpcOptions = expandVPCOptions(s) + } + + log.Printf("[DEBUG] Updating vpc endpoint Connection %s", input) + + _, err := conn.UpdateVpcEndpointWithContext(ctx, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "updating vpc endpoint Connection (%s): %s", d.Id(), err) + } + + err = vpcEndpointConnectionWaitUntilUpdate(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return diag.Errorf("waiting for vpc endpoint to become active: %s", err) + } + + return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) + +} +func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) + + req := &opensearchservice.DeleteVpcEndpointInput{ + VpcEndpointId: aws.String(d.Id()), + } + + _, err := conn.DeleteVpcEndpointWithContext(ctx, req) + + if tfawserr.ErrCodeEquals(err, "ResourceNotFoundException") { + return nil + } + + if err != nil { + return diag.Errorf("deleting vpc endpoint Connection (%s): %s", d.Id(), err) + } + + return nil +} + +func vpcEndpointConnectionRefreshState(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + resp, err := conn.DescribeVpcEndpointsWithContext(ctx, &opensearchservice.DescribeVpcEndpointsInput{ + VpcEndpointIds: []*string{aws.String(id)}, + }) + if err != nil { + return nil, "", err + } + + if resp == nil || resp.VpcEndpoints == nil || + len(resp.VpcEndpoints) == 0 || resp.VpcEndpoints[0] == nil { + // Sometimes AWS just has consistency issues and doesn't see + // our connection yet. Return an empty state. + return nil, "", nil + } + endpoint := resp.VpcEndpoints[0] + if endpoint.Status == nil { + // Sometimes AWS just has consistency issues and doesn't see + // our connection yet. Return an empty state. + return nil, "", nil + } + statusCode := aws.StringValue(endpoint.Status) + + return endpoint, statusCode, nil + } +} + +func vpcEndpointConnectionWaitUntilActive(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for VPC Endpoint Connection (%s) to become available.", id) + stateConf := &retry.StateChangeConf{ + Pending: []string{ + opensearchservice.VpcEndpointStatusCreating, + }, + Target: []string{ + opensearchservice.VpcEndpointStatusActive, + }, + Refresh: vpcEndpointConnectionRefreshState(ctx, conn, id), + Timeout: timeout, + } + if _, err := stateConf.WaitForStateContext(ctx); err != nil { + return fmt.Errorf("waiting for VPC Endpoint Connection (%s) to become available: %s", id, err) + } + return nil +} + +func vpcEndpointConnectionWaitUntilUpdate(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for VPC Endpoint Connection (%s) to become available.", id) + stateConf := &retry.StateChangeConf{ + Pending: []string{ + opensearchservice.VpcEndpointStatusUpdating, + }, + Target: []string{ + opensearchservice.VpcEndpointStatusActive, + }, + Refresh: vpcEndpointConnectionRefreshState(ctx, conn, id), + Timeout: timeout, + } + if _, err := stateConf.WaitForStateContext(ctx); err != nil { + return fmt.Errorf("waiting for VPC Endpoint Connection (%s) to become available: %s", id, err) + } + return nil +} diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go new file mode 100644 index 000000000000..45d9ac9f92c7 --- /dev/null +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -0,0 +1,256 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package opensearch_test + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/opensearchservice" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + tfopensearch "github.com/hashicorp/terraform-provider-aws/internal/service/opensearch" +) + +func TestAccOpenSearchVPCEndpointConnection_basic(t *testing.T) { + ctx := acctest.Context(t) + var domain opensearchservice.DomainStatus + ri := sdkacctest.RandString(10) + name := fmt.Sprintf("tf-test-%s", ri) + resourceName := "aws_opensearch_vpc_endpoint_connection.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDomainDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCEndpointConnectionConfig(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), + resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { + ctx := acctest.Context(t) + var domain opensearchservice.DomainStatus + ri := sdkacctest.RandString(10) + name := fmt.Sprintf("tf-test-%s", ri) + resourceName := "aws_opensearch_vpc_endpoint_connection.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDomainDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCEndpointConnectionConfig(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), + resource.TestCheckResourceAttr(resourceName, "vpc_options.security_group_ids.#", "1"), + resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), + ), + }, + { + Config: testAccVPCEndpointConnectionConfigUpdate(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), + resource.TestCheckResourceAttr(resourceName, "vpc_options.security_group_ids.#", "2"), + resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { + ctx := acctest.Context(t) + var domain opensearchservice.DomainStatus + ri := sdkacctest.RandString(10) + name := fmt.Sprintf("tf-test-%s", ri) + resourceName := "aws_opensearch_vpc_endpoint_connection.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDomainDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCEndpointConnectionConfig(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfopensearch.ResourceVPCEndpoint(), resourceName), + ), + }, + }, + }) +} + +func testAccVPCEndpointConnectionConfig(name string) string { + // Satisfy the pw requirements + //pw := fmt.Sprintf("Aa1-%s", sdkacctest.RandString(10)) + + return acctest.ConfigCompose( + acctest.ConfigAvailableAZsNoOptIn(), + fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_security_group" "test" { + vpc_id = aws_vpc.test.id +} + +resource "aws_security_group" "test2" { + vpc_id = aws_vpc.test.id +} + +resource "aws_opensearch_domain" "domain_1" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} + +resource "aws_opensearch_vpc_endpoint_connection" "test" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + + } +`, name)) + +} + +func testAccVPCEndpointConnectionConfigUpdate(name string) string { + // Satisfy the pw requirements + //pw := fmt.Sprintf("Aa1-%s", sdkacctest.RandString(10)) + + return acctest.ConfigCompose( + acctest.ConfigAvailableAZsNoOptIn(), + fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_security_group" "test" { + vpc_id = aws_vpc.test.id +} + +resource "aws_security_group" "test2" { + vpc_id = aws_vpc.test.id +} + +resource "aws_opensearch_domain" "domain_1" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} + +resource "aws_opensearch_vpc_endpoint_connection" "test" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + + } +`, name)) + +} From 2db394c9f08579372f2b15ffe20b5105e8c5ad33 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Mon, 10 Jul 2023 11:13:36 +0100 Subject: [PATCH 02/46] added documentation --- .changelog/29912.txt | 3 + .../vpc_endpoint_connection_test.go | 4 +- ...arch_vpc_endpoint_connection.html.markdown | 77 +++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 .changelog/29912.txt create mode 100644 website/docs/r/opensearch_vpc_endpoint_connection.html.markdown diff --git a/.changelog/29912.txt b/.changelog/29912.txt new file mode 100644 index 000000000000..3202e12a1615 --- /dev/null +++ b/.changelog/29912.txt @@ -0,0 +1,3 @@ +```release-note:IsNewResource +resource/aws_opensearch_vpc_endpoint_connection: added a new resource to create vpc endpoint connection for an aws opensearch domain +``` \ No newline at end of file diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 45d9ac9f92c7..528743475af9 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -60,7 +60,7 @@ func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { Config: testAccVPCEndpointConnectionConfig(name), Check: resource.ComposeTestCheckFunc( testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), - resource.TestCheckResourceAttr(resourceName, "vpc_options.security_group_ids.#", "1"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "1"), resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), ), }, @@ -68,7 +68,7 @@ func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { Config: testAccVPCEndpointConnectionConfigUpdate(name), Check: resource.ComposeTestCheckFunc( testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), - resource.TestCheckResourceAttr(resourceName, "vpc_options.security_group_ids.#", "2"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "2"), resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), ), }, diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown new file mode 100644 index 000000000000..0bb0658b482b --- /dev/null +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -0,0 +1,77 @@ +--- +subcategory: "OpenSearch" +layout: "aws" +page_title: "AWS: aws_opensearch_vpc_endpoint_connection" +description: |- + Terraform resource for managing an AWS OpenSearch VPC Endpoint connection. +--- + +# Resource: aws_opensearch_vpc_endpoint_connection + +Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_CreateVpcEndpoint.html). Creates an Amazon OpenSearch Service-managed VPC endpoint.. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_opensearch_domain" "domain_1" { + domain_name = testdomain + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} + +resource "aws_opensearch_vpc_endpoint_connection" "test" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + + } + +``` + +## Argument Reference + +The following arguments are supported: + +* `domain_arn` - (Required, Forces new resource) Specifies the Amazon Resource Name (ARN) of the domain to create the endpoint for +* `vpc_options` - (Optional) Options to specify the subnets and security groups for the endpoint. + +### vpc_options + +* `security_group_ids` - (Optional) The list of security group IDs associated with the VPC endpoints for the domain. If you do not provide a security group ID, OpenSearch Service uses the default security group for the VPC. +* `subnet_ids` - (Optional) A list of subnet IDs associated with the VPC endpoints for the domain. If your domain uses multiple Availability Zones, you need to provide two subnet IDs, one per zone. Otherwise, provide only one. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The connection endpoint ID for connecting to the domain. +* `connection_status` - The current status of the endpoint. + +## Import + +AWS Opensearch VPC Endpoint Connection can be imported by using the VPC Endpoint Connection ID, e.g., + +``` +$ terraform import aws_opensearch_vpc_endpoint_connection.foo endpoint-id +``` From bffccaea6c6b69b523d99a41ef19e7cedcb7a71c Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Mon, 10 Jul 2023 12:57:01 +0100 Subject: [PATCH 03/46] fix format in test file --- internal/service/opensearch/vpc_endpoint_connection_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 528743475af9..b28cc157804f 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -175,7 +175,7 @@ resource "aws_opensearch_vpc_endpoint_connection" "test" { subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - } +} `, name)) } @@ -250,7 +250,7 @@ resource "aws_opensearch_vpc_endpoint_connection" "test" { subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - } +} `, name)) } From d13f8780683f72fef2dadedd498f04aefdf1c00f Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Mon, 10 Jul 2023 13:25:12 +0100 Subject: [PATCH 04/46] fix format in test file --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 0bb0658b482b..7f2dfc89f59d 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -45,7 +45,7 @@ resource "aws_opensearch_vpc_endpoint_connection" "test" { subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - } +} ``` From 14f59a98f17a5e29c0775af196ef4b92962a1662 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 09:41:28 +0100 Subject: [PATCH 05/46] fix website format --- ...arch_vpc_endpoint_connection.html.markdown | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 7f2dfc89f59d..ae9ac440fe5e 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -15,36 +15,13 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ### Basic Usage ```terraform -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_opensearch_domain" "domain_1" { - domain_name = testdomain - - ebs_options { - ebs_enabled = true - volume_size = 10 - } - - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } - - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} resource "aws_opensearch_vpc_endpoint_connection" "test" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - + } } ``` From 473c2486bbb242d8d50dab2aa269913d65a20b35 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 09:48:35 +0100 Subject: [PATCH 06/46] fix website format --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index ae9ac440fe5e..ad1928bf2f68 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -16,7 +16,7 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ```terraform -resource "aws_opensearch_vpc_endpoint_connection" "test" { +resource "aws_opensearch_vpc_endpoint_connection" "foo" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] From 02a3affd54d442a4bbc5ddb52c82c9f583e06291 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 09:53:10 +0100 Subject: [PATCH 07/46] fix website format --- .../r/opensearch_vpc_endpoint_connection.html.markdown | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index ad1928bf2f68..9d1334dea956 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -14,17 +14,7 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ### Basic Usage -```terraform -resource "aws_opensearch_vpc_endpoint_connection" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} - -``` ## Argument Reference From 1cd95fb25cd51116631de12dafe28884c1b2ddc6 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 09:57:53 +0100 Subject: [PATCH 08/46] fix website format --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 9d1334dea956..0b1afadcbc95 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -14,7 +14,7 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ### Basic Usage - +sample code here ## Argument Reference From 573bfd7a4aafd3de61fa5a78c19f29572bfd39e9 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 10:03:41 +0100 Subject: [PATCH 09/46] fix website format --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 0b1afadcbc95..b16f23644118 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -14,7 +14,7 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ### Basic Usage -sample code here +sample code here ## Argument Reference From 843b36b9781e293ad4a532ab634abafcdc5315fc Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 10:11:27 +0100 Subject: [PATCH 10/46] fix website format --- internal/service/opensearch/vpc_endpoint_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index b28cc157804f..962bac63ecc4 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -169,7 +169,7 @@ resource "aws_opensearch_domain" "domain_1" { } resource "aws_opensearch_vpc_endpoint_connection" "test" { - domain_arn = aws_opensearch_domain.domain_1.arn + domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] From ff4cfd5de33875629acb4680e2dc490ecaf60274 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 10:30:34 +0100 Subject: [PATCH 11/46] fix website format --- .../vpc_endpoint_connection_test.go | 256 +++++++++--------- ...arch_vpc_endpoint_connection.html.markdown | 12 + 2 files changed, 140 insertions(+), 128 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 962bac63ecc4..fb3fd6f85b43 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -112,70 +112,70 @@ func testAccVPCEndpointConnectionConfig(name string) string { return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" - - tags = { - Name = %[1]q - } -} - -resource "aws_security_group" "test" { - vpc_id = aws_vpc.test.id -} - -resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id -} - -resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q - - ebs_options { - ebs_enabled = true - volume_size = 10 - } - - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } - - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} - -resource "aws_opensearch_vpc_endpoint_connection" "test" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - -} + resource "aws_vpc" "test" { + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } + } + + resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } + } + + resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } + } + + resource "aws_security_group" "test" { + vpc_id = aws_vpc.test.id + } + + resource "aws_security_group" "test2" { + vpc_id = aws_vpc.test.id + } + + resource "aws_opensearch_domain" "domain_1" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + } + + resource "aws_opensearch_vpc_endpoint_connection" "foo" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + + } `, name)) } @@ -187,70 +187,70 @@ func testAccVPCEndpointConnectionConfigUpdate(name string) string { return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" - - tags = { - Name = %[1]q - } -} - -resource "aws_security_group" "test" { - vpc_id = aws_vpc.test.id -} - -resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id -} - -resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q - - ebs_options { - ebs_enabled = true - volume_size = 10 - } - - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } - - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} - -resource "aws_opensearch_vpc_endpoint_connection" "test" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - -} + resource "aws_vpc" "test" { + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } + } + + resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } + } + + resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } + } + + resource "aws_security_group" "test" { + vpc_id = aws_vpc.test.id + } + + resource "aws_security_group" "test2" { + vpc_id = aws_vpc.test.id + } + + resource "aws_opensearch_domain" "domain_1" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + } + + resource "aws_opensearch_vpc_endpoint_connection" "foo" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } + + } `, name)) } diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index b16f23644118..2e14310765b7 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -16,6 +16,18 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ sample code here +```terraform + +resource "aws_opensearch_vpc_endpoint_connection" "foo" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} + +``` + ## Argument Reference The following arguments are supported: From 2e4425052b26d1303c45ba8877cf50b2d552d748 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 10:45:11 +0100 Subject: [PATCH 12/46] fix website format --- .../vpc_endpoint_connection_test.go | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index fb3fd6f85b43..a98c3c48a754 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -106,84 +106,76 @@ func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { } func testAccVPCEndpointConnectionConfig(name string) string { - // Satisfy the pw requirements - //pw := fmt.Sprintf("Aa1-%s", sdkacctest.RandString(10)) - return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), - fmt.Sprintf(` - resource "aws_vpc" "test" { + fmt.Sprintf(`resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" - + tags = { Name = %[1]q } - } - - resource "aws_subnet" "test" { + } + + resource "aws_subnet" "test" { vpc_id = aws_vpc.test.id availability_zone = data.aws_availability_zones.available.names[0] cidr_block = "192.168.0.0/24" - + tags = { Name = %[1]q } - } - - resource "aws_subnet" "test2" { + } + + resource "aws_subnet" "test2" { vpc_id = aws_vpc.test.id availability_zone = data.aws_availability_zones.available.names[1] cidr_block = "192.168.1.0/24" - + tags = { Name = %[1]q } - } - - resource "aws_security_group" "test" { + } + + resource "aws_security_group" "test" { vpc_id = aws_vpc.test.id - } - - resource "aws_security_group" "test2" { + } + + resource "aws_security_group" "test2" { vpc_id = aws_vpc.test.id - } - - resource "aws_opensearch_domain" "domain_1" { + } + + resource "aws_opensearch_domain" "domain_1" { domain_name = %[1]q - + ebs_options { ebs_enabled = true volume_size = 10 } - + cluster_config { instance_count = 2 zone_awareness_enabled = true instance_type = "t3.small.search" } - + vpc_options { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - } - - resource "aws_opensearch_vpc_endpoint_connection" "foo" { + } + + resource "aws_opensearch_vpc_endpoint_connection" "foo" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - - } -`, name)) + + }`, name)) } func testAccVPCEndpointConnectionConfigUpdate(name string) string { - // Satisfy the pw requirements - //pw := fmt.Sprintf("Aa1-%s", sdkacctest.RandString(10)) - return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` From 748609a3353edc37c88d92beca6a48c1de8b5235 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 12:24:22 +0100 Subject: [PATCH 13/46] website format --- internal/service/opensearch/vpc_endpoint_connection_test.go | 3 ++- .../docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index a98c3c48a754..e9d2fcbf4bd3 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -108,7 +108,8 @@ func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { func testAccVPCEndpointConnectionConfig(name string) string { return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), - fmt.Sprintf(`resource "aws_vpc" "test" { + fmt.Sprintf(` + resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" tags = { diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 2e14310765b7..4340e0e0cf00 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -14,8 +14,6 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ### Basic Usage -sample code here - ```terraform resource "aws_opensearch_vpc_endpoint_connection" "foo" { From 301d73267e1f6d5bf9f3cd2bf10a2a088560e3b1 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 12:40:24 +0100 Subject: [PATCH 14/46] website format --- .../opensearch/vpc_endpoint_connection_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index e9d2fcbf4bd3..832b9e74b2fa 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -109,7 +109,7 @@ func testAccVPCEndpointConnectionConfig(name string) string { return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` - resource "aws_vpc" "test" { + resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" tags = { @@ -171,8 +171,8 @@ func testAccVPCEndpointConnectionConfig(name string) string { security_group_ids = [aws_security_group.test.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - - }`, name)) + } + `, name)) } @@ -180,7 +180,7 @@ func testAccVPCEndpointConnectionConfigUpdate(name string) string { return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` - resource "aws_vpc" "test" { + resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" tags = { @@ -242,8 +242,7 @@ func testAccVPCEndpointConnectionConfigUpdate(name string) string { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - } -`, name)) + `, name)) } From 978d1e6a0f00456435c9c5c70a9b785b295e5169 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 12:48:47 +0100 Subject: [PATCH 15/46] website format --- .../vpc_endpoint_connection_test.go | 120 ++++++++---------- 1 file changed, 56 insertions(+), 64 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 832b9e74b2fa..7f73c14ebb7b 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -109,70 +109,62 @@ func testAccVPCEndpointConnectionConfig(name string) string { return acctest.ConfigCompose( acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` - resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" - - tags = { - Name = %[1]q - } - } - - resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" - - tags = { - Name = %[1]q - } - } - - resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" - - tags = { - Name = %[1]q - } - } - - resource "aws_security_group" "test" { - vpc_id = aws_vpc.test.id - } - - resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id - } - - resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q - - ebs_options { - ebs_enabled = true - volume_size = 10 - } - - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } - - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - } - - resource "aws_opensearch_vpc_endpoint_connection" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - } - `, name)) +resource "aws_vpc" "test" { + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_security_group" "test" { + vpc_id = aws_vpc.test.id +} + +resource "aws_security_group" "test2" { + vpc_id = aws_vpc.test.id +} + +resource "aws_opensearch_domain" "test" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t2.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} +`, name)) } From 74cf8431d0b390cf5a83be610bbdbe1b376d5191 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 11 Jul 2023 12:56:14 +0100 Subject: [PATCH 16/46] website format --- .../service/opensearch/vpc_endpoint_connection_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 7f73c14ebb7b..24a155e96c67 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -164,6 +164,14 @@ resource "aws_opensearch_domain" "test" { subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } } + +resource "aws_opensearch_vpc_endpoint_connection" "foo" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} `, name)) } From d1243c3c819bfd82395fc8d2ed89cf9af5f9f041 Mon Sep 17 00:00:00 2001 From: Debojit Bhadra Date: Tue, 11 Jul 2023 13:11:25 +0100 Subject: [PATCH 17/46] refactor: updated test.go --- .../vpc_endpoint_connection_test.go | 143 +++++++++--------- 1 file changed, 69 insertions(+), 74 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 24a155e96c67..1580a4fba36e 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -106,9 +106,7 @@ func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { } func testAccVPCEndpointConnectionConfig(name string) string { - return acctest.ConfigCompose( - acctest.ConfigAvailableAZsNoOptIn(), - fmt.Sprintf(` + return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" @@ -145,7 +143,7 @@ resource "aws_security_group" "test2" { vpc_id = aws_vpc.test.id } -resource "aws_opensearch_domain" "test" { +resource "aws_opensearch_domain" "domain_1" { domain_name = %[1]q ebs_options { @@ -156,93 +154,90 @@ resource "aws_opensearch_domain" "test" { cluster_config { instance_count = 2 zone_awareness_enabled = true - instance_type = "t2.small.search" + instance_type = "t3.small.search" } vpc_options { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } -} + } -resource "aws_opensearch_vpc_endpoint_connection" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } + resource "aws_opensearch_vpc_endpoint_connection" "foo" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } } `, name)) } func testAccVPCEndpointConnectionConfigUpdate(name string) string { - return acctest.ConfigCompose( - acctest.ConfigAvailableAZsNoOptIn(), - fmt.Sprintf(` - resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" - - tags = { - Name = %[1]q - } - } - - resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" - - tags = { - Name = %[1]q - } - } - - resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" - - tags = { - Name = %[1]q - } - } - - resource "aws_security_group" "test" { - vpc_id = aws_vpc.test.id - } + return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } +} - resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id - } +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } +} - resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q +resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } +} - ebs_options { - ebs_enabled = true - volume_size = 10 - } +resource "aws_security_group" "test" { + vpc_id = aws_vpc.test.id +} - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } +resource "aws_security_group" "test2" { + vpc_id = aws_vpc.test.id +} - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - } +resource "aws_opensearch_domain" "domain_1" { + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} - resource "aws_opensearch_vpc_endpoint_connection" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } - } - `, name)) - +resource "aws_opensearch_vpc_endpoint_connection" "foo" { + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} +`, name)) } From 00a837660b808c1b553b306f4c6655a8b332e2e8 Mon Sep 17 00:00:00 2001 From: Debojit Bhadra Date: Tue, 11 Jul 2023 14:31:04 +0100 Subject: [PATCH 18/46] fix indentation --- .../vpc_endpoint_connection_test.go | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 1580a4fba36e..9225f8f174b7 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -161,9 +161,9 @@ resource "aws_opensearch_domain" "domain_1" { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } - } +} - resource "aws_opensearch_vpc_endpoint_connection" "foo" { +resource "aws_opensearch_vpc_endpoint_connection" "foo" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id] @@ -177,67 +177,67 @@ resource "aws_opensearch_domain" "domain_1" { func testAccVPCEndpointConnectionConfigUpdate(name string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" - - tags = { - Name = %[1]q - } + cidr_block = "192.168.0.0/22" + + tags = { + Name = %[1]q + } } - + resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" - - tags = { - Name = %[1]q - } -} - + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[0] + cidr_block = "192.168.0.0/24" + + tags = { + Name = %[1]q + } +} + resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" - - tags = { - Name = %[1]q - } -} - + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[1] + cidr_block = "192.168.1.0/24" + + tags = { + Name = %[1]q + } +} + resource "aws_security_group" "test" { - vpc_id = aws_vpc.test.id + vpc_id = aws_vpc.test.id } - + resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id + vpc_id = aws_vpc.test.id } - + resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q - - ebs_options { - ebs_enabled = true - volume_size = 10 - } - - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } - - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} - + domain_name = %[1]q + + ebs_options { + ebs_enabled = true + volume_size = 10 + } + + cluster_config { + instance_count = 2 + zone_awareness_enabled = true + instance_type = "t3.small.search" + } + + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} + resource "aws_opensearch_vpc_endpoint_connection" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} + domain_arn = aws_opensearch_domain.domain_1.arn + vpc_options { + security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + } +} `, name)) } From 6ee6301c2b51e3f56975c14a1dee33036e1e2ea4 Mon Sep 17 00:00:00 2001 From: Debojit Bhadra Date: Tue, 11 Jul 2023 15:40:10 +0100 Subject: [PATCH 19/46] lint fix --- internal/service/opensearch/vpc_endpoint_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 9225f8f174b7..375cf0eece26 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -238,6 +238,6 @@ resource "aws_opensearch_vpc_endpoint_connection" "foo" { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } -} +} `, name)) } From 6882a5b7be781bb758c3a9fccae5d9959d12f635 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Wed, 12 Jul 2023 16:57:38 +0100 Subject: [PATCH 20/46] remove whitespace --- internal/service/opensearch/vpc_endpoint_connection.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection.go b/internal/service/opensearch/vpc_endpoint_connection.go index f4ef713deda3..5216ce321ba3 100644 --- a/internal/service/opensearch/vpc_endpoint_connection.go +++ b/internal/service/opensearch/vpc_endpoint_connection.go @@ -27,7 +27,6 @@ func ResourceVPCEndpoint() *schema.Resource { ReadWithoutTimeout: resourceVPCEndpointRead, UpdateWithoutTimeout: resourceVPCEndpointPut, DeleteWithoutTimeout: resourceVPCEndpointDelete, - Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, From 0dc7b6685d399a792abf356eb4efb6720ec710fe Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 10:53:56 +0100 Subject: [PATCH 21/46] remove unnecessary trailing newline --- internal/service/opensearch/vpc_endpoint_connection.go | 1 - internal/service/opensearch/vpc_endpoint_connection_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection.go b/internal/service/opensearch/vpc_endpoint_connection.go index 5216ce321ba3..de2811d3dac4 100644 --- a/internal/service/opensearch/vpc_endpoint_connection.go +++ b/internal/service/opensearch/vpc_endpoint_connection.go @@ -177,7 +177,6 @@ func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta in } return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) - } func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_connection_test.go index 375cf0eece26..485db866c6fb 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_connection_test.go @@ -171,7 +171,6 @@ resource "aws_opensearch_vpc_endpoint_connection" "foo" { } } `, name)) - } func testAccVPCEndpointConnectionConfigUpdate(name string) string { From 5787fceb8d4b376e790f4c8220bc822aff7376cb Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 11:05:43 +0100 Subject: [PATCH 22/46] updated documentation --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 4340e0e0cf00..17a72d27f660 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -38,7 +38,7 @@ The following arguments are supported: * `security_group_ids` - (Optional) The list of security group IDs associated with the VPC endpoints for the domain. If you do not provide a security group ID, OpenSearch Service uses the default security group for the VPC. * `subnet_ids` - (Optional) A list of subnet IDs associated with the VPC endpoints for the domain. If your domain uses multiple Availability Zones, you need to provide two subnet IDs, one per zone. Otherwise, provide only one. -## Attributes Reference +## Attribute Reference In addition to all arguments above, the following attributes are exported: From 29ca27a3ecf541f681247244e6f7cb02a5e85fc0 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 11:30:38 +0100 Subject: [PATCH 23/46] updated documentation --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 17a72d27f660..f2c3d3da2392 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -40,7 +40,7 @@ The following arguments are supported: ## Attribute Reference -In addition to all arguments above, the following attributes are exported: +This resource exports the following attributes in addition to the arguments above: * `id` - The connection endpoint ID for connecting to the domain. * `connection_status` - The current status of the endpoint. From df4db09b918bb8b14c06d85ad71e1f673142e49a Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 11:46:23 +0100 Subject: [PATCH 24/46] updated documentation --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index f2c3d3da2392..ac136c9929e8 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -47,7 +47,7 @@ This resource exports the following attributes in addition to the arguments abov ## Import -AWS Opensearch VPC Endpoint Connection can be imported by using the VPC Endpoint Connection ID, e.g., +AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. ``` $ terraform import aws_opensearch_vpc_endpoint_connection.foo endpoint-id From 0deb277dd9e46e0835aeacb7b71978d42b127e30 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 11:57:52 +0100 Subject: [PATCH 25/46] updated documentation --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index ac136c9929e8..6cbc84adaa5f 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -47,7 +47,7 @@ This resource exports the following attributes in addition to the arguments abov ## Import -AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. +AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example ``` $ terraform import aws_opensearch_vpc_endpoint_connection.foo endpoint-id From c5a2b02350967aa25fe1f71458901f8baddbfd6a Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 12:03:05 +0100 Subject: [PATCH 26/46] updated documentation --- website/docs/r/opensearch_vpc_endpoint_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 6cbc84adaa5f..097ac184efcf 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -47,7 +47,7 @@ This resource exports the following attributes in addition to the arguments abov ## Import -AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example +AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example: ``` $ terraform import aws_opensearch_vpc_endpoint_connection.foo endpoint-id From 68ca2aa21db42c36e8936e6a708fe3b3872424a2 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 13:01:19 +0100 Subject: [PATCH 27/46] updated documentation --- .../opensearch_vpc_endpoint_connection.html.markdown | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 097ac184efcf..4185b07101aa 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -50,5 +50,14 @@ This resource exports the following attributes in addition to the arguments abov AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example: ``` -$ terraform import aws_opensearch_vpc_endpoint_connection.foo endpoint-id +$ terraform +import { + to = aws_opensearch_vpc_endpoint_connection.foo + id = "endpoint-id" +} + +resource "aws_opensearch_vpc_endpoint_connection" "foo" { + name = "hashi" + # (other resource arguments...) +} ``` From 10510892760bc26337160a28a599c5fa3c6f6986 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 13:06:27 +0100 Subject: [PATCH 28/46] updated documentation --- .../docs/r/opensearch_vpc_endpoint_connection.html.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 4185b07101aa..a8afa26ae3f1 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -49,8 +49,7 @@ This resource exports the following attributes in addition to the arguments abov AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example: -``` -$ terraform +```terraform import { to = aws_opensearch_vpc_endpoint_connection.foo id = "endpoint-id" From 134cab4477abd455489b0fb975171bc9660e3a61 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 08:10:11 -0400 Subject: [PATCH 29/46] Fix tfproviderdocs 'the first import section code block should have an import block using type 'terraform''. --- ...nsearch_vpc_endpoint_connection.html.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 4185b07101aa..199ae3131bf1 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -47,17 +47,17 @@ This resource exports the following attributes in addition to the arguments abov ## Import -AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import OpenSearch VPC endpoint connections using the `id`. For example: -``` -$ terraform +```terraform import { - to = aws_opensearch_vpc_endpoint_connection.foo + to = aws_opensearch_vpc_endpoint_connection.example id = "endpoint-id" } +``` -resource "aws_opensearch_vpc_endpoint_connection" "foo" { - name = "hashi" - # (other resource arguments...) -} +Using `terraform import`, import OpenSearch VPC endpoint connections using the `id`. For example: + +```console +% terraform import aws_opensearch_vpc_endpoint_connection.example endpoint-id ``` From 6330fd85095f1bc8030666858f84b58afa8631ef Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 08:16:57 -0400 Subject: [PATCH 30/46] Correct CHANGELOG entry. --- .changelog/29912.txt | 3 --- .changelog/32435.txt | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 .changelog/29912.txt create mode 100644 .changelog/32435.txt diff --git a/.changelog/29912.txt b/.changelog/29912.txt deleted file mode 100644 index 3202e12a1615..000000000000 --- a/.changelog/29912.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:IsNewResource -resource/aws_opensearch_vpc_endpoint_connection: added a new resource to create vpc endpoint connection for an aws opensearch domain -``` \ No newline at end of file diff --git a/.changelog/32435.txt b/.changelog/32435.txt new file mode 100644 index 000000000000..db11890b2c3d --- /dev/null +++ b/.changelog/32435.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_opensearch_vpc_endpoint_connection +``` \ No newline at end of file From 31e3c9cdcd6f16d9b1018ce722c31b52f6549273 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 08:18:42 -0400 Subject: [PATCH 31/46] r/aws_opensearch_vpc_endpoint_connection: Document 'timeouts'. --- .../r/opensearch_vpc_endpoint_connection.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index 199ae3131bf1..8bffcdb883bd 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -45,6 +45,14 @@ This resource exports the following attributes in addition to the arguments abov * `id` - The connection endpoint ID for connecting to the domain. * `connection_status` - The current status of the endpoint. +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `60m`) +* `update` - (Default `60m`) +* `delete` - (Default `90m`) + ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import OpenSearch VPC endpoint connections using the `id`. For example: From 4ec51b54a95ddcf528bc7551a60e37b4a1b326cd Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 08:21:56 -0400 Subject: [PATCH 32/46] r/aws_opensearch_vpc_endpoint_connection: Alphabetize attribute. --- .../service/opensearch/vpc_endpoint_connection.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_connection.go b/internal/service/opensearch/vpc_endpoint_connection.go index de2811d3dac4..a6d2e814062a 100644 --- a/internal/service/opensearch/vpc_endpoint_connection.go +++ b/internal/service/opensearch/vpc_endpoint_connection.go @@ -27,6 +27,7 @@ func ResourceVPCEndpoint() *schema.Resource { ReadWithoutTimeout: resourceVPCEndpointRead, UpdateWithoutTimeout: resourceVPCEndpointPut, DeleteWithoutTimeout: resourceVPCEndpointDelete, + Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -38,6 +39,10 @@ func ResourceVPCEndpoint() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "connection_status": { + Type: schema.TypeString, + Computed: true, + }, "domain_arn": { Type: schema.TypeString, Required: true, @@ -54,19 +59,16 @@ func ResourceVPCEndpoint() *schema.Resource { Type: schema.TypeSet, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "security_group_ids": { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "subnet_ids": { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "vpc_id": { Type: schema.TypeString, @@ -75,10 +77,6 @@ func ResourceVPCEndpoint() *schema.Resource { }, }, }, - "connection_status": { - Type: schema.TypeString, - Computed: true, - }, }, } } From 852c0d02c2bb6f686d782526041273de4412b80a Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 13:54:34 +0100 Subject: [PATCH 33/46] updated resource name to vpc endpoint --- .../service/opensearch/service_package_gen.go | 2 +- ...endpoint_connection.go => vpc_endpoint.go} | 38 +++++++++---------- ...onnection_test.go => vpc_endpoint_test.go} | 28 +++++++------- ...arch_vpc_endpoint_connection.html.markdown | 16 ++++---- 4 files changed, 42 insertions(+), 42 deletions(-) rename internal/service/opensearch/{vpc_endpoint_connection.go => vpc_endpoint.go} (79%) rename internal/service/opensearch/{vpc_endpoint_connection_test.go => vpc_endpoint_test.go} (87%) diff --git a/internal/service/opensearch/service_package_gen.go b/internal/service/opensearch/service_package_gen.go index 213140cd6909..be066c6c9dec 100644 --- a/internal/service/opensearch/service_package_gen.go +++ b/internal/service/opensearch/service_package_gen.go @@ -60,7 +60,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka }, { Factory: ResourceVPCEndpoint, - TypeName: "aws_opensearch_vpc_endpoint_connection", + TypeName: "aws_opensearch_vpc_endpoint", }, } } diff --git a/internal/service/opensearch/vpc_endpoint_connection.go b/internal/service/opensearch/vpc_endpoint.go similarity index 79% rename from internal/service/opensearch/vpc_endpoint_connection.go rename to internal/service/opensearch/vpc_endpoint.go index de2811d3dac4..1047dff17f20 100644 --- a/internal/service/opensearch/vpc_endpoint_connection.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -20,7 +20,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -// @SDKResource("aws_opensearch_vpc_endpoint_connection") +// @SDKResource("aws_opensearch_vpc_endpoint") func ResourceVPCEndpoint() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceVPCEndpointCreate, @@ -113,7 +113,7 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta d.SetId(aws.StringValue(resp.VpcEndpoint.VpcEndpointId)) log.Printf("[INFO] open search vpc endpoint ID: %s", d.Id()) - err = vpcEndpointConnectionWaitUntilActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) + err = vpcEndpointWaitUntilActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) if err != nil { return diag.Errorf("waiting for vpc endpoint to become active: %s", err) } @@ -124,20 +124,20 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) - endpointRaw, status, err := vpcEndpointConnectionRefreshState(ctx, conn, d.Id())() + endpointRaw, status, err := vpcEndpointRefreshState(ctx, conn, d.Id())() if err != nil { - return diag.Errorf("reading vpc endpoint Connection: %s", err) + return diag.Errorf("reading vpc endpoint: %s", err) } endpoint := endpointRaw.(*opensearchservice.VpcEndpoint) - log.Printf("[DEBUG] vpc endpoint Connection response: %#v", endpoint) + log.Printf("[DEBUG] vpc endpoint response: %#v", endpoint) d.Set("connection_status", status) d.Set("domain_arn", endpoint.DomainArn) if endpoint.VpcOptions == nil { - return diag.Errorf("reading vpc endpoint Connection vpc options ") + return diag.Errorf("reading vpc endpoint vpc options ") } d.Set("vpc_options", flattenVPCDerivedInfo(endpoint.VpcOptions)) @@ -163,15 +163,15 @@ func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta in input.VpcOptions = expandVPCOptions(s) } - log.Printf("[DEBUG] Updating vpc endpoint Connection %s", input) + log.Printf("[DEBUG] Updating vpc endpoint %s", input) _, err := conn.UpdateVpcEndpointWithContext(ctx, input) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating vpc endpoint Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating vpc endpoint (%s): %s", d.Id(), err) } - err = vpcEndpointConnectionWaitUntilUpdate(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)) + err = vpcEndpointWaitUntilUpdate(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)) if err != nil { return diag.Errorf("waiting for vpc endpoint to become active: %s", err) } @@ -192,13 +192,13 @@ func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta } if err != nil { - return diag.Errorf("deleting vpc endpoint Connection (%s): %s", d.Id(), err) + return diag.Errorf("deleting vpc endpoint (%s): %s", d.Id(), err) } return nil } -func vpcEndpointConnectionRefreshState(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) retry.StateRefreshFunc { +func vpcEndpointRefreshState(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { resp, err := conn.DescribeVpcEndpointsWithContext(ctx, &opensearchservice.DescribeVpcEndpointsInput{ VpcEndpointIds: []*string{aws.String(id)}, @@ -225,8 +225,8 @@ func vpcEndpointConnectionRefreshState(ctx context.Context, conn *opensearchserv } } -func vpcEndpointConnectionWaitUntilActive(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { - log.Printf("[DEBUG] Waiting for VPC Endpoint Connection (%s) to become available.", id) +func vpcEndpointWaitUntilActive(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for VPC Endpoint (%s) to become available.", id) stateConf := &retry.StateChangeConf{ Pending: []string{ opensearchservice.VpcEndpointStatusCreating, @@ -234,17 +234,17 @@ func vpcEndpointConnectionWaitUntilActive(ctx context.Context, conn *opensearchs Target: []string{ opensearchservice.VpcEndpointStatusActive, }, - Refresh: vpcEndpointConnectionRefreshState(ctx, conn, id), + Refresh: vpcEndpointRefreshState(ctx, conn, id), Timeout: timeout, } if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for VPC Endpoint Connection (%s) to become available: %s", id, err) + return fmt.Errorf("waiting for VPC Endpoint (%s) to become available: %s", id, err) } return nil } -func vpcEndpointConnectionWaitUntilUpdate(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { - log.Printf("[DEBUG] Waiting for VPC Endpoint Connection (%s) to become available.", id) +func vpcEndpointWaitUntilUpdate(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for VPC Endpoint (%s) to become available.", id) stateConf := &retry.StateChangeConf{ Pending: []string{ opensearchservice.VpcEndpointStatusUpdating, @@ -252,11 +252,11 @@ func vpcEndpointConnectionWaitUntilUpdate(ctx context.Context, conn *opensearchs Target: []string{ opensearchservice.VpcEndpointStatusActive, }, - Refresh: vpcEndpointConnectionRefreshState(ctx, conn, id), + Refresh: vpcEndpointRefreshState(ctx, conn, id), Timeout: timeout, } if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for VPC Endpoint Connection (%s) to become available: %s", id, err) + return fmt.Errorf("waiting for VPC Endpoint (%s) to become available: %s", id, err) } return nil } diff --git a/internal/service/opensearch/vpc_endpoint_connection_test.go b/internal/service/opensearch/vpc_endpoint_test.go similarity index 87% rename from internal/service/opensearch/vpc_endpoint_connection_test.go rename to internal/service/opensearch/vpc_endpoint_test.go index 485db866c6fb..f97b2bbb4a1f 100644 --- a/internal/service/opensearch/vpc_endpoint_connection_test.go +++ b/internal/service/opensearch/vpc_endpoint_test.go @@ -14,12 +14,12 @@ import ( tfopensearch "github.com/hashicorp/terraform-provider-aws/internal/service/opensearch" ) -func TestAccOpenSearchVPCEndpointConnection_basic(t *testing.T) { +func TestAccOpenSearchVPCEndpoint_basic(t *testing.T) { ctx := acctest.Context(t) var domain opensearchservice.DomainStatus ri := sdkacctest.RandString(10) name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint_connection.test" + resourceName := "aws_opensearch_vpc_endpoint.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -28,7 +28,7 @@ func TestAccOpenSearchVPCEndpointConnection_basic(t *testing.T) { CheckDestroy: testAccCheckDomainDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccVPCEndpointConnectionConfig(name), + Config: testAccVPCEndpointConfig(name), Check: resource.ComposeTestCheckFunc( testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), @@ -43,12 +43,12 @@ func TestAccOpenSearchVPCEndpointConnection_basic(t *testing.T) { }) } -func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { +func TestAccOpenSearchVPCEndpoint_update(t *testing.T) { ctx := acctest.Context(t) var domain opensearchservice.DomainStatus ri := sdkacctest.RandString(10) name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint_connection.test" + resourceName := "aws_opensearch_vpc_endpoint.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -57,7 +57,7 @@ func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { CheckDestroy: testAccCheckDomainDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccVPCEndpointConnectionConfig(name), + Config: testAccVPCEndpointConfig(name), Check: resource.ComposeTestCheckFunc( testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "1"), @@ -65,7 +65,7 @@ func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { ), }, { - Config: testAccVPCEndpointConnectionConfigUpdate(name), + Config: testAccVPCEndpointConfigUpdate(name), Check: resource.ComposeTestCheckFunc( testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "2"), @@ -81,12 +81,12 @@ func TestAccOpenSearchVPCEndpointConnection_update(t *testing.T) { }) } -func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { +func TestAccOpenSearchVPCEndpoint_disappears(t *testing.T) { ctx := acctest.Context(t) var domain opensearchservice.DomainStatus ri := sdkacctest.RandString(10) name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint_connection.test" + resourceName := "aws_opensearch_vpc_endpoint.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -95,7 +95,7 @@ func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { CheckDestroy: testAccCheckDomainDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccVPCEndpointConnectionConfig(name), + Config: testAccVPCEndpointConfig(name), Check: resource.ComposeTestCheckFunc( testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), acctest.CheckResourceDisappears(ctx, acctest.Provider, tfopensearch.ResourceVPCEndpoint(), resourceName), @@ -105,7 +105,7 @@ func TestAccOpenSearchVPCEndpointConnection_disappears(t *testing.T) { }) } -func testAccVPCEndpointConnectionConfig(name string) string { +func testAccVPCEndpointConfig(name string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" @@ -163,7 +163,7 @@ resource "aws_opensearch_domain" "domain_1" { } } -resource "aws_opensearch_vpc_endpoint_connection" "foo" { +resource "aws_opensearch_vpc_endpoint" "foo" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id] @@ -173,7 +173,7 @@ resource "aws_opensearch_vpc_endpoint_connection" "foo" { `, name)) } -func testAccVPCEndpointConnectionConfigUpdate(name string) string { +func testAccVPCEndpointConfigUpdate(name string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "192.168.0.0/22" @@ -231,7 +231,7 @@ resource "aws_opensearch_domain" "domain_1" { } } -resource "aws_opensearch_vpc_endpoint_connection" "foo" { +resource "aws_opensearch_vpc_endpoint" "foo" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown index a8afa26ae3f1..bf5d620080f7 100644 --- a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown @@ -1,14 +1,14 @@ --- subcategory: "OpenSearch" layout: "aws" -page_title: "AWS: aws_opensearch_vpc_endpoint_connection" +page_title: "AWS: aws_opensearch_vpc_endpoint" description: |- - Terraform resource for managing an AWS OpenSearch VPC Endpoint connection. + Terraform resource for managing an AWS OpenSearch VPC Endpoint. --- -# Resource: aws_opensearch_vpc_endpoint_connection +# Resource: aws_opensearch_vpc_endpoint -Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_CreateVpcEndpoint.html). Creates an Amazon OpenSearch Service-managed VPC endpoint.. +Manages an [AWS Opensearch VPC Endpoint](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_CreateVpcEndpoint.html). Creates an Amazon OpenSearch Service-managed VPC endpoint.. ## Example Usage @@ -16,7 +16,7 @@ Manages an [AWS Opensearch VPC Endpoint Connection](https://docs.aws.amazon.com/ ```terraform -resource "aws_opensearch_vpc_endpoint_connection" "foo" { +resource "aws_opensearch_vpc_endpoint" "foo" { domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] @@ -47,15 +47,15 @@ This resource exports the following attributes in addition to the arguments abov ## Import -AWS Opensearch VPC Endpoint Connection imported by using the VPC Endpoint Connection ID `id`. For example: +AWS Opensearch VPC Endpoint imported by using the VPC Endpoint Connection ID `id`. For example: ```terraform import { - to = aws_opensearch_vpc_endpoint_connection.foo + to = aws_opensearch_vpc_endpoint.foo id = "endpoint-id" } -resource "aws_opensearch_vpc_endpoint_connection" "foo" { +resource "aws_opensearch_vpc_endpoint" "foo" { name = "hashi" # (other resource arguments...) } From 8b8bd4221b7109f98d300191af7f9164c47c65ca Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 15:56:30 +0100 Subject: [PATCH 34/46] updated test case --- internal/service/opensearch/vpc_endpoint_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_test.go b/internal/service/opensearch/vpc_endpoint_test.go index f97b2bbb4a1f..a3469e2270e3 100644 --- a/internal/service/opensearch/vpc_endpoint_test.go +++ b/internal/service/opensearch/vpc_endpoint_test.go @@ -19,7 +19,7 @@ func TestAccOpenSearchVPCEndpoint_basic(t *testing.T) { var domain opensearchservice.DomainStatus ri := sdkacctest.RandString(10) name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint.test" + resourceName := "aws_opensearch_vpc_endpoint.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -48,7 +48,7 @@ func TestAccOpenSearchVPCEndpoint_update(t *testing.T) { var domain opensearchservice.DomainStatus ri := sdkacctest.RandString(10) name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint.test" + resourceName := "aws_opensearch_vpc_endpoint.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -86,7 +86,7 @@ func TestAccOpenSearchVPCEndpoint_disappears(t *testing.T) { var domain opensearchservice.DomainStatus ri := sdkacctest.RandString(10) name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint.test" + resourceName := "aws_opensearch_vpc_endpoint.foo" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, From 12309e0b4d9596ab3aee892b3f1c3b4dcb702319 Mon Sep 17 00:00:00 2001 From: Lanre Afodunrinbi Date: Tue, 15 Aug 2023 16:04:35 +0100 Subject: [PATCH 35/46] updated documentation name --- ...ection.html.markdown => opensearch_vpc_endpoint.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/docs/r/{opensearch_vpc_endpoint_connection.html.markdown => opensearch_vpc_endpoint.html.markdown} (100%) diff --git a/website/docs/r/opensearch_vpc_endpoint_connection.html.markdown b/website/docs/r/opensearch_vpc_endpoint.html.markdown similarity index 100% rename from website/docs/r/opensearch_vpc_endpoint_connection.html.markdown rename to website/docs/r/opensearch_vpc_endpoint.html.markdown From 815b34ed469b51e4b150544b9dddc64670a17013 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 15:25:50 -0400 Subject: [PATCH 36/46] Correct CHANGELOG entry. --- .changelog/32435.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/32435.txt b/.changelog/32435.txt index db11890b2c3d..68a15a639398 100644 --- a/.changelog/32435.txt +++ b/.changelog/32435.txt @@ -1,3 +1,3 @@ ```release-note:new-resource -aws_opensearch_vpc_endpoint_connection +aws_opensearch_vpc_endpoint ``` \ No newline at end of file From 70bbb06a039e17c739535b96d9059728e6ff7635 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 15:33:05 -0400 Subject: [PATCH 37/46] r/aws_opensearch_vpc_endpoint: 'vpc_options' is Required. --- internal/service/opensearch/vpc_endpoint.go | 33 ++++++------------- .../r/opensearch_vpc_endpoint.html.markdown | 4 +-- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index 9731fb1003db..c19af5bdf9b9 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -51,7 +51,7 @@ func ResourceVPCEndpoint() *schema.Resource { }, "vpc_options": { Type: schema.TypeList, - Optional: true, + Required: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -63,11 +63,12 @@ func ResourceVPCEndpoint() *schema.Resource { "security_group_ids": { Type: schema.TypeSet, Optional: true, + Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, "subnet_ids": { Type: schema.TypeSet, - Optional: true, + Required: true, Elem: &schema.Schema{Type: schema.TypeString}, }, "vpc_id": { @@ -85,35 +86,21 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) - // Create the VPC Endpoint input := &opensearchservice.CreateVpcEndpointInput{ - DomainArn: aws.String(d.Get("domain_arn").(string)), - } - - if v, ok := d.GetOk("vpc_options"); ok { - options := v.([]interface{}) - if options[0] == nil { - return sdkdiag.AppendErrorf(diags, "At least one field is expected inside vpc_options") - } - - s := options[0].(map[string]interface{}) - input.VpcOptions = expandVPCOptions(s) + DomainArn: aws.String(d.Get("domain_arn").(string)), + VpcOptions: expandVPCOptions(d.Get("vpc_options").([]interface{})[0].(map[string]interface{})), } - log.Printf("[DEBUG] Create VPC Endpoint options: %#v", input) + output, err := conn.CreateVpcEndpointWithContext(ctx, input) - resp, err := conn.CreateVpcEndpointWithContext(ctx, input) if err != nil { - return diag.Errorf("creating vpc endpoint : %s", err) + return sdkdiag.AppendErrorf(diags, "creating OpenSearch VPC Endpoint: %s", err) } - // Get the ID and store it - d.SetId(aws.StringValue(resp.VpcEndpoint.VpcEndpointId)) - log.Printf("[INFO] open search vpc endpoint ID: %s", d.Id()) + d.SetId(aws.StringValue(output.VpcEndpoint.VpcEndpointId)) - err = vpcEndpointWaitUntilActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) - if err != nil { - return diag.Errorf("waiting for vpc endpoint to become active: %s", err) + if err := vpcEndpointWaitUntilActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch VPC Endpoint (%s) create: %s", d.Id(), err) } return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) diff --git a/website/docs/r/opensearch_vpc_endpoint.html.markdown b/website/docs/r/opensearch_vpc_endpoint.html.markdown index 37df03511121..dba59cb0fa58 100644 --- a/website/docs/r/opensearch_vpc_endpoint.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint.html.markdown @@ -31,12 +31,12 @@ resource "aws_opensearch_vpc_endpoint" "foo" { The following arguments are supported: * `domain_arn` - (Required, Forces new resource) Specifies the Amazon Resource Name (ARN) of the domain to create the endpoint for -* `vpc_options` - (Optional) Options to specify the subnets and security groups for the endpoint. +* `vpc_options` - (Required) Options to specify the subnets and security groups for the endpoint. ### vpc_options * `security_group_ids` - (Optional) The list of security group IDs associated with the VPC endpoints for the domain. If you do not provide a security group ID, OpenSearch Service uses the default security group for the VPC. -* `subnet_ids` - (Optional) A list of subnet IDs associated with the VPC endpoints for the domain. If your domain uses multiple Availability Zones, you need to provide two subnet IDs, one per zone. Otherwise, provide only one. +* `subnet_ids` - (Required) A list of subnet IDs associated with the VPC endpoints for the domain. If your domain uses multiple Availability Zones, you need to provide two subnet IDs, one per zone. Otherwise, provide only one. ## Attribute Reference From 7032cafcbf9bfeee431ab6aed5294af2446b42a3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 16:45:22 -0400 Subject: [PATCH 38/46] opensearch: Add 'vpcEndpointError' etc. --- internal/service/opensearch/exports_test.go | 9 +++ internal/service/opensearch/vpc_endpoint.go | 77 ++++++++++++++++++ .../service/opensearch/vpc_endpoint_test.go | 79 +++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 internal/service/opensearch/exports_test.go diff --git a/internal/service/opensearch/exports_test.go b/internal/service/opensearch/exports_test.go new file mode 100644 index 000000000000..35455a2a6424 --- /dev/null +++ b/internal/service/opensearch/exports_test.go @@ -0,0 +1,9 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package opensearch + +// Exports for use in tests only. +var ( + VPCEndpointsError = vpcEndpointsError +) diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index c19af5bdf9b9..8064a8c2813d 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -5,6 +5,7 @@ package opensearch import ( "context" + "errors" "fmt" "log" "time" @@ -17,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -163,6 +165,7 @@ func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta in return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) } + func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) @@ -183,6 +186,80 @@ func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta return nil } +type vpcEndpointNotFoundError struct { + apiError error +} + +func (e *vpcEndpointNotFoundError) Error() string { + if e.apiError != nil { + return e.apiError.Error() + } + + return "VPC endpoint not found" +} + +func (e *vpcEndpointNotFoundError) Is(err error) bool { + _, ok := err.(*vpcEndpointNotFoundError) //nolint:errorlint // Explicitly does *not* match down the error tree + return ok +} + +func (e *vpcEndpointNotFoundError) As(target any) bool { + t, ok := target.(**retry.NotFoundError) + if !ok { + return false + } + + *t = &retry.NotFoundError{ + Message: e.Error(), + } + + return true +} + +func vpcEndpointError(apiObject *opensearchservice.VpcEndpointError) error { + if apiObject == nil { + return nil + } + + errorCode := aws.StringValue(apiObject.ErrorCode) + innerError := fmt.Errorf("%s: %s", errorCode, aws.StringValue(apiObject.ErrorMessage)) + err := fmt.Errorf("%s: %w", aws.StringValue(apiObject.VpcEndpointId), innerError) + + if errorCode == opensearchservice.VpcEndpointErrorCodeEndpointNotFound { + err = &vpcEndpointNotFoundError{apiError: err} + } + + return err +} + +func vpcEndpointsError(apiObjects []*opensearchservice.VpcEndpointError) error { + var errs []error + + for _, apiObject := range apiObjects { + errs = append(errs, vpcEndpointError(apiObject)) + } + + return errors.Join(errs...) +} + +func findVPCEndpoints(ctx context.Context, conn *opensearchservice.OpenSearchService, input *opensearchservice.DescribeVpcEndpointsInput) ([]*opensearchservice.VpcEndpoint, error) { + output, err := conn.DescribeVpcEndpointsWithContext(ctx, input) + + if err != nil { + return nil, err + } + + if output == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + if errs := output.VpcEndpointErrors; len(errs) > 0 { + return nil, vpcEndpointsError(errs) + } + + return output.VpcEndpoints, nil +} + func vpcEndpointRefreshState(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { resp, err := conn.DescribeVpcEndpointsWithContext(ctx, &opensearchservice.DescribeVpcEndpointsInput{ diff --git a/internal/service/opensearch/vpc_endpoint_test.go b/internal/service/opensearch/vpc_endpoint_test.go index a3469e2270e3..cd496c194f12 100644 --- a/internal/service/opensearch/vpc_endpoint_test.go +++ b/internal/service/opensearch/vpc_endpoint_test.go @@ -7,13 +7,92 @@ import ( "fmt" "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/opensearchservice" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" tfopensearch "github.com/hashicorp/terraform-provider-aws/internal/service/opensearch" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) +func TestVPCEndpointErrorsNotFound(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + apiObjects []*opensearchservice.VpcEndpointError + notFound bool + }{ + { + name: "nil input", + }, + { + name: "slice of nil input", + apiObjects: []*opensearchservice.VpcEndpointError{nil, nil}, + }, + { + name: "single SERVER_ERROR", + apiObjects: []*opensearchservice.VpcEndpointError{&opensearchservice.VpcEndpointError{ + ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), + ErrorMessage: aws.String("fail"), + VpcEndpointId: aws.String("aos-12345678"), + }}, + }, + { + name: "single ENDPOINT_NOT_FOUND", + apiObjects: []*opensearchservice.VpcEndpointError{&opensearchservice.VpcEndpointError{ + ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeEndpointNotFound), + ErrorMessage: aws.String("Endpoint does not exist"), + VpcEndpointId: aws.String("aos-12345678"), + }}, + notFound: true, + }, + { + name: "no ENDPOINT_NOT_FOUND in many", + apiObjects: []*opensearchservice.VpcEndpointError{ + &opensearchservice.VpcEndpointError{ + ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), + ErrorMessage: aws.String("fail"), + VpcEndpointId: aws.String("aos-abcd0123"), + }, + &opensearchservice.VpcEndpointError{ + ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), + ErrorMessage: aws.String("crash"), + VpcEndpointId: aws.String("aos-12345678"), + }, + }, + }, + { + name: "single ENDPOINT_NOT_FOUND in many", + apiObjects: []*opensearchservice.VpcEndpointError{ + &opensearchservice.VpcEndpointError{ + ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), + ErrorMessage: aws.String("fail"), + VpcEndpointId: aws.String("aos-abcd0123"), + }, + &opensearchservice.VpcEndpointError{ + ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeEndpointNotFound), + ErrorMessage: aws.String("Endpoint does not exist"), + VpcEndpointId: aws.String("aos-12345678"), + }, + }, + notFound: true, + }, + } + + for _, testCase := range testCases { + testCase := testCase + t.Run(testCase.name, func(t *testing.T) { + t.Parallel() + + if got, want := tfresource.NotFound(tfopensearch.VPCEndpointsError(testCase.apiObjects)), testCase.notFound; got != want { + t.Errorf("NotFound = %v, want %v", got, want) + } + }) + } +} + func TestAccOpenSearchVPCEndpoint_basic(t *testing.T) { ctx := acctest.Context(t) var domain opensearchservice.DomainStatus From f12aa3c294de3490a329c7bb55249e6d20bc4599 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 16:54:17 -0400 Subject: [PATCH 39/46] r/aws_opensearch_vpc_endpoint: Tidy up resource Delete. --- internal/service/opensearch/vpc_endpoint.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index 8064a8c2813d..080e973acaeb 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -167,23 +167,25 @@ func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta in } func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) - req := &opensearchservice.DeleteVpcEndpointInput{ + log.Printf("[DEBUG] Deleting OpenSearch VPC Endpoint: %s", d.Id()) + _, err := conn.DeleteVpcEndpointWithContext(ctx, &opensearchservice.DeleteVpcEndpointInput{ VpcEndpointId: aws.String(d.Id()), - } - - _, err := conn.DeleteVpcEndpointWithContext(ctx, req) + }) - if tfawserr.ErrCodeEquals(err, "ResourceNotFoundException") { - return nil + if tfawserr.ErrCodeEquals(err, opensearchservice.ErrCodeResourceNotFoundException) { + return diags } if err != nil { - return diag.Errorf("deleting vpc endpoint (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting OpenSearch VPC Endpoint (%s): %s", d.Id(), err) } - return nil + // TODO: Wait for delete. + + return diags } type vpcEndpointNotFoundError struct { From 86929f3ad4c357ef2f3c77ad64d02b20dfed133f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 17:10:46 -0400 Subject: [PATCH 40/46] r/aws_opensearch_vpc_endpoint: Tidy up resource Read. --- internal/service/opensearch/exports_test.go | 3 +- internal/service/opensearch/flex.go | 19 ----- internal/service/opensearch/vpc_endpoint.go | 75 +++++++++++++++---- .../r/opensearch_vpc_endpoint.html.markdown | 3 +- 4 files changed, 63 insertions(+), 37 deletions(-) diff --git a/internal/service/opensearch/exports_test.go b/internal/service/opensearch/exports_test.go index 35455a2a6424..73459f63ae7b 100644 --- a/internal/service/opensearch/exports_test.go +++ b/internal/service/opensearch/exports_test.go @@ -5,5 +5,6 @@ package opensearch // Exports for use in tests only. var ( - VPCEndpointsError = vpcEndpointsError + FindVPCEndpointByID = findVPCEndpointByID + VPCEndpointsError = vpcEndpointsError ) diff --git a/internal/service/opensearch/flex.go b/internal/service/opensearch/flex.go index 27224b04ea99..6283cf970c7d 100644 --- a/internal/service/opensearch/flex.go +++ b/internal/service/opensearch/flex.go @@ -215,22 +215,3 @@ func flattenSnapshotOptions(snapshotOptions *opensearchservice.SnapshotOptions) return []map[string]interface{}{m} } - -func flattenVPCDerivedInfo(o *opensearchservice.VPCDerivedInfo) []map[string]interface{} { - m := map[string]interface{}{} - - if o.AvailabilityZones != nil { - m["availability_zones"] = flex.FlattenStringSet(o.AvailabilityZones) - } - if o.SecurityGroupIds != nil { - m["security_group_ids"] = flex.FlattenStringSet(o.SecurityGroupIds) - } - if o.SubnetIds != nil { - m["subnet_ids"] = flex.FlattenStringSet(o.SubnetIds) - } - if o.VPCId != nil { - m["vpc_id"] = aws.StringValue(o.VPCId) - } - - return []map[string]interface{}{m} -} diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index 080e973acaeb..dc7780cf297a 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -41,10 +41,6 @@ func ResourceVPCEndpoint() *schema.Resource { }, Schema: map[string]*schema.Schema{ - "connection_status": { - Type: schema.TypeString, - Computed: true, - }, "domain_arn": { Type: schema.TypeString, Required: true, @@ -109,26 +105,31 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta } func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) - endpointRaw, status, err := vpcEndpointRefreshState(ctx, conn, d.Id())() + endpoint, err := findVPCEndpointByID(ctx, conn, d.Id()) - if err != nil { - return diag.Errorf("reading vpc endpoint: %s", err) + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] OpenSearch VPC Endpoint (%s) not found, removing from state", d.Id()) + d.SetId("") + return diags } - endpoint := endpointRaw.(*opensearchservice.VpcEndpoint) - log.Printf("[DEBUG] vpc endpoint response: %#v", endpoint) + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading OpenSearch VPC Endpoint (%s): %s", d.Id(), err) + } - d.Set("connection_status", status) d.Set("domain_arn", endpoint.DomainArn) - - if endpoint.VpcOptions == nil { - return diag.Errorf("reading vpc endpoint vpc options ") + if endpoint.VpcOptions != nil { + if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(endpoint.VpcOptions)}); err != nil { + return diag.Errorf("setting vpc_options: %s", err) + } + } else { + d.Set("vpc_options", nil) } - d.Set("vpc_options", flattenVPCDerivedInfo(endpoint.VpcOptions)) - return nil + return diags } func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -244,6 +245,24 @@ func vpcEndpointsError(apiObjects []*opensearchservice.VpcEndpointError) error { return errors.Join(errs...) } +func findVPCEndpointByID(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) (*opensearchservice.VpcEndpoint, error) { + input := &opensearchservice.DescribeVpcEndpointsInput{ + VpcEndpointIds: aws.StringSlice([]string{id}), + } + + return findVPCEndpoint(ctx, conn, input) +} + +func findVPCEndpoint(ctx context.Context, conn *opensearchservice.OpenSearchService, input *opensearchservice.DescribeVpcEndpointsInput) (*opensearchservice.VpcEndpoint, error) { + output, err := findVPCEndpoints(ctx, conn, input) + + if err != nil { + return nil, err + } + + return tfresource.AssertSinglePtrResult(output) +} + func findVPCEndpoints(ctx context.Context, conn *opensearchservice.OpenSearchService, input *opensearchservice.DescribeVpcEndpointsInput) ([]*opensearchservice.VpcEndpoint, error) { output, err := conn.DescribeVpcEndpointsWithContext(ctx, input) @@ -324,3 +343,29 @@ func vpcEndpointWaitUntilUpdate(ctx context.Context, conn *opensearchservice.Ope } return nil } + +func flattenVPCDerivedInfo(apiObject *opensearchservice.VPCDerivedInfo) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{} + + if v := apiObject.AvailabilityZones; v != nil { + tfMap["availability_zones"] = aws.StringValueSlice(v) + } + + if v := apiObject.SecurityGroupIds; v != nil { + tfMap["security_group_ids"] = aws.StringValueSlice(v) + } + + if v := apiObject.SubnetIds; v != nil { + tfMap["subnet_ids"] = aws.StringValueSlice(v) + } + + if v := apiObject.VPCId; v != nil { + tfMap["vpc_id"] = aws.StringValue(v) + } + + return tfMap +} diff --git a/website/docs/r/opensearch_vpc_endpoint.html.markdown b/website/docs/r/opensearch_vpc_endpoint.html.markdown index dba59cb0fa58..01826854ac1b 100644 --- a/website/docs/r/opensearch_vpc_endpoint.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint.html.markdown @@ -8,7 +8,7 @@ description: |- # Resource: aws_opensearch_vpc_endpoint -Manages an [AWS Opensearch VPC Endpoint](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_CreateVpcEndpoint.html). Creates an Amazon OpenSearch Service-managed VPC endpoint.. +Manages an [AWS Opensearch VPC Endpoint](https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_CreateVpcEndpoint.html). Creates an Amazon OpenSearch Service-managed VPC endpoint. ## Example Usage @@ -43,7 +43,6 @@ The following arguments are supported: This resource exports the following attributes in addition to the arguments above: * `id` - The connection endpoint ID for connecting to the domain. -* `connection_status` - The current status of the endpoint. ## Timeouts From 634f268ea387fbda6288a07af0697915823598fa Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 17:15:37 -0400 Subject: [PATCH 41/46] r/aws_opensearch_vpc_endpoint: Tidy up resource Update. --- internal/service/opensearch/flex.go | 15 ------- internal/service/opensearch/vpc_endpoint.go | 44 ++++++++++++--------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/internal/service/opensearch/flex.go b/internal/service/opensearch/flex.go index 6283cf970c7d..99ed40bd86d0 100644 --- a/internal/service/opensearch/flex.go +++ b/internal/service/opensearch/flex.go @@ -6,8 +6,6 @@ package opensearch import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/opensearchservice" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-aws/internal/flex" ) func expandCognitoOptions(c []interface{}) *opensearchservice.CognitoOptions { @@ -113,19 +111,6 @@ func expandEncryptAtRestOptions(m map[string]interface{}) *opensearchservice.Enc return &options } -func expandVPCOptions(m map[string]interface{}) *opensearchservice.VPCOptions { - options := opensearchservice.VPCOptions{} - - if v, ok := m["security_group_ids"]; ok { - options.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) - } - if v, ok := m["subnet_ids"]; ok { - options.SubnetIds = flex.ExpandStringSet(v.(*schema.Set)) - } - - return &options -} - func flattenCognitoOptions(c *opensearchservice.CognitoOptions) []map[string]interface{} { m := map[string]interface{}{} diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index dc7780cf297a..c0f7ec05d34c 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -27,7 +28,7 @@ func ResourceVPCEndpoint() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceVPCEndpointCreate, ReadWithoutTimeout: resourceVPCEndpointRead, - UpdateWithoutTimeout: resourceVPCEndpointPut, + UpdateWithoutTimeout: resourceVPCEndpointUpdate, DeleteWithoutTimeout: resourceVPCEndpointDelete, Importer: &schema.ResourceImporter{ @@ -132,36 +133,23 @@ func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta i return diags } -func resourceVPCEndpointPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVPCEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) - // Update the VPC Endpoint input := &opensearchservice.UpdateVpcEndpointInput{ + VpcOptions: expandVPCOptions(d.Get("vpc_options").([]interface{})[0].(map[string]interface{})), VpcEndpointId: aws.String(d.Id()), } - if v, ok := d.GetOk("vpc_options"); ok { - options := v.([]interface{}) - if options[0] == nil { - return sdkdiag.AppendErrorf(diags, "At least one field is expected inside vpc_options") - } - - s := options[0].(map[string]interface{}) - input.VpcOptions = expandVPCOptions(s) - } - - log.Printf("[DEBUG] Updating vpc endpoint %s", input) - _, err := conn.UpdateVpcEndpointWithContext(ctx, input) if err != nil { - return sdkdiag.AppendErrorf(diags, "updating vpc endpoint (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating OpenSearch VPC Endpoint (%s): %s", d.Id(), err) } - err = vpcEndpointWaitUntilUpdate(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)) - if err != nil { - return diag.Errorf("waiting for vpc endpoint to become active: %s", err) + if err := vpcEndpointWaitUntilUpdate(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch VPC Endpoint (%s) update: %s", d.Id(), err) } return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) @@ -344,6 +332,24 @@ func vpcEndpointWaitUntilUpdate(ctx context.Context, conn *opensearchservice.Ope return nil } +func expandVPCOptions(tfMap map[string]interface{}) *opensearchservice.VPCOptions { + if tfMap == nil { + return nil + } + + apiObject := &opensearchservice.VPCOptions{} + + if v, ok := tfMap["security_group_ids"].(*schema.Set); ok && v.Len() > 0 { + apiObject.SecurityGroupIds = flex.ExpandStringSet(v) + } + + if v, ok := tfMap["subnet_ids"].(*schema.Set); ok && v.Len() > 0 { + apiObject.SubnetIds = flex.ExpandStringSet(v) + } + + return apiObject +} + func flattenVPCDerivedInfo(apiObject *opensearchservice.VPCDerivedInfo) map[string]interface{} { if apiObject == nil { return nil From a05d4bfb9040e395722761d0da3eb65da600d336 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 17:19:36 -0400 Subject: [PATCH 42/46] r/aws_opensearch_vpc_endpoint: Add 'endpoint' attribute. --- internal/service/opensearch/vpc_endpoint.go | 5 +++++ website/docs/r/opensearch_vpc_endpoint.html.markdown | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index c0f7ec05d34c..66098c6abf1e 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -48,6 +48,10 @@ func ResourceVPCEndpoint() *schema.Resource { ForceNew: true, ValidateFunc: verify.ValidARN, }, + "endpoint": { + Type: schema.TypeString, + Computed: true, + }, "vpc_options": { Type: schema.TypeList, Required: true, @@ -122,6 +126,7 @@ func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta i } d.Set("domain_arn", endpoint.DomainArn) + d.Set("endpoint", endpoint.Endpoint) if endpoint.VpcOptions != nil { if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(endpoint.VpcOptions)}); err != nil { return diag.Errorf("setting vpc_options: %s", err) diff --git a/website/docs/r/opensearch_vpc_endpoint.html.markdown b/website/docs/r/opensearch_vpc_endpoint.html.markdown index 01826854ac1b..2c812e3b1de6 100644 --- a/website/docs/r/opensearch_vpc_endpoint.html.markdown +++ b/website/docs/r/opensearch_vpc_endpoint.html.markdown @@ -42,7 +42,8 @@ The following arguments are supported: This resource exports the following attributes in addition to the arguments above: -* `id` - The connection endpoint ID for connecting to the domain. +* `id` - The unique identifier of the endpoint. +* `endpoint` - The connection endpoint ID for connecting to the domain. ## Timeouts From fe52f6b278923a9519efeb20bf0b7d05b22bf74b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 17:25:15 -0400 Subject: [PATCH 43/46] r/aws_opensearch_vpc_endpoint: Tidy up waiters. --- internal/service/opensearch/vpc_endpoint.go | 86 ++++++++++----------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index 66098c6abf1e..283d05a734f8 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -102,7 +102,7 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta d.SetId(aws.StringValue(output.VpcEndpoint.VpcEndpointId)) - if err := vpcEndpointWaitUntilActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if err := waitVPCEndpointCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch VPC Endpoint (%s) create: %s", d.Id(), err) } @@ -153,7 +153,7 @@ func resourceVPCEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "updating OpenSearch VPC Endpoint (%s): %s", d.Id(), err) } - if err := vpcEndpointWaitUntilUpdate(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := waitVPCEndpointUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch VPC Endpoint (%s) update: %s", d.Id(), err) } @@ -177,7 +177,9 @@ func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "deleting OpenSearch VPC Endpoint (%s): %s", d.Id(), err) } - // TODO: Wait for delete. + if err := waitVPCEndpointDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch VPC Endpoint (%s) delete: %s", d.Id(), err) + } return diags } @@ -274,67 +276,59 @@ func findVPCEndpoints(ctx context.Context, conn *opensearchservice.OpenSearchSer return output.VpcEndpoints, nil } -func vpcEndpointRefreshState(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) retry.StateRefreshFunc { +func statusVPCEndpoint(ctx context.Context, conn *opensearchservice.OpenSearchService, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - resp, err := conn.DescribeVpcEndpointsWithContext(ctx, &opensearchservice.DescribeVpcEndpointsInput{ - VpcEndpointIds: []*string{aws.String(id)}, - }) - if err != nil { - return nil, "", err - } + output, err := findVPCEndpointByID(ctx, conn, id) - if resp == nil || resp.VpcEndpoints == nil || - len(resp.VpcEndpoints) == 0 || resp.VpcEndpoints[0] == nil { - // Sometimes AWS just has consistency issues and doesn't see - // our connection yet. Return an empty state. + if tfresource.NotFound(err) { return nil, "", nil } - endpoint := resp.VpcEndpoints[0] - if endpoint.Status == nil { - // Sometimes AWS just has consistency issues and doesn't see - // our connection yet. Return an empty state. - return nil, "", nil + + if err != nil { + return nil, "", err } - statusCode := aws.StringValue(endpoint.Status) - return endpoint, statusCode, nil + return output, aws.StringValue(output.Status), nil } } -func vpcEndpointWaitUntilActive(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { - log.Printf("[DEBUG] Waiting for VPC Endpoint (%s) to become available.", id) +func waitVPCEndpointCreated(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ - Pending: []string{ - opensearchservice.VpcEndpointStatusCreating, - }, - Target: []string{ - opensearchservice.VpcEndpointStatusActive, - }, - Refresh: vpcEndpointRefreshState(ctx, conn, id), + Pending: []string{opensearchservice.VpcEndpointStatusCreating}, + Target: []string{opensearchservice.VpcEndpointStatusActive}, + Refresh: statusVPCEndpoint(ctx, conn, id), Timeout: timeout, } - if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for VPC Endpoint (%s) to become available: %s", id, err) - } - return nil + + _, err := stateConf.WaitForStateContext(ctx) + + return err } -func vpcEndpointWaitUntilUpdate(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { - log.Printf("[DEBUG] Waiting for VPC Endpoint (%s) to become available.", id) +func waitVPCEndpointUpdated(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ - Pending: []string{ - opensearchservice.VpcEndpointStatusUpdating, - }, - Target: []string{ - opensearchservice.VpcEndpointStatusActive, - }, - Refresh: vpcEndpointRefreshState(ctx, conn, id), + Pending: []string{opensearchservice.VpcEndpointStatusUpdating}, + Target: []string{opensearchservice.VpcEndpointStatusActive}, + Refresh: statusVPCEndpoint(ctx, conn, id), Timeout: timeout, } - if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for VPC Endpoint (%s) to become available: %s", id, err) + + _, err := stateConf.WaitForStateContext(ctx) + + return err +} + +func waitVPCEndpointDeleted(ctx context.Context, conn *opensearchservice.OpenSearchService, id string, timeout time.Duration) error { + stateConf := &retry.StateChangeConf{ + Pending: []string{opensearchservice.VpcEndpointStatusDeleting}, + Target: []string{}, + Refresh: statusVPCEndpoint(ctx, conn, id), + Timeout: timeout, } - return nil + + _, err := stateConf.WaitForStateContext(ctx) + + return err } func expandVPCOptions(tfMap map[string]interface{}) *opensearchservice.VPCOptions { From be9de7228852be00f3db493baad54fce94e86a24 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 17:46:12 -0400 Subject: [PATCH 44/46] r/aws_opensearch_vpc_endpoint: Tidy up acceptance tests. --- .../service/opensearch/vpc_endpoint_test.go | 247 +++++++++--------- 1 file changed, 128 insertions(+), 119 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_test.go b/internal/service/opensearch/vpc_endpoint_test.go index cd496c194f12..176cf16399e8 100644 --- a/internal/service/opensearch/vpc_endpoint_test.go +++ b/internal/service/opensearch/vpc_endpoint_test.go @@ -4,6 +4,7 @@ package opensearch_test import ( + "context" "fmt" "testing" @@ -11,7 +12,9 @@ import ( "github.com/aws/aws-sdk-go/service/opensearchservice" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" tfopensearch "github.com/hashicorp/terraform-provider-aws/internal/service/opensearch" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -33,7 +36,7 @@ func TestVPCEndpointErrorsNotFound(t *testing.T) { }, { name: "single SERVER_ERROR", - apiObjects: []*opensearchservice.VpcEndpointError{&opensearchservice.VpcEndpointError{ + apiObjects: []*opensearchservice.VpcEndpointError{{ ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), ErrorMessage: aws.String("fail"), VpcEndpointId: aws.String("aos-12345678"), @@ -41,7 +44,7 @@ func TestVPCEndpointErrorsNotFound(t *testing.T) { }, { name: "single ENDPOINT_NOT_FOUND", - apiObjects: []*opensearchservice.VpcEndpointError{&opensearchservice.VpcEndpointError{ + apiObjects: []*opensearchservice.VpcEndpointError{{ ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeEndpointNotFound), ErrorMessage: aws.String("Endpoint does not exist"), VpcEndpointId: aws.String("aos-12345678"), @@ -51,12 +54,12 @@ func TestVPCEndpointErrorsNotFound(t *testing.T) { { name: "no ENDPOINT_NOT_FOUND in many", apiObjects: []*opensearchservice.VpcEndpointError{ - &opensearchservice.VpcEndpointError{ + { ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), ErrorMessage: aws.String("fail"), VpcEndpointId: aws.String("aos-abcd0123"), }, - &opensearchservice.VpcEndpointError{ + { ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), ErrorMessage: aws.String("crash"), VpcEndpointId: aws.String("aos-12345678"), @@ -66,12 +69,12 @@ func TestVPCEndpointErrorsNotFound(t *testing.T) { { name: "single ENDPOINT_NOT_FOUND in many", apiObjects: []*opensearchservice.VpcEndpointError{ - &opensearchservice.VpcEndpointError{ + { ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeServerError), ErrorMessage: aws.String("fail"), VpcEndpointId: aws.String("aos-abcd0123"), }, - &opensearchservice.VpcEndpointError{ + { ErrorCode: aws.String(opensearchservice.VpcEndpointErrorCodeEndpointNotFound), ErrorMessage: aws.String("Endpoint does not exist"), VpcEndpointId: aws.String("aos-12345678"), @@ -95,22 +98,31 @@ func TestVPCEndpointErrorsNotFound(t *testing.T) { func TestAccOpenSearchVPCEndpoint_basic(t *testing.T) { ctx := acctest.Context(t) - var domain opensearchservice.DomainStatus - ri := sdkacctest.RandString(10) - name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint.foo" + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var v opensearchservice.VpcEndpoint + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + domainName := testAccRandomDomainName() + resourceName := "aws_opensearch_vpc_endpoint.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckDomainDestroy(ctx), + CheckDestroy: testAccCheckVPCEndpointDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccVPCEndpointConfig(name), - Check: resource.ComposeTestCheckFunc( - testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), - resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), + Config: testAccVPCEndpointConfig_basic(rName, domainName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckVPCEndpointExists(ctx, resourceName, &v), + resource.TestCheckResourceAttrSet(resourceName, "endpoint"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.availability_zones.#", "2"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "1"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.subnet_ids.#", "2"), + resource.TestCheckResourceAttrSet(resourceName, "vpc_options.0.vpc_id"), ), }, { @@ -122,6 +134,36 @@ func TestAccOpenSearchVPCEndpoint_basic(t *testing.T) { }) } +func TestAccOpenSearchVPCEndpoint_disappears(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var v opensearchservice.VpcEndpoint + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + domainName := testAccRandomDomainName() + resourceName := "aws_opensearch_vpc_endpoint.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckVPCEndpointDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCEndpointConfig_basic(rName, domainName), + Check: resource.ComposeTestCheckFunc( + testAccCheckVPCEndpointExists(ctx, resourceName, &v), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfopensearch.ResourceVPCEndpoint(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +/* func TestAccOpenSearchVPCEndpoint_update(t *testing.T) { ctx := acctest.Context(t) var domain opensearchservice.DomainStatus @@ -159,71 +201,68 @@ func TestAccOpenSearchVPCEndpoint_update(t *testing.T) { }, }) } +*/ -func TestAccOpenSearchVPCEndpoint_disappears(t *testing.T) { - ctx := acctest.Context(t) - var domain opensearchservice.DomainStatus - ri := sdkacctest.RandString(10) - name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint.foo" +func testAccCheckVPCEndpointExists(ctx context.Context, n string, v *opensearchservice.VpcEndpoint) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckDomainDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccVPCEndpointConfig(name), - Check: resource.ComposeTestCheckFunc( - testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), - acctest.CheckResourceDisappears(ctx, acctest.Provider, tfopensearch.ResourceVPCEndpoint(), resourceName), - ), - }, - }, - }) -} + conn := acctest.Provider.Meta().(*conns.AWSClient).OpenSearchConn(ctx) -func testAccVPCEndpointConfig(name string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" + output, err := tfopensearch.FindVPCEndpointByID(ctx, conn, rs.Primary.ID) - tags = { - Name = %[1]q - } -} + if err != nil { + return err + } -resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" + *v = *output - tags = { - Name = %[1]q - } + return nil + } } -resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" +func testAccCheckVPCEndpointDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_opensearch_vpc_endpoint" { + continue + } - tags = { - Name = %[1]q - } + conn := acctest.Provider.Meta().(*conns.AWSClient).OpenSearchConn(ctx) + + _, err := tfopensearch.FindVPCEndpointByID(ctx, conn, rs.Primary.ID) + + if tfresource.NotFound(err) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("OpenSearch VPC Endpoint %s still exists", rs.Primary.ID) + } + + return nil + } } +func testAccVPCEndpointConfig_base(rName, domainName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(` resource "aws_security_group" "test" { + name = %[1]q vpc_id = aws_vpc.test.id -} -resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id + tags = { + Name = %[1]q + } } -resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q +resource "aws_opensearch_domain" "test" { + domain_name = %[2]q ebs_options { ebs_enabled = true @@ -233,89 +272,59 @@ resource "aws_opensearch_domain" "domain_1" { cluster_config { instance_count = 2 zone_awareness_enabled = true - instance_type = "t3.small.search" + instance_type = "t2.small.search" } - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} - -resource "aws_opensearch_vpc_endpoint" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { security_group_ids = [aws_security_group.test.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + subnet_ids = aws_subnet.test[*].id } } -`, name)) -} -func testAccVPCEndpointConfigUpdate(name string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "192.168.0.0/22" +resource "aws_vpc" "client" { + cidr_block = "10.0.0.0/16" + + enable_dns_support = true + enable_dns_hostnames = true tags = { Name = %[1]q } } -resource "aws_subnet" "test" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "192.168.0.0/24" +resource "aws_subnet" "client" { + count = 2 + + vpc_id = aws_vpc.client.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = cidrsubnet(aws_vpc.client.cidr_block, 8, count.index) tags = { Name = %[1]q } } -resource "aws_subnet" "test2" { - vpc_id = aws_vpc.test.id - availability_zone = data.aws_availability_zones.available.names[1] - cidr_block = "192.168.1.0/24" +resource "aws_security_group" "client" { + count = 2 + + name = "%[1]s-client-${count.index}" + vpc_id = aws_vpc.client.id tags = { Name = %[1]q } } - -resource "aws_security_group" "test" { - vpc_id = aws_vpc.test.id -} - -resource "aws_security_group" "test2" { - vpc_id = aws_vpc.test.id +`, rName, domainName)) } -resource "aws_opensearch_domain" "domain_1" { - domain_name = %[1]q - - ebs_options { - ebs_enabled = true - volume_size = 10 - } - - cluster_config { - instance_count = 2 - zone_awareness_enabled = true - instance_type = "t3.small.search" - } - - vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] - } -} +func testAccVPCEndpointConfig_basic(rName, domainName string) string { + return acctest.ConfigCompose(testAccVPCEndpointConfig_base(rName, domainName), ` +resource "aws_opensearch_vpc_endpoint" "test" { + domain_arn = aws_opensearch_domain.test.arn -resource "aws_opensearch_vpc_endpoint" "foo" { - domain_arn = aws_opensearch_domain.domain_1.arn vpc_options { - security_group_ids = [aws_security_group.test.id, aws_security_group.test2.id] - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + subnet_ids = aws_subnet.client[*].id } } -`, name)) +`) } From c8b16985fdf45c31ff1315f799419caba40187bc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 18:20:11 -0400 Subject: [PATCH 45/46] Fix callers of 'flattenVPCDerivedInfo'. --- internal/service/opensearch/domain.go | 2 +- .../service/opensearch/domain_data_source.go | 2 +- internal/service/opensearch/flex.go | 46 +++++++++++++++++++ internal/service/opensearch/vpc_endpoint.go | 45 ------------------ 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/internal/service/opensearch/domain.go b/internal/service/opensearch/domain.go index 6e10f2cf16f0..272693417ed0 100644 --- a/internal/service/opensearch/domain.go +++ b/internal/service/opensearch/domain.go @@ -896,7 +896,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf } if ds.VPCOptions != nil { - if err := d.Set("vpc_options", flattenVPCDerivedInfo(ds.VPCOptions)); err != nil { + if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(ds.VPCOptions)}); err != nil { return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err) } diff --git a/internal/service/opensearch/domain_data_source.go b/internal/service/opensearch/domain_data_source.go index 5068ba647146..027754316178 100644 --- a/internal/service/opensearch/domain_data_source.go +++ b/internal/service/opensearch/domain_data_source.go @@ -466,7 +466,7 @@ func dataSourceDomainRead(ctx context.Context, d *schema.ResourceData, meta inte } if ds.VPCOptions != nil { - if err := d.Set("vpc_options", flattenVPCDerivedInfo(ds.VPCOptions)); err != nil { + if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(ds.VPCOptions)}); err != nil { return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err) } diff --git a/internal/service/opensearch/flex.go b/internal/service/opensearch/flex.go index 99ed40bd86d0..e9d3ecbede94 100644 --- a/internal/service/opensearch/flex.go +++ b/internal/service/opensearch/flex.go @@ -6,6 +6,8 @@ package opensearch import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/opensearchservice" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/flex" ) func expandCognitoOptions(c []interface{}) *opensearchservice.CognitoOptions { @@ -200,3 +202,47 @@ func flattenSnapshotOptions(snapshotOptions *opensearchservice.SnapshotOptions) return []map[string]interface{}{m} } + +func expandVPCOptions(tfMap map[string]interface{}) *opensearchservice.VPCOptions { + if tfMap == nil { + return nil + } + + apiObject := &opensearchservice.VPCOptions{} + + if v, ok := tfMap["security_group_ids"].(*schema.Set); ok && v.Len() > 0 { + apiObject.SecurityGroupIds = flex.ExpandStringSet(v) + } + + if v, ok := tfMap["subnet_ids"].(*schema.Set); ok && v.Len() > 0 { + apiObject.SubnetIds = flex.ExpandStringSet(v) + } + + return apiObject +} + +func flattenVPCDerivedInfo(apiObject *opensearchservice.VPCDerivedInfo) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{} + + if v := apiObject.AvailabilityZones; v != nil { + tfMap["availability_zones"] = aws.StringValueSlice(v) + } + + if v := apiObject.SecurityGroupIds; v != nil { + tfMap["security_group_ids"] = aws.StringValueSlice(v) + } + + if v := apiObject.SubnetIds; v != nil { + tfMap["subnet_ids"] = aws.StringValueSlice(v) + } + + if v := apiObject.VPCId; v != nil { + tfMap["vpc_id"] = aws.StringValue(v) + } + + return tfMap +} diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index 283d05a734f8..100f10251d95 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -18,7 +18,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" - "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -330,47 +329,3 @@ func waitVPCEndpointDeleted(ctx context.Context, conn *opensearchservice.OpenSea return err } - -func expandVPCOptions(tfMap map[string]interface{}) *opensearchservice.VPCOptions { - if tfMap == nil { - return nil - } - - apiObject := &opensearchservice.VPCOptions{} - - if v, ok := tfMap["security_group_ids"].(*schema.Set); ok && v.Len() > 0 { - apiObject.SecurityGroupIds = flex.ExpandStringSet(v) - } - - if v, ok := tfMap["subnet_ids"].(*schema.Set); ok && v.Len() > 0 { - apiObject.SubnetIds = flex.ExpandStringSet(v) - } - - return apiObject -} - -func flattenVPCDerivedInfo(apiObject *opensearchservice.VPCDerivedInfo) map[string]interface{} { - if apiObject == nil { - return nil - } - - tfMap := map[string]interface{}{} - - if v := apiObject.AvailabilityZones; v != nil { - tfMap["availability_zones"] = aws.StringValueSlice(v) - } - - if v := apiObject.SecurityGroupIds; v != nil { - tfMap["security_group_ids"] = aws.StringValueSlice(v) - } - - if v := apiObject.SubnetIds; v != nil { - tfMap["subnet_ids"] = aws.StringValueSlice(v) - } - - if v := apiObject.VPCId; v != nil { - tfMap["vpc_id"] = aws.StringValue(v) - } - - return tfMap -} From 1bed608776a9fd6e83b71903778d9a72863e9919 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 15 Aug 2023 19:20:37 -0400 Subject: [PATCH 46/46] Add 'TestAccOpenSearchVPCEndpoint_update'. --- .../service/opensearch/vpc_endpoint_test.go | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/internal/service/opensearch/vpc_endpoint_test.go b/internal/service/opensearch/vpc_endpoint_test.go index 176cf16399e8..427037d1fc53 100644 --- a/internal/service/opensearch/vpc_endpoint_test.go +++ b/internal/service/opensearch/vpc_endpoint_test.go @@ -163,45 +163,50 @@ func TestAccOpenSearchVPCEndpoint_disappears(t *testing.T) { }) } -/* func TestAccOpenSearchVPCEndpoint_update(t *testing.T) { ctx := acctest.Context(t) - var domain opensearchservice.DomainStatus - ri := sdkacctest.RandString(10) - name := fmt.Sprintf("tf-test-%s", ri) - resourceName := "aws_opensearch_vpc_endpoint.foo" + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var v opensearchservice.VpcEndpoint + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + domainName := testAccRandomDomainName() + resourceName := "aws_opensearch_vpc_endpoint.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckDomainDestroy(ctx), + CheckDestroy: testAccCheckVPCEndpointDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccVPCEndpointConfig(name), - Check: resource.ComposeTestCheckFunc( - testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), + Config: testAccVPCEndpointConfig_basic(rName, domainName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckVPCEndpointExists(ctx, resourceName, &v), + resource.TestCheckResourceAttrSet(resourceName, "endpoint"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.availability_zones.#", "2"), resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.subnet_ids.#", "2"), + resource.TestCheckResourceAttrSet(resourceName, "vpc_options.0.vpc_id"), ), }, { - Config: testAccVPCEndpointConfigUpdate(name), - Check: resource.ComposeTestCheckFunc( - testAccCheckDomainExists(ctx, "aws_opensearch_domain.domain_1", &domain), + Config: testAccVPCEndpointConfig_updated(rName, domainName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckVPCEndpointExists(ctx, resourceName, &v), + resource.TestCheckResourceAttrSet(resourceName, "endpoint"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.availability_zones.#", "2"), resource.TestCheckResourceAttr(resourceName, "vpc_options.0.security_group_ids.#", "2"), - resource.TestCheckResourceAttr(resourceName, "connection_status", "ACTIVE"), + resource.TestCheckResourceAttr(resourceName, "vpc_options.0.subnet_ids.#", "2"), + resource.TestCheckResourceAttrSet(resourceName, "vpc_options.0.vpc_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, }, }) } -*/ func testAccCheckVPCEndpointExists(ctx context.Context, n string, v *opensearchservice.VpcEndpoint) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -328,3 +333,16 @@ resource "aws_opensearch_vpc_endpoint" "test" { } `) } + +func testAccVPCEndpointConfig_updated(rName, domainName string) string { + return acctest.ConfigCompose(testAccVPCEndpointConfig_base(rName, domainName), ` +resource "aws_opensearch_vpc_endpoint" "test" { + domain_arn = aws_opensearch_domain.test.arn + + vpc_options { + subnet_ids = aws_subnet.client[*].id + security_group_ids = aws_security_group.client[*].id + } +} +`) +}