Migrate to Spot Official Provider
This post describes how to migrate your current Terraform file structure to support the structure of the latest Spot Provider version. These steps support a single or multiple Elastigroups resources import. The current implementation of Terraform import can only import resources into the state. It does not generate configuration. A future version of Terraform will also generate configuration. Make sure to save a copy of your current *.tf file and terraform.tfstate before starting.
Step 1: Prepare Your Resources
Create a new folder containing the following files:
-
*.tf– a file which contains an empty Elastigroup resource, i.e:provider "spotinst" {
token = "xxxxxxxxxxxxxxxxxxxxxxx"
account = "act-1exxxx40"
}
resource "spotinst_elastigroup_aws" "TFtest1" {}The Provider can also be added as described here.
-
terraform.tfstate– a file which contains this skeleton:{
"version": 3,
"terraform_version": "0.11.4",
"serial": 1,
"lineage": "same as on old provider",
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {
"spotinst_elastigroup_aws.<name of the resource>-IMPORT": {
"type": "spotinst_elastigroup_aws",
"depends_on": [],
"primary": {
"id": "<group-id>",
"attributes": {}
}
}
}
}
]
}
Step 2: Migrate Your Current Resource
-
Open the terminal and run
terraform initin order to download the official Spot provider to the same folder from the previous step. -
Execute the following command:
terraform import spotinst_elastigroup_aws.<name of the resource> <group-id> -
The updated
terraform.tfstateshould now contain your Elastigroups in addition to the previous resource with the-IMPORTsuffix.Remove the resource with the
-IMPORTsuffix.noteYou must delete the
-IMPORTresource to prevent your Elastigroup from being destroyed. -
Perform a
terraform planto ensure the state file has changed successfully. You are supposed to see a log of the changes.
Step 3: Convert Your Schema
-
Migrate the previous tf.file to your empty
spotinst_elastigroup_awsresource (created as part of step 1) and convert its schema to be aligned with the new provider.You can use our special post on how to view Elastigroup configuration as Terraform.
-
Occasionally perform
terraform planto verify which fields need to be modified on the schema without actually changing the group via the Spot API.noteDo not run
terraform applyuntil you fully migrate the Terraform schema to the new provider. -
Perform
terraform applyto successfully apply your changes.