Skip to content

Instantly share code, notes, and snippets.

@kiranchavala
Created September 27, 2021 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiranchavala/c1b81f1d629b0567e08e219891d4ed48 to your computer and use it in GitHub Desktop.
Save kiranchavala/c1b81f1d629b0567e08e219891d4ed48 to your computer and use it in GitHub Desktop.
Importing Cloudstack resources into Terraform.txt
1. Install Terraform on mac
brew install hashicorp/tap/terraform
brew install terraform
2. Install the terraform provider plugin for cloudstack
https://kiranchavala.in/blog/terraform-cloudstack/
3. Create a provider.tf file with the following content
mkdir -p test
cd test
vi provider.tf
terraform {
required_providers {
cloudstack = {
source = "localdomain/provider/cloudstack"
version = "0.3.0"
}
}
}
provider "cloudstack" {
api_url = "http://10.207.253.10:8080/client/api"
api_key = "m9Sp_8ZQW2OvL3dEH-2uzE6YMqveh_tghys3kdBFEvYwWNtD9jgwkXM4gkuQiQJYSa4TAOmIXAb8yXQAHcYYMw"
secret_key = "eQYXq5vzwoEoi_iSv9KYScnanEZA16neF7RmhOfSpHIQT1HZlRbIDmcpueZyCWF-P2g665HclYBGi82SrIx1uQ"
}
terraform init
4. In order to import resources from Rovius cloud
We need to generate the resource config that we want to import
cat main.tf
resource "cloudstack_instance" "VM-Iso9" {
service_offering="63b906fa-6ae3-40dd-9af9-ec6ae09910d2"
template="83f134e1-9d1e-11eb-a8e7-1e00f200001d"
zone="8b340ea8-eb7b-4b56-9629-319f152d7ecb"
network_id="787f189f-2564-4be4-8903-b845535c6245"
display_name="VM-Iso9"
}
pass the vm id
terraform import cloudstack_instance.VM-Iso9 709b25b6-8453-4c4a-957d-0817707394f5
Ref :
https://spacelift.io/blog/importing-exisiting-infrastructure-into-terraform
https://www.terraform.io/docs/cli/commands/import.html
terraform import cloudstack_instance.VM-Iso9 709b25b6-8453-4c4a-957d-0817707394f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment