Skip to content

Bug in role binding patch #713

@simonklb

Description

@simonklb

I noticed that during an in-place update of the subjects in a kubernetes_cluster_role_binding resource the resulting applied changes were incorrect. This seems to be happening when the update changes the number of subjects and the order they are added. The plan looks correct but when applied the resulting subjects in the Kubernetes resource are incorrect.

This is a pretty critical error as it could give the user a false sense of assurance that the correct access rules are in place while they are in fact not.

Terraform Version

Terraform v0.12.17

  • provider.kubernetes v1.10.0

Affected Resource(s)

  • kubernetes_cluster_role_binding
  • kubernetes_role_binding (probably, not tested)

Terraform Configuration Files

resource "kubernetes_cluster_role_binding" "cluster_admin" {
  metadata {
    name = "custom-cluster-admin"
  }

  role_ref {
    api_group = "rbac.authorization.k8s.io"
    kind      = "ClusterRole"
    name      = "cluster-admin"
  }

  dynamic "subject" {
    for_each = local.rbac_cluster_admin_users
    content {
      kind      = "User"
      name      = subject.value
      api_group = "rbac.authorization.k8s.io"
    }
  }

  dynamic "subject" {
    for_each = local.rbac_cluster_admin_groups
    content {
      kind      = "Group"
      name      = subject.value
      api_group = "rbac.authorization.k8s.io"
    }
  }
}

Expected Behavior

The correct subjects in the ClusterRoleBinding k8s resource.

Actual Behavior

Incorrect subjects in the ClusterRoleBinding k8s resource.

Steps to Reproduce

  1. Update the kubernetes_cluster_role_binding resource subject configuration.
  2. terraform apply
  3. terraform apply again

See the failing test case I commited here for a specific example: #712

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions