Introduction
Importing existing resources into Terraform is essential for managing infrastructure as code without recreating existing configurations. This guide demonstrates how to import a Crusoe VPC network into Terraform state using the Crusoe Terraform provider. By following this guide, users can seamlessly integrate existing Crusoe Cloud resources into their Terraform workflow.
Note: You can also Import other Crusoe Resources such as subnets, firewalls using the same method. For example code please refer terraform-provider-crusoe document mentioned in references.
Prerequisites
Before starting, ensure you have the following:
-
Terraform installed (version 1.0+ recommended) – Download Terraform
-
Crusoe Terraform Provider (version >= 0.5.27)
-
Access to a Crusoe Cloud project with appropriate permissions
-
Existing VPC Network ID (e.g.,
5cdb7e62-6720-4fca-83ca-488afbd98c79
) -
Configured Terraform working directory with a provider block
Step-by-Step Instructions
Step 1: Upgrade the Crusoe Provider
To ensure compatibility with Terraform’s import functionality, update the Crusoe provider to version >= 0.5.27
.
-
Modify your
terraform
block in the configuration file:terraform { required_providers { crusoe = { source = "registry.terraform.io/crusoecloud/crusoe" version = ">= 0.5.27" } } }
-
Run the following command to upgrade the provider:
terraform init -upgrade
Step 2: Define the VPC Network in Terraform
Before importing, the resource must exist in the Terraform configuration. Add the following to your .tf
file:
resource "crusoe_vpc_network" "default_vpc_network" {
name = "default-vpc-network"
cidr = "172.27.0.0/16" # Adjust if needed
}
Step 3: Import the Existing VPC Network
Run the following command to import the existing VPC network into Terraform’s state:
terraform import crusoe_vpc_network.default_vpc_network 5cdb7e62-6720-4fca-83ca-488afbd98c79
Upon successful import, you will see a message like:
Import successful!
The resources that were imported are shown above. These resources are now in your Terraform state and will henceforth be managed by Terraform.
Step 4: Verify the Import
-
Run the following command to check if Terraform recognizes the imported resource:
terraform plan
-
If there are unexpected changes, compare the imported state with your Terraform configuration and adjust accordingly.
Example
Scenario
A user has an existing VPC network in Crusoe Cloud and wants to manage it with Terraform without recreating it. They follow this guide and successfully import their existing VPC using its resource ID.
Outcome
The imported VPC is now part of the Terraform state, allowing modifications, updates, and deletions through Terraform.
Common Issues & Troubleshooting
Issue: "Resource address does not exist in the configuration"
Solution: Ensure that the resource name in your Terraform configuration matches exactly with the import command.
Issue: "Provider version conflict"
Solution: Run terraform init -upgrade
to upgrade the Crusoe provider to the required version.
Issue: "Unexpected changes after import"
Solution: Run terraform show
to inspect the imported state and adjust the Terraform configuration to match the actual resource settings.
Additional Resources
-
Crusoe VPC Network Example (for importing additional resources like firewalls, subnets, and more)
Comments
0 comments
Please sign in to leave a comment.