How to add remote .tfstate
Gitlab
create a gitlab token with api endpoint
Terraform
add a backend to your 00_providers.tf
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "1.44.0"
}
}
backend "http" {
address = "https://gitlab.com/api/v4/projects/<projectID>/terraform/state/state"
lock_address = "https://gitlab.com/api/v4/projects/<projectID>/terraform/state/state/lock"
unlock_address = "https://gitlab.com/api/v4/projects/<projectID>/terraform/state/state/lock"
lock_method = "POST"
unlock_method = "DELETE"
retry_wait_min = 5
}
}
update your *-openrc.sh by adding the following at the end
export TF_HTTP_USERNAME=<gitlab username>
export TF_HTTP_PASSWORD=<gitlab token>
source the *-openrc.sh
file
run init the state
terraform init
go check your gitlab and see if there is a .tfstatew