Migration¶
Mach Composer does not support tools for migrating a component from site-managed to site-component managed. However, it is possible to manually do the migrations through using terraform directly.
To migrate a component from site-managed to site-component the following steps are necessary:
- Change the site-component configuration you want to move out by setting the
correct deployment type:
# my-site.yml site: identifier: my-site components: - name: my-component deployment: type: site-component # Etc... # Etc...
mach-composer generate -f main.yaml
to generate the Terraform locallymach-composer init -f main.yaml
to initialize the Terraform CLI- Assuming a site named
my-site
move to generatedmy-site
directory (cd ./deployments/main/my-site
) and runterraform state pull > terraform.tfstate
- Do the same for the component you want to move out, assuming a component
named
my-component
move to generatedmy-component
directory (cd ./deployments/main/my-site/my-component
) and runterraform state pull > terraform.tfstate
- Move back to the site directory (
cd ..
) and runterraform state mv --state=terraform.tfstate --state-out=./my-component/terraform.tfstate module.my-component module.my-component
- Push the changes to the remote
state (
terraform state push terraform.tfstate
) - Move to the component directory (
cd ./my-component
) and do the same:terraform state push terraform.tfstate
- Move back to the root directory (
cd ../../..
) and runterraform plan
to check if the changes will be applied correctly - Finally, run
terraform apply
to apply the changes
Convenience script (use at own risk)¶
#!/bin/bash
if [ -n "$1" ]; then
echo "Using $1 as the site directory."
else
echo "Provide the site directory. This generally is in the format of ./deployments/main/<site-name>."
exit 1
fi
if [ -n "$2" ]; then
echo "Using $2 as the component"
else
echo "Provide the component name"
exit 1
fi
mach-composer generate -f main.yaml
mach-composer init -f main.yaml
cd ./$1 || exit
terraform state pull > terraform.tfstate
cd ./$2 || exit
terraform state pull > terraform.tfstate
cd ../
terraform state mv --state=terraform.tfstate --state-out=./"$2"/terraform.tfstate "module.$2" "module.$2"
terraform state push terraform.tfstate
cd ./"$2" || exit
terraform state push terraform.tfstate