We are creating registry entries using the rancher2_registry
provider and are running into an issue where when we run terraform apply
again, without any changes, it reorders the list of registries in the object. This appears to be completely random.
Here’s what the data looks like:
variable "containerRepositories" {
type = list(object({
url = string
username = string
password = string
}))
default = []
description = "A list of Docker container repositories."
}
containerRepositories = [
{
url = "dcc-docker-release.<redacted>"
username = "bld_dcc"
password = "<redacted>"
},
{
url = "dcc-docker-dev.<redacted>"
username = "bld_dcc"
password = "<redacted>"
},
{
url = "dcsws-docker-release.<redacted>"
username = "bld_dcc"
password = "<redacted>"
},
{
url = "dcsws-docker-dev.<redacted>"
username = "bld_dcc"
password = "<redacted>"
}
]
resource "rancher2_registry" "regcred-build" {
count = length(var.containerRepositories) > 0 ? 1 : 0
name = "regcred"
description = "Registry entry for k8s to talk to customers Artifactory registries"
project_id = rancher2_project.jenkins-project-build.id
namespace_id = rancher2_namespace.jenkins-namespace-build.id
dynamic "registries" {
for_each = var.containerRepositories
content {
address = registries.value["url"]
username = registries.value["username"]
password = registries.value["password"]
}
}
}
The result of running terraform apply
when there have been no updates. If we apply this, then run it again, they will often “switch back”
~ resource "rancher2_registry" "regcred" {
id = "jenkins-dcs:regcred"
name = "regcred"
# (5 unchanged attributes hidden)
~ registries {
~ address = "dcsws-docker-release.<redacted>" -> "dcc-docker-release.<redacted>"
# (2 unchanged attributes hidden)
}
~ registries {
~ address = "dcc-docker-release.<redacted>" -> "dcsws-docker-release.<redacted>"
# (2 unchanged attributes hidden)
}
# (2 unchanged blocks hidden)
}
We are running Terraform v1.1.9 and rancher/rancher2 v1.23.0
Is there a way to fix this or is it a bug in the provider?