Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRN token malformed in Region eu-de (Frankfurt 1) - CRN constructor issue when using non-us region? #1141

Closed
bmarolleau opened this issue Feb 26, 2020 · 11 comments

Comments

@bmarolleau
Copy link

Hi there,

Here is the description of the experienced issue: I can't create a new Power Virtual Server virtual instance (VM) from Terraform/CAM when pointing to eu-de , Frankfurt 1 (works ok in us-south) , receiving the following error when running terraform plan:
"{"description":"an error has occurred; please try again: unable to get admin image instance: unable to get new image instance: unable to get provider client: provider client does not exist or does not have any credentials registered","error":"internal server error"}"
The crn generated (based on the Region and Location , I suppose) by the provider should contain eu-de-1/xxxx , but it contains eu-de/xxx which generates the error above. (note the -1 , dash one at the end, for Frankfurt 1 location)
CRN constructor generated (KO) : crn:v1:bluemix:public:power-iaas:eu-de:a/45d319a
CRN to be generated instead (Frankfurt 1) : crn:v1:bluemix:public:power-iaas:eu-de:a-1/45d319a
CRN to be generated instead (Frankfurt 2) : crn:v1:bluemix:public:power-iaas:eu-de:a-2/45d319a

This statement concerns my environment & IBM Cloud Account. Note that for eu-de , Frankfurt 2 , the crn should contains -2 (dash 2) , based on my environment (please check :) )

Terraform Version

terraform --version
Terraform v0.12.19

  • provider.ibm v1.2.1
  • provider.local v1.4.0

Affected Resource(s)

  • ibm_pi_instance

Terraform Configuration Files

Debug Output

Expected Behavior

What should have happened?

Actual Behavior

Fail to provision a pi_instance in region eu-de , even with export IC_REGION=eu-de

Steps to Reproduce

  1. export IC_REGION=eu-de
  2. terraform plan
@hkantare
Copy link
Collaborator

hkantare commented Feb 26, 2020

Can you please set region to eu-de-1
export IC_REGION=eu-de-1

@bmarolleau
Copy link
Author

bmarolleau commented Feb 26, 2020

Hi, Thx for your help!
I tried that, but in that case, I got this, the region seems to be used in the REST API URL, and then generates this :

`Error: Get https://eu-de-1.power-iaas.cloud.ibm.com/pcloud/v1/cloud-instances/f83b6038-b9a7-42a6-9500-6d458bbdd11e/networks/internal: dial tcp: lookup eu-de-1.power-iaas.cloud.ibm.com on xxxxxxx : no such host

on main.tf line 8, in data "ibm_pi_network" "power_networks":
8: data "ibm_pi_network" "power_networks" {

Error: Get https://eu-de-1.power-iaas.cloud.ibm.com/pcloud/v1/cloud-instances/f83b6038-b9a7-42a6-9500-6d458bbdd11e/images/d8b5dff9-973b-4107-83d5-a705076ff6f0: dial tcp: lookup eu-de-1.power-iaas.cloud.ibm.com on xxxxxxxx no such host

on main.tf line 14, in data "ibm_pi_image" "power_images":
14: data "ibm_pi_image" "power_images" {`

@hkantare
Copy link
Collaborator

hkantare commented Feb 27, 2020

The error which we see is from the API even when I tried from CLI
I do see same error

Harinis-MacBook-Pro:~ hkantare$ ic pi imglc  
Listing images under account Harini Reddy's Account as user hkantare@in.ibm.com...
FAILED
[GET /pcloud/v1/images][500] pcloudImagesGetallInternalServerError  &{Code:0 Description:an error has occurred; please try again: unable to get admin image instance: unable to get new image instance: unable to get provider client: provider client does not exist or does not have any credentials registered Error:internal server error Message:}

Harinis-MacBook-Pro:~ hkantare$ ic pi images
Listing images under account Harini Reddy's Account as user hkantare@in.ibm.com...
FAILED
[GET /pcloud/v1/cloud-instances/{cloud_instance_id}/images][500] pcloudCloudinstancesImagesGetallInternalServerError  &{Code:0 Description:an error has occurred; please try again: unable to get admin image instance: unable to get new image instance: unable to get provider client: provider client does not exist or does not have any credentials registered Error:internal server error Message:}

I tried creating SSHKEY for the power virtual system of frankfurt 1 region
export IC_REGION=eu-de

resource "ibm_pi_key" "key" {
  pi_cloud_instance_id = "e3515ca1-b75f-4dca-8164-a67cbf545c24"
  pi_key_name          = "test"
  pi_ssh_key           = "***SSHKEY***"
}

data "ibm_pi_key" "dskey" {
  depends_on           = ["ibm_pi_key.key"]
  pi_cloud_instance_id = "51e1879c-bcbe-4ee1-a008-49cdba0eaf60"
  pi_key_name          = "test"
}

Harinis-MacBook-Pro:power hkantare$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
 <= read (data resources)

Terraform will perform the following actions:

  # data.ibm_pi_key.dskey will be read during apply
  # (config refers to values not yet known)
 <= data "ibm_pi_key" "dskey"  {
      + creation_date        = (known after apply)
      + id                   = (known after apply)
      + pi_cloud_instance_id = "51e1879c-bcbe-4ee1-a008-49cdba0eaf60"
      + pi_key_name          = "test"
      + sshkey               = (known after apply)
    }

  # ibm_pi_key.key will be created
  + resource "ibm_pi_key" "key" {
      + id                   = (known after apply)
      + key_id               = (known after apply)
      + pi_cloud_instance_id = "e3515ca1-b75f-4dca-8164-a67cbf545c24"
      + pi_key_name          = "test"
      + pi_ssh_key           = "***SSHKEY***"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

ibm_pi_key.key: Creating...
ibm_pi_key.key: Creation complete after 3s [id=e3515ca1-b75f-4dca-8164-a67cbf545c24/test]
data.ibm_pi_key.dskey: Refreshing state...

@hkantare
Copy link
Collaborator

It created su
Screen Shot 2020-02-27 at 4 29 00 PM
ccessfully...

@hkantare
Copy link
Collaborator

For the issues from API can you please open issue against PI

@bmarolleau
Copy link
Author

Well, the error seems to be around this CRN constructor when using a multi-zone Region like Frankfort , right ?
If I look at the CRN constructor message I receive just before the REST API error due to the malformed CRN, here is the culprit:
Benoit2$ git clone https://github.com/IBM-Cloud/terraform-provider-ibm.git
Benoit2$ grep -R "Calling the crn constructor" ./*
./common/github.com/IBM-Cloud/power-go-client/ibmpisession/ibmpowersession.go: log.Printf("Calling the crn constructor that is to be passed back to the caller %s", useraccount)

and the issue is in func crnBuilder(powerinstance, useraccount, region string) , which does not use the zone to build the Cloud Resource Number, which is very us-south / us-east centric and will be a problem sooner or later for customers in Europe or other Regions.
Based on how the CRN are generated, the region should not be used from the template, but the zone or location instead...
I could create a PR for that, but not sure to manage to fix it , please advise. Thanks.

@hkantare
Copy link
Collaborator

we are looking into design how to handle the issue.We will update the design soon..

@bmarolleau
Copy link
Author

thx a lot for your support!

@surajsub
Copy link
Contributor

surajsub commented Mar 3, 2020

Code update has been made..

@hkantare
Copy link
Collaborator

We added a new provider argument zone to work for multi-zone . Specify the zone parameter if the region support multi-zone
provider "ibm" {
region = "eu-de"
zone = "eu-de-1"
}
Available as part of new releases
https://github.com/IBM-Cloud/terraform-provider-ibm/releases/tag/v1.2.4
https://github.com/IBM-Cloud/terraform-provider-ibm/releases/tag/v0.24.4

@bmarolleau
Copy link
Author

Thanks very much , it works now using the latest version of the Provider (I pulled it from the source) - in us-south (single zone regions) and Frankfurt (multi-zone regions) . In my test, I set the regions from a variables.tf file :

variable "ibmcloud_region" {
    description = "Denotes which IBM Cloud region to connect to"
    default     = "eu-de"
}
variable "ibmcloud_zone" {
    description = "Denotes which IBM Cloud zone to connect to - .i.e: eu-de-1 eu-de-2  us-south etc."
    default     = "eu-de-1"
}

Problem Solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants