Home > Software design >  Data source for aws_vpc_endpoint_service_allowed_principal
Data source for aws_vpc_endpoint_service_allowed_principal

Time:12-14

I need to check the list of aws_vpc_endpoint_service_allowed_principal from a specific aws_vpc_endpoint_service.

The aws_vpc_endpoint_service data source does not return the list of allowed_principals.

Does anyone know how can I retrieve that information?

CodePudding user response:

Since the data source for that resource does not exist, you can use external data source with a custom script to query the required information.

Here's an example script (get_vpc_endpoint_service_permissions.sh) that fetches the required information:

#!/bin/bash
sep=$(aws ec2 describe-vpc-endpoint-service-permissions --service-id vpce-svc-03d5ebb7d9579a2b3 --query 'AllowedPrincipals')
jq -n --arg sep "$sep" '{"sep":$sep}'

and here's how you consume it in terraform:

data "external" "vpc_endpoint_service_permissions" {
  program = ["bash", "get_vpc_endpoint_service_permissions.sh"]
}

output "vpc_endpoint_service_permissions" {
  value = data.external.vpc_endpoint_service_permissions.result.sep
}

data.external.vpc_endpoint_service_permissions.result.sep contains the output of the bash script, which is a JSON array that you can access/manipulate as needed.

  • Related