I’m new to terraform. I’m not able to connect to the Gitlab remote Terraform managed backend. The state file is out of sync.
To be clear, nothing throws error, everything seems to work fine. But I know that on my local machine the terraform state file is out of sync from the Gitlab one because when the gitlab ci finishes I have one instance launched, but when I do terraform plan on my local machine, the plan says it will create an instance. It should not because there is already an instance running on the infrastructure.
Here is my provider.tf file:
terraform {
required_version = ">= 0.14.0" # Takes into account Terraform versions from 0.14.0
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.42.0"
}
ovh = {
source = "ovh/ovh"
version = ">= 0.13.0"
}
}
backend "http" {
address = "https://gitlab.com/api/v4/projects/XXXXX/terraform/state/$TF_STATE_NAME"
lock_address = "https://gitlab.com/api/v4/projects/XXXXX/terraform/state/$TF_STATE_NAME/lock"
unlock_address = "https://gitlab.com/api/v4/projects/XXXXX/terraform/state/$TF_STATE_NAME/lock"
}
}
# Configure the OpenStack provider hosted by OVHcloud
provider "openstack" {
auth_url = "https://auth.cloud.ovh.net/v3/" # Authentication URL
domain_name = "default" # Domain name - Always at 'default' for OVHcloud
alias = "ovh" # An alias
}
provider "ovh" {
region = "BHS5"
alias = "ovh"
endpoint = "ovh-eu"
application_key = OVH_APPLICATION_KEY
application_secret = OVH_APPLICATION_SECRET
consumer_key = OVH_CONSUMER_KEY
}
And I have run the terraform init command that I copied from gitlab under operate → Terraform states → Actions → Copy Terraform init command, and everything worked fine, no errors.
What am I missing?