-
Notifications
You must be signed in to change notification settings - Fork 130
container_namespace should infer project_id from provider but doesn't #3068
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
Comments
Hello thanks for filling up the issue. Could you try to set it explicitly to see if it can solve the problem in the meantime we prepare a fix? https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/container_namespace |
Hi @remyleone I did that (see step 3 in "Steps to reproduce"). Setting the |
Another weird, possibly related thing here. My workaround adding the |
I was just deleting a container namespace that was created in the wrong project (due to this bug) and I noticed that the |
Hi again, it seems this bug is not constrained to this specific resource. I'm currently in the process of testing out Scaleway specifically, and my first 'demo project' was a serverless container setup, but now I'm delving into other things and I'm seeing the same issue. Code:
The Similar to the issue with the container namespace, if I add the This leads me to believe that some internal shared logic used to determine the project ID if it isn't set as a resource argument is broken. |
Hello @bennycornelissen |
Update: after some back-and-forth with @remyleone on Slack, it seems we may have found the issue: provider config precedence, in a way that I simply hadn't considered. In my environment, I had the following variables set: ❯ hasenv SCW
SCW_SECRET_KEY
SCW_DEFAULT_ORGANIZATION_ID
SCW_ACCESS_KEY
SCW_DEFAULT_PROJECT_ID The In my Terraform code, I tested 2 types of provider config; one simple, and one a bit more elaborate: Flavor one: provider "scaleway" {
project_id = "<UUID here>"
region = "nl-ams"
zone = "nl-ams-1"
} Flavor two: locals {
scw_provider_region = "nl-ams"
scw_provider_zone = "nl-ams-1"
scw_provider_project_name = "<my project name here>"
environment_name = "k8s-cluster-basic"
}
# This is the 'root' provider. We use this to dynamically get the UUID for the Scaleway project we actually
# want to create resources in
provider "scaleway" {
alias = "scaleway-root"
# NOTE: Authentication secret, Org ID, and default project are expected to be supplied through the environment.
# make sure you set SWC_ACCESS_KEY, SWC_SECRET_KEY, SCW_DEFAULT_ORGANIZATION_ID, and SCW_DEFAULT_PROJECT_ID
region = local.scw_provider_region
zone = local.scw_provider_zone
}
# Look up the Scaleway project
data "scaleway_account_project" "project" {
name = local.scw_provider_project_name
provider = scaleway.scaleway-root
}
# This is the 'main' scaleway provider that we will use for all other resources
provider "scaleway" {
project_id = data.scaleway_account_project.project.id
region = local.scw_provider_region
zone = local.scw_provider_zone
} Then, if I would create a project-scoped resource without specifying a Unsetting that variable works. If my environment looks like below, my project-scoped resources are created in the project where I expect them, and even my 'Flavor two' approach with a 'scaleway-root provider' to look up the actual project UUID based on name works perfectly. ❯ hasenv SCW
SCW_SECRET_KEY
SCW_DEFAULT_ORGANIZATION_ID
SCW_ACCESS_KEY So it may very well be that this 'bug' is a massive case of PEBKAC on my end 😅 Unless this behaviour is not intentional.. then it's a bug. I'm not sure if the docs are clear enough on this particular provider config precedence, or that I just did a poor job of reading them (very possible). I'll leave that to you to decide. TL;DR: if you are setting |
Hello, ahah ok exactly, I was writing you and saw your comment 🥇
|
@Gnoale I got a Slack message from @remyleone earlier today, asking me to check my environment variables... 😉 It's been a few years since provider config precedence caught me. Good call as well on not changing the order either 👍 |
It would still be helpful to provide more logs about the origin of the credentials we get. So that way it is clear to identify the provenance. CLI is already doing it. We might implement it in the logs of terraform |
Also, as I mentioned on Slack as well, you can't really tell at the plan stage currently in which project resources will be created as it's a computed value. While I understand that's not easily fixed, it would be helpful to offer a provider level argument as a safeguard, similar to the Example:
If I were to run Terraform with any other project ID (no matter where it comes from), it would stop because the project ID is not allowed. |
We will improve logging #3099 (comment) |
Terraform Version
Affected Resource(s)
scaleway_container_namespace
Terraform Configuration Files
Expected Behavior
Create a Serverless Containers namespace in the project matching the ID from the provider.
Actual Behavior
Creates a Serverless Containers namespace in the default project.
Steps to Reproduce
scaleway_container_namespace
resource, adding in theproject_id
argumentThe text was updated successfully, but these errors were encountered: