-1

**SOLVED: the output I was seeking can be found in the resource aws_apigatewayv2_domain_name from the attribute target_domain_name (which is nested under domain_name_configuration.

I am looking to find a way to add an output in my Terraform module to get the url of the custom domain name route53 url that is automatically created by AWS when I create a custom domain in Api Gateway. (ex. d-uq5rzcek63.execute-api.us-east-1.amazonaws.com). Does anyone know how to access that value as an output?

Here is the block of code building the custom domain:

resource "aws_apigatewayv2_domain_name" "module_domain" {
  domain_name = "exampledomain.com"
  domain_name_configuration {
    certificate_arn = "arn:aws:acm:us-east-1:000000000000:certificate/xxxx11x-x11x-11xx-11x1-11xxx111xxx1"
    endpoint_type   = "REGIONAL"
    security_policy = "TLS_1_2"
  }
}

Refer to screenshot of where this value can be found in console.

Em Ma
  • 17
  • 3
  • Which one are you using, API Gareway v1 or 2? Can you add the code you have to the question? – Marko E Nov 16 '22 at 21:06
  • I am trying to do the same thing for both my API Gateway V1 and V2 modules, but for the sake of this thread we can focus on Apigatewayv2. – Em Ma Nov 16 '22 at 21:17
  • Your code and the screenshot refer to two different types of resources. You need to either create or data look up an `aws_apigatewayv2_api` get the API Endpoint value – Prav Nov 17 '22 at 00:06
  • 1
    @Prav In my case here though I am only creating a domain (as seen in code block) - before even attaching a domain to an apigateway, aws will create an aws managed route 53 url which you can see in my screenshot. This is what I’m trying to access. – Em Ma Nov 17 '22 at 02:40

1 Answers1

1

This can be obtained using invoke_url from aws_apigatewayv2_stage, or using api_endpoint from aws_apigatewayv2_api.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • In my case here though I am only creating a domain (as seen in code block) - before even attaching a domain to an apigateway, aws will create an aws managed route 53 url which you can see in my screenshot. This is what I’m trying to access. – Em Ma Nov 17 '22 at 02:38
  • @EmMa I'm not sure what you mean. The get the API Gateway domain name as shown on your screenshot, you have to use what I wrote. – Marcin Nov 17 '22 at 02:57
  • **SOLVED: the output I was seeking can be found in the resource aws_apigatewayv2_domain_name from the attribute target_domain_name (which is nested under domain_name_configuration. – Em Ma Nov 17 '22 at 16:14