terraform-provider-rancher2
terraform-provider-rancher2 copied to clipboard
rancher2_bootstrap error: [ERROR] Normalizing url: no api_url provided
I'm getting this error while trying to get access with the rancher2_bootstrap resource
Full output:
$ terragrunt apply
╷
│ Error: Invalid provider configuration
│
│ Provider "registry.terraform.io/rancher/rancher2" requires explicit
│ configuration. Add a provider block to the root module and configure the
│ provider's required arguments as described in the provider documentation.
│
╵
╷
│ Error: [ERROR] Normalizing url: no api_url provided
│
│ with provider["registry.terraform.io/rancher/rancher2"],
│ on <empty> line 0:
│ (source code not available)
│
╵
ERRO[0012] 1 error occurred:
* exit status 1
My config
provider "rancher2" {
alias = "bootstrap"
api_url = "https://rancher.server.com"
bootstrap = true
}
resource "rancher2_bootstrap" "admin" {
provider = rancher2.bootstrap
password = var.rancher_password
}
terraform {
required_providers {
rancher2 = {
source = "rancher/rancher2"
version = "1.23.0"
}
}
}
If someone knows a fix or a better way to access rancher, I'm interested :)
In case it can help someone else, my workaround to get the rancher admin token:
data "external" "hack-extract-rancher-admin-password" {
program = ["bash", "${path.module}/get-admin-token.sh"]
query = {
rancher_admin_password = var.rancher_admin_password
rancher_domain_name = var.rancher_domain_name
}
depends_on = [helm_release.rancher]
}
get-admin-token.sh
:
#!/usr/bin/env bash
set -euo pipefail
# read input json for args
eval "$(jq -r '@sh "rancher_admin_password=\(.rancher_admin_password) rancher_domain_name=\(.rancher_domain_name)"')"
# build rancher query data
data=$(cat <<EOF
{
"responseType":"cookie",
"username":"admin",
"password":"${rancher_admin_password}"
}
EOF
)
# sed out the token
rancher_admin_token=$(curl -q -v "https://${rancher_domain_name}/v3-public/localProviders/local?action=login" --data-raw "$data" 2>&1 \
| grep 'set-cookie.*token' \
| sed -E 's/.*=(token[^;]+);.*/\1/')
# output value in json
jq -n --arg rancher_admin_token "$rancher_admin_token" '{"rancher_admin_token":$rancher_admin_token}'
Your solution matches the description from which leads to your error-message https://registry.terraform.io/providers/rancher/rancher2/latest/docs
a working version is mentioned here https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/bootstrap
so this would be the outcome
# Provider bootstrap config with alias
provider "rancher2" {
api_url = "https://${var.rancher_hostname}"
bootstrap = true
}
# Create a new rancher2_bootstrap
resource "rancher2_bootstrap" "admin" {
password = "${var.rancher_bootstrap_password}"
telemetry = true
}
# Provider config for admin
provider "rancher2" {
alias = "admin"
api_url = rancher2_bootstrap.admin.url
token_key = rancher2_bootstrap.admin.token
insecure = true
}
Thanks for your reply @KittlitzMichael, sadly I'm not into this work anymore.
Hopefully it will help someone else
Getting the same error. Looks like someone got it working on the other issue but didn't explain how. Above code on this issue gives same error... 🤔 will update if I find a solution.
I too am having an issue only when I try to do an import. A plain apply works just fine
I was receiving this error because I had 2x provider "rancher2"
blocks, both with different aliases (i.e. rancher2.bootstrap
and rancher2.admin
).
If any rancher2
resources are written without referring to a specific alias (e.g. a rancher2_role_template
resource that does not include provider = rancher2.admin
) it will initialise with an empty provider and thus produce this error message.
@justdan96 that was exactly my issue. Thank you so much :slightly_smiling_face:
I have a module with so many resources and have possible one of two ranchers. I pass the provider in the root module and still get same error.
Error
│ Error: [ERROR] Normalizing url: no api_url provided
│
│ with provider["registry.terraform.io/rancher/rancher2"],
│ on <empty> line 0:
│ (source code not available)
│
calling root module
module "cluster" {
providers = {
rancher2 = rancher2.southeast
}
source = "./terraform-rancher-cluster-install"
# Variables
group_name = "group1"
kubernetes_version = "v1.28.8"
project_name = "appdevprjct"
rancher_env = "southeast"
}
Providers
provider "rancher2" {
alias = "rancher-southwest"
api_url = data.vault_generic_secret.terraform_rancher_southwest.data["endpoint"]
token_key = data.vault_generic_secret.terraform_rancher_southwest.data["bearer_token"]
}
provider "rancher2" {
alias = "rancher-southeast"
api_url = data.vault_generic_secret.terraform_rancher_southeast.data["endpoint"]
token_key = data.vault_generic_secret.terraform_rancher_southeast.data["bearer_token"]
}
data for modules
data "vault_generic_secret" "terraform_rancher_southeast" {
path = "terraform/rancher-southeast"
}
data "vault_generic_secret" "terraform_rancher_southwest" {
path = "terraform/rancher-southwest"
}