This guide explains how to import existing Namecheap domains and DNS records into Pulumi, allowing you to manage them as Infrastructure as Code.
Why Migrate to Pulumi?#
- Version Control: Track all DNS changes in Git
- Reproducibility: Recreate environments easily
- Collaboration: Team members can review and approve changes
- Automation: Integrate with CI/CD pipelines
- Documentation: Code serves as living documentation
Pre-Migration Checklist#
Before migrating, ensure you have:
- Namecheap API access enabled
- API credentials (username, API key)
- IP address whitelisted
- Backup of current DNS settings
- List of domains to migrate
- Understanding of current DNS configuration
Backup Current Configuration#
Export your current DNS records manually or via API:
Import Strategy#
Option 1: Import Existing Resources (Recommended)#
This approach imports existing DNS records into Pulumi state without changes.
Step 1: Create Pulumi code matching existing configuration
Step 2: Import the resource
Step 3: Verify the import
Option 2: Recreate Resources#
For simpler setups, you can define resources from scratch:
Step 1: Document existing configuration
Take screenshots or notes of your current Namecheap DNS settings.
Step 2: Create Pulumi program
Step 3: Apply with caution
Migration Patterns#
Single Domain Migration#
Simplest case - one domain with standard DNS:
Multiple Domains Migration#
Organize multiple domains efficiently:
Environment-Based Migration#
Migrate dev, staging, and production separately:
Migration Steps#
Phase 1: Preparation (Week 1)#
-
Audit Current Configuration
- Document all DNS records
- Identify critical services
- Note custom configurations
-
Set Up Development Environment
-
Test in Sandbox
Phase 2: Non-Critical Domains (Week 2)#
- Start with development domains
- Import or recreate resources
- Verify DNS resolution
- Monitor for 24-48 hours
Phase 3: Production Domains (Week 3-4)#
-
Lower TTL values
-
Migrate during low-traffic period
-
Monitor closely
-
Keep backup plan ready
-
Restore normal TTL after 48 hours
Rollback Plan#
Always have a rollback strategy:
Post-Migration Tasks#
Verification#
Documentation#
Monitoring Setup#
Set up alerts for DNS changes:
Common Migration Issues#
Issue: Import Fails#
Problem: Cannot import existing resource
Solution: Use different resource name or remove from state first
Issue: Records Not Matching#
Problem: Pulumi shows changes after import
Solution: Ensure your code exactly matches existing configuration, including:
- TTL values (use actual values, not defaults)
- Record order (may need to reorder)
- Trailing dots on CNAMEs
Issue: Downtime During Migration#
Problem: DNS resolution fails after migration
Solution:
- Check Namecheap API responded successfully
- Verify records in Namecheap dashboard
- Use low TTL values before migration
- Have rollback plan ready
Best Practices#
Incremental Migration#
Don't migrate everything at once:
Use Stack Tags#
Track migration status:
Document Everything#
Next Steps#
- Configuration Guide - Set up provider
- DNS Guide - Best practices
- Domain Records - API reference