How to fix private-dns-enabled cannot be set because there is already a conflicting DNS domain?

Navigating the intricacies of Amazon Web Services (AWS) can be a complex task. Even seasoned developers working with Infrastructure as Code (IaC) tools like Terraform and CloudFormation may occasionally face frustrating obstacles.

A common stumbling block arises from conflicts in Virtual Private Cloud (VPC) settings, particularly when managing private DNS domains.

In this blog post, I'll guide you through resolving an error stating -

private-dns-enabled cannot be set because there is already a conflicting DNS domain for secretsmanager.us-east-2.amazonaws.com in the VPC.

Fixing the error private-dns-enabled cannot be set because there is already a conflicting DNS domain for secretsmanager


Table of content

  1. Understanding the Issue
  2. Step 1: Identify the Conflicting DNS Zone
  3. Step 2: Delete the Conflicting DNS Zone
  4. Step 3: Modify Your Terraform or CloudFormation Script
  5. Step 4: Run Terraform Apply or Update CloudFormation Stack
  6. Step 5: Troubleshooting VPC Endpoint Issues:
  7. Conclusion

Understanding the Issue

Let's first dissect what this error signifies. When you set up a VPC with private DNS enabled, AWS automatically establishes a Route 53 private hosted zone to resolve any DNS queries within the VPC to the private IPs of the associated service.

However, if an existing Route 53 hosted zone for the same domain is present, a conflict arises, leading to this error.

So how can we resolve this error, both within your AWS infrastructure and your Terraform and CloudFormation scripts?

Let's break it down step-by-step:

Step 1: Identify the Conflicting DNS Zone

  1. Start by identifying the conflicting DNS zone.

  2. Log into the AWS Route 53 console and locate the existing hosted zone for example secretsmanager.us-east-2.amazonaws.com.

  3. Take note of the hosted zone ID.


Step 2: Delete the Conflicting DNS Zone

  1. If the conflicting DNS zone isn't needed, delete it.

  2. But proceed with caution, as this could impact other resources depending on it. If it's necessary, consider alternatives, like -

    • Creating a new VPC that doesn't require private DNS for this specific service.

Step 3: Modify Your Terraform or CloudFormation Script

  1. Having identified and addressed the conflict in your AWS settings, it's time to turn to your IaC scripts.

  2. Ensure that you've removed all references to the deleted DNS hosted zone in your script. If you've opted to create a new VPC or implemented another solution, make these changes in your script as well.


Step 4: Run Terraform Apply or Update CloudFormation Stack

Once your script is updated, apply the changes by running the terraform apply command for Terraform scripts, or update the stack if you're using a CloudFormation script.


Step 5: Troubleshooting VPC Endpoint Issues:

Sometimes, a similar issue might arise when trying to rename a VPC endpoint in a CloudFormation stack. As one of our readers kindly shared, they resolved this by deleting the problematic endpoint:

  1. Log into the AWS Console.
  2. Navigate to VPC -> Virtual Private Cloud -> Endpoints.
  3. Find the problematic entry in the list of Endpoints.
  4. Click on the entry and select Actions -> Delete Endpoint.
  5. Patiently wait for the deletion process to complete (this may take a few minutes).

Upon deleting the endpoint, they successfully reran their CloudFormation stack without any errors.


Conclusion

While Infrastructure as Code (IaC) can bring efficiency and simplicity to your workflows, encountering challenges is part of the journey.

Whether you're using Terraform or CloudFormation, understanding how to resolve common errors, such as DNS domain conflicts in Amazon VPC, is crucial. Remember, it's essential to understand the potential impact before modifying your infrastructure.

Always refer to the relevant AWS documentation or best practices for your IaC tool of choice.

In times of doubt, don't hesitate to ask for help. AWS Support or a knowledgeable colleague can be invaluable resources. As you continue navigating your path as a developer, remember that each error you face is an opportunity for learning and growth. Keep pushing forward, and happy coding!

Posts in this Series