Closed zerofai closed 3 months ago
Issue still exist in v 4.0.0. provider
`Initializing provider plugins...
Hi, I encountered the same issue. Simply upgrading from rancher2 provider from 3.1.1 to 4.0.0 and I got the same error :
│ Error: Incorrect attribute value type │ │ on create_cluster_rke2.tf line 185, in resource "rancher2_cluster_v2" "moncluster": │ 185: config = { │ 186: system-default-registry = "myregistry.foo.com", │ 187: protect-kernel-defaults = false, │ 188: cloud-provider-name = "rancher-vsphere" │ 189: } │ │ Inappropriate value for attribute "config": string required.
I managed to fix this by converting the attribute to this format :
config = <<EOF system-default-registry: "myregistry.foo.com" protect-kernel-defaults: false cloud-provider-name: "rancher-vsphere" EOF
If this is the only supported syntax, the documentation should be updated. This syntax is mentioned in only one example (https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2#create-a-cluster-with-machine-global-config-or-machine-selector-config)
Edit: It must be related to PR 1223
@SebPlv - I think that's a great fix/workaround, since it seems like the schema did change going from 3.1.1 -> 4.x.
One note is that I think the PR that caused the change is different than the one you linked. The one linked reverts it from a string field, to a map field. Notably, that change only affects clusterV2RKEConfigSystemConfigFieldsV0
which is the function preserved as part of the schema migration method terraform provides.
Essentially that just ensures that the state format is updated correctly, however AFAIK end-users still need to update their plans format to match the new syntax manually.
Again that's very close, but long story short the PR responsible for the new behavior (and not the migrations) is here: https://github.com/rancher/terraform-provider-rancher2/pull/1181 . And overall I believe the "official answer" (which this is not) will be that plans should be updated to use strings.
@mallardduck Thanks for these precisions and pointing out the right PR !
Hi, Does this fix already included in any releases?
Still get the same error in v4.1.0
$ ../bin/terraform -version
Terraform v1.8.5
on linux_amd64
+ provider registry.terraform.io/rancher/rancher2 v4.1.0
@albinsun - this issue is closed and I believe @matttrach did this because the correct solution is to do what Seb suggested. Please adjust your terraform plan accordingly, so that the config
value is a string like:
config = <<EOF
system-default-registry: "myregistry.foo.com"
protect-kernel-defaults: false
cloud-provider-name: "rancher-vsphere"
EOF
@albinsun - this issue is closed and I believe @matttrach did this because the correct solution is to do what Seb suggested. Please adjust your terraform plan accordingly, so that the
config
value is a string like:
Thank you @mallardduck and @matttrach,
I just try to follow an example in latest doc to set machine_selector_config
: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2#create-a-node-driver-cluster-with-harvester-as-both-the-infrastructure-provider-and-cloud-provider
Is the problem from the file()
or path.module
?
If so, how to leverage them in the string form config?
Update
It works by jsonencode
the original object.
...
machine_selector_config {
config = jsonencode({
cloud-provider-config = file("${path.module}/kubeconfig")
cloud-provider-name = "harvester"
})
}
...
@matttrach - Seems like we may have a docs issue, maybe the examples didn't get updated for the change?
Rancher Server Setup
Information about the Cluster
User Information
Provider Information
Describe the bug
With refer to https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2 Example: Creating Rancher v2 harvester cluster v2 with harvester cloud provider Terraform cannot validate, report below: │ on main.tf line 33, in resource "rancher2_cluster_v2" "target-rke2-cluster": │ 33: config = { │ 34: cloud-provider-config = file(var.harvester-cloud-provider-kubeconfig) │ 35: cloud-provider-name = "harvester" │ 36: } │ │ Inappropriate value for attribute "config": string required.
To Reproduce
Use the example to creating Rancher v2 harvester cluster v2 with harvester cloud provider
Actual Result
Terraform validation failed
Expected Result
RKE2 cluster should provision properly with Harvester Cloud Provider install