Skip to content

feat: add field for cross account support in endpoint groups for AGA #37269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/service/globalaccelerator/endpoint_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func resourceEndpointGroup() *schema.Resource {
Optional: true,
ValidateFunc: validation.IntBetween(0, 255),
},
"cross_account_attachment_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
},
},
},
Expand Down Expand Up @@ -383,6 +388,10 @@ func expandEndpointConfiguration(tfMap map[string]interface{}) *awstypes.Endpoin
apiObject.Weight = aws.Int32(int32(v))
}

if v, ok := tfMap["cross_account_attachment_arn"].(string); ok && v != "" {
apiObject.AttachmentArn = aws.String(v)
}

return apiObject
}

Expand Down
65 changes: 65 additions & 0 deletions internal/service/globalaccelerator/endpoint_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ func TestAccGlobalAcceleratorEndpointGroup_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "health_check_path", ""),
resource.TestCheckResourceAttr(resourceName, "health_check_port", "80"),
resource.TestCheckResourceAttr(resourceName, "health_check_protocol", "TCP"),
resource.TestCheckResourceAttr(resourceName, "cross_account_attachment_arn", ""),
acctest.MatchResourceAttrGlobalARN(resourceName, "listener_arn", "globalaccelerator", regexache.MustCompile(`accelerator/[^/]+/listener/[^/]+`)),
resource.TestCheckResourceAttr(resourceName, "port_override.#", "0"),
resource.TestCheckResourceAttr(resourceName, "threshold_count", "3"),
resource.TestCheckResourceAttr(resourceName, "traffic_dial_percentage", "100"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccGlobalAcceleratorEndpointGroup_crossAccount(t *testing.T) {
ctx := acctest.Context(t)
var v awstypes.EndpointGroup
resourceName := "aws_globalaccelerator_endpoint_group.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.GlobalAcceleratorServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckEndpointGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEndpointGroupConfig_crossAccount(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointGroupExists(ctx, resourceName, &v),
acctest.MatchResourceAttrGlobalARN(resourceName, "arn", "globalaccelerator", regexache.MustCompile(`accelerator/[^/]+/listener/[^/]+/endpoint-group/[^/]+`)),
resource.TestCheckResourceAttr(resourceName, "endpoint_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "endpoint_group_region", acctest.Region()),
resource.TestCheckResourceAttr(resourceName, "health_check_interval_seconds", "30"),
resource.TestCheckResourceAttr(resourceName, "health_check_path", ""),
resource.TestCheckResourceAttr(resourceName, "health_check_port", "80"),
resource.TestCheckResourceAttr(resourceName, "health_check_protocol", "TCP"),
resource.TestCheckResourceAttr(resourceName, "cross_account_attachment_arn", "arn:aws:elasticloadbalancing:us-west-1:111111111111:loadbalancer/net/nlb-01/8a6825aea9cdab43"),
acctest.MatchResourceAttrGlobalARN(resourceName, "listener_arn", "globalaccelerator", regexache.MustCompile(`accelerator/[^/]+/listener/[^/]+`)),
resource.TestCheckResourceAttr(resourceName, "port_override.#", "0"),
resource.TestCheckResourceAttr(resourceName, "threshold_count", "3"),
Expand Down Expand Up @@ -874,3 +914,28 @@ resource "aws_globalaccelerator_endpoint_group" "test" {
}
`, rName)
}

func testAccEndpointGroupConfig_crossAccount(rName string) string {
return fmt.Sprintf(`
resource "aws_globalaccelerator_accelerator" "test" {
name = %[1]q
ip_address_type = "IPV4"
enabled = false
}

resource "aws_globalaccelerator_listener" "test" {
accelerator_arn = aws_globalaccelerator_accelerator.test.id
protocol = "TCP"

port_range {
from_port = 80
to_port = 80
}
}

resource "aws_globalaccelerator_endpoint_group" "test" {
listener_arn = aws_globalaccelerator_listener.test.id
cross_account_attachment_arn = "arn:aws:elasticloadbalancing:us-west-1:111111111111:loadbalancer/net/nlb-01/8a6825aea9cdab43"
}
`, rName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Terraform will only perform drift detection of its value when present in a confi
**Note:** When client IP address preservation is enabled, the Global Accelerator service creates an EC2 Security Group in the VPC named `GlobalAccelerator` that must be deleted (potentially outside of Terraform) before the VPC will successfully delete. If this EC2 Security Group is not deleted, Terraform will retry the VPC deletion for a few minutes before reporting a `DependencyViolation` error. This cannot be resolved by re-running Terraform.
* `endpoint_id` - (Optional) An ID for the endpoint. If the endpoint is a Network Load Balancer or Application Load Balancer, this is the Amazon Resource Name (ARN) of the resource. If the endpoint is an Elastic IP address, this is the Elastic IP address allocation ID.
* `weight` - (Optional) The weight associated with the endpoint. When you add weights to endpoints, you configure AWS Global Accelerator to route traffic based on proportions that you specify.
* `cross_account_attachment_arn` - (Optional) An ARN of an exposed cross-account attachment. See the [AWS documentation](https://docs.aws.amazon.com/global-accelerator/latest/dg/cross-account-resources.html) for more details.

`port_override` supports the following arguments:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Terraform will only perform drift detection of its value when present in a confi
**Note:** When client IP address preservation is enabled, the Global Accelerator service creates an EC2 Security Group in the VPC named `GlobalAccelerator` that must be deleted (potentially outside of Terraform) before the VPC will successfully delete. If this EC2 Security Group is not deleted, Terraform will retry the VPC deletion for a few minutes before reporting a `DependencyViolation` error. This cannot be resolved by re-running Terraform.
* `endpoint_id` - (Optional) An ID for the endpoint. If the endpoint is a Network Load Balancer or Application Load Balancer, this is the Amazon Resource Name (ARN) of the resource. If the endpoint is an Elastic IP address, this is the Elastic IP address allocation ID.
* `weight` - (Optional) The weight associated with the endpoint. When you add weights to endpoints, you configure AWS Global Accelerator to route traffic based on proportions that you specify.
* `cross_account_attachment_arn` - (Optional) An ARN of an exposed cross-account attachment. See the [AWS documentation](https://docs.aws.amazon.com/global-accelerator/latest/dg/cross-account-resources.html) for more details.

`port_override` supports the following arguments:

Expand Down