Terraform for automating NC2 and FVN
Introduction
This guide introduces a collection of Terraform and OpenTofu scripts designed to automate the deployment and configuration of Nutanix Cloud Clusters (NC2) on AWS, with a particular focus on Flow Virtual Networking (FVN). These scripts help streamline the process of setting up complex networking configurations and VM deployments in NC2 environments.
Benefits of automation
Automation with Terraform and OpenTofu brings several significant advantages:
- Time Efficiency: Manual configuration of NC2 environments can be time-consuming. These scripts automate the process, reducing deployment time from hours to minutes.
- Cost Optimization: Since NC2 on AWS bills bare-metal hosts hourly, faster deployments directly translate to cost savings.
- Consistency: Automated deployments ensure consistent configurations across different environments.
- Reproducibility: The infrastructure can be easily recreated or modified using the same code.
- Version Control: Infrastructure changes can be tracked and managed through version control systems.
Terraform and OpenTofu
These samples have been thoroughly tested on NC2 on AWS using OpenTofu but are fully compatible with Terraform. While primarily developed for AWS environments, the scripts should work on NC2 on Azure as well, though this hasn’t been part of the testing during development.
Key Differences Between Terraform and OpenTofu
- Both tools use the same HashiCorp Configuration Language (HCL)
- OpenTofu is an open-source fork of Terraform
- The scripts are compatible with both tools without modification
Features of the Terraform samples
The provided samples are designed with flexibility and ease of use in mind:
Environment Configuration
- All samples assume Prism Central and other variables are exported as environment variables
- Each folder includes a
set-env.sh
script for easy environment setup - Variables can be customized to match your specific environment
Networking Focus
The samples cover various networking scenarios:
- NAT and no-NAT configurations for Flow Virtual Networking
- Multi-subnet VPC setups
- Transit VPC configurations
- Floating IP assignments
- External Route Propagation (ERP) settings
VM Management
Some samples extend beyond networking to include:
- VM image downloads and registration
- VM creation and configuration
- Cloud-init script execution for software installation
- Automated VM deployment across different network configurations
Download
The samples can be downloaded from the following GitHub repository: https://github.com/jonas-werner/nc2-fvn-terraform
Script Overview
1. nc2-os-images
- Downloads Ubuntu and CentOS images
- Registers images in Prism Central image repository
- Supports multiple image versions and formats
2. nc2-fvn_nonat-only
- Creates no-NAT subnet in the transit-vpc
- Configures basic networking components
- Sets up initial routing
3. nc2-fvn_nat-vpcs
- Creates NAT-enabled VPCs
- Configures multiple subnets
- Sets up NAT gateway and routing
4. nc2-fvn_nonat-vpcs
- Creates no-NAT VPCs
- Configures multiple subnets
- Sets up direct routing
5. nc2-fvn_nat-vms-simple
- Deploys VMs in NAT-enabled VPC environment
- Assigns floating IPs
- Configures basic VM networking
6. nc2-fvn_nat-nonat-vms
- Deploys VMs in mixed NAT/no-NAT environment
- Configures ERP entries
- Sets up complex networking scenarios
Detail for the nc2-fvn_nat-nonat-vms sample
This comprehensive script demonstrates a complex deployment scenario that combines both NAT and no-NAT configurations:
Network Setup
- Creates no-NAT network in the transit-vpc
- Creates two Flow VPCs:
- One configured for NAT
- One configured for no-NAT
- Routing between networks will be done via the transit-vpc
VM Deployment
- Downloads Ubuntu image to Prism Central image repository
- Deploys VMs across different network configurations
- Configures networking for each VM:
- NAT networks: Assigns floating IPs from AWS VPC CIDR range
- No-NAT VPCs: Configures ERP entries for subnets
Important Notes
- ERP configuration is only applied to newly created Flow VPCs
- The pre-existing transit-vpc requires manual ERP configuration
- This step is left to the user as adding networks here automatically updates also the AWS VPC default route table
ERPs added to the Flow VPCs
ERPs added to the Flow transit-vpc resulting in AWS VPC route table update:
Best Practices
When using these scripts, consider the following best practices:
- Environment Variables: For convenience, refer to the provided
set-env.sh
script to set up your environment - Testing: Test configurations in a non-production environment first
- Backup: Keep backups of your Terraform state files
- Documentation: Document any customizations you make to the scripts
- Security: Review and adjust security groups and network policies as needed
Conclusion
This guide has introduced a comprehensive collection of Terraform scripts for automating overlay networking and VM creation on NC2 on AWS. These scripts provide a solid foundation for deploying and managing complex NC2 environments while saving time and reducing the potential for configuration errors.