It’s possible to use the Terraform platform to manage AWS CloudFront in the following way?

Hello,
I’d like to understand whether it’s possible to use the Terraform platform to manage AWS CloudFront in the following way:

I want to duplicate the configuration of an existing CloudFront distribution (associated with a domain) and then create a new distribution for a different domain based on that configuration.

In other words, my goal is to use Terraform to:

  1. Retrieve the full configuration of an existing CloudFront domain/distribution,
  2. Make minimal changes (e.g., domain name),
  3. And then create a new distribution using the modified configuration.

This way, the new domain’s CloudFront configuration would be identical to the original one, except for the updated domain name.

Is this workflow supported in Terraform? If so, what’s the best practice to accomplish it?

Thanks in advance!

I am not sure if it can be done in a repeatable or automated fashion, but it is possible to generate the configuration of an existing resource using this workflow. Once the TF configuration is generated, you can make whatever changes required and apply it to create the new resource. That said, I don’t know if you’d only need the aws_cloudfront_distribution resource, or the other side CloudFront resources as well.