How to retrieve associated CloudFront Distribution URL in Amplify+Terraform?

Viewed 158

Within Terraform, is it possible to retrieve the URL of an Amplify app's CloudFront Distribution?

If I was to create a new Next.js app within the web console, there is an important 200 rewrite that gets added in 'Redirects & Rewrites', which points all front-end paths to the associated CloudFront Distribution. However, I'm now migrated to Terraform aws_amplify_app, which doesn't add this rewrite automatically.

So, does anyone know how to do this within the TF provider? I appreciate that this may be impossible because the CloudFront Distribution is only created as part of the Amplify App itself. So, alternatively, if it is not exposed, is there a way for Amplify to handle this Next-specific logic when using Terraform (rather than just through the web console)?

Here is the relevant code from my main.tf, with a TODO comment showing what needs to be automatic.

resource "aws_amplify_app" "ui" {
  name       = "my-ui"
  ...

  custom_rule {
    source = "/<*>"
    status = "200"
     ## TODO -- this should be automatically set as the URL of the newly created CloudFront distribution
    target = "https://xxxxxxxxx.cloudfront.net/<*>"
  }
}
0 Answers
Related