terraformopenstack

Terraform cant create VM in openstack provider (No suitable endpoint could be found in the service catalog)


I have project in terraform - provider "openstack" v1.16:

  provider "openstack" {
  auth_url = "${var.auth_url}"
  user_name = "${var.username}"
  password = "${var.password}"
  region = "${var.region}"
  project_domain_id = "${var.project_id}"
  project_domain_name = "${var.project_domain_name}"
  endpoint_type = "public"
}

And try to create compute node:

resource "openstack_compute_instance_v2" "terraform_test" {
  name = "test"
  region = "${var.region}"
  availability_zone = "nova"
  image_id = "${var.image}"
  flavor_name = "m1.medium"
  key_pair = "${var.ssh_key}"
  security_groups = ["default"]

  network {
    uuid = "${var.network}"
  }
}

"terraform plan" without any errors.

When a try to apply plan, i take this error:

Error: Error applying plan:

1 error(s) occurred:

* openstack_compute_instance_v2.terraform_test: 1 error(s) occurred:

* openstack_compute_instance_v2.terraform_test: Error creating OpenStack compute client: No suitable endpoint could be found in the service catalog.

When i do

openstack catalog list

I take

 nova        compute   regionName
                         public: https://compute.$url:8774/v2.1
                       regionName   
                         admin: $url
                       regionName
                         internal: $url

 keystone    identity  regionName
                         internal: $url
                       regionName
                         admin: $url
                       regionName
                         public: https://auth.$url:5000/v2.0

So i have endpoint for computing (create vm's). What is the problem?


Solution

  • I found a solution: openstack provide *-openrc.sh script with all environment variables for connection:

    # With the addition of Keystone we have standardized on the term **tenant**
    # as the entity that owns the resources.
    export OS_TENANT_ID=$ID
    export OS_TENANT_NAME="$NAME"
    
    # unsetting v3 items in case set
    unset OS_PROJECT_ID
    unset OS_PROJECT_NAME
    unset OS_USER_DOMAIN_NAME
    

    I found out that I used variables for API v3, but post them to API v2. So I changed variables names with the same values:

    project_domain_id > tenant_id
    project_domain_name > tenant_name
    

    Provider now looks like:

    provider "openstack" {
      auth_url = "${var.auth_url}"
      user_name = "${var.username}"
      password = "${var.password}"
      region = "${var.region}"
      tenant_name = "${var.tenant_name}"
      tenant_id = "${var.tenant_id}"
    }
    

    Now it works fine!