ionos-cloud / terraform-provider-ionoscloud

The IonosCloud Terraform provider gives the ability to deploy and configure resources using the IonosCloud APIs.
Mozilla Public License 2.0
34 stars 23 forks source link

Overriding `endpoint` in provider configuration isn't used for retrieving requests #496

Closed maxbischoff closed 9 months ago

maxbischoff commented 9 months ago

Description

We are using an API proxy for accessing the IONOS API, which we configure by setting IONOS_API_URL. This address is successfully used to let the terraform provider make requests to create resources (e.g. ionoscloud_user), but when retrieving the status for the underlying request, the wrong endpoint (which is not resolvable/reachable from our environment) is used, causing the resource creation to fail.

Expected behavior

I expect the provider to use the configured IONOS API endpoint for all requests to the IONOS API.

Environment

Terraform version:

1.5.3

Provider version:

6.4.10

OS:

Ubuntu

How to Reproduce

In our setup, we use a Proxy to access the IONOS API. The default endpoint is not reachable from our environment. For reproducing the error in such a setup, you simply need to run terraform apply with an overriden endpoint and any example resouce (I tested it with ionoscloud_user):

provider "ionoscloud" { endpoint = "http://my-proxy.local" }

resource "ionoscloud_user" "this" { active = true first_name = "test" last_name = "User" email = "test123@example.com"

password = "doesntmatter administrator = false }

Error and Debug Output

Error: request failed with following error: Get "https://<redacted>/cloudapi/v6/requests/<uid>/status": dial tcp: lookup <redacted> on 10.233.41.224:53: no such host

   with ionoscloud_user.this,
   on main.tf line 41, in resource "ionoscloud_user" "this":
   41: resource "ionoscloud_user" "this" { 

<redacted> is the base-API-URL that is returned in the LOCATION header from the user-creation response.

Additional Notes

I looked at the provider and go-sdk and found that after creating a resource (i.e. user), the LOCATION header from the response is used to retrieve the request status, and the function from the ionos go-sdk would override the host of the location header when it is configured in the client. The host and scheme are never set on the client, neither explicitly when the terraform provider configures it, nor implicitly in the client's NewApiClient or [NewConfiguration](https://github.com/ionos-cloud/sdk-go/blob/master/configuration.go#L130) methods.

maxbischoff commented 9 months ago

@LiviusP is there any way I can help with fixing this?

cristiGuranIonos commented 9 months ago

Looking at how to best override the location header that's being returned

maxbischoff commented 9 months ago

I believe the best fix would be to simply fix the configuration in https://github.com/ionos-cloud/sdk-go/blob/master/configuration.go#L130 by setting Host and Scheme when the hostUrl is set. Then the sdk will already override the location header for us.

cristiGuranIonos commented 9 months ago

We're doing some tests. If you have something that works, you can maybe create a PR? We always encourage the creation of PRs.

maxbischoff commented 9 months ago

I believe https://github.com/ionos-cloud/sdk-resources/pull/339 could address this. To my understanding that repo generates the SDKs, correct? If that approach looks generally good to you @cristiGuranIonos, I can also add tests and add the code to the other client's templates.

cristiGuranIonos commented 8 months ago

Should be fixed in v6.4.11

maxbischoff commented 8 months ago

Thanks, that worked for me :)