Skip to content
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

feat: add manage-namespaces and updatepsa to verb list #1392

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

alegrey91
Copy link
Contributor

@alegrey91 alegrey91 commented Sep 2, 2024

Issue: #1219

Problem

manage-namespaces and updatepsa verbs were not available to be used in RoleTemplate rules.

Solution

Add manage-namespaces and updatepsa to the list of available verbs.

Testing

Engineering Testing

Manual Testing

Run a rancher instance using docker:

sudo docker run --privileged -it --rm -p 80:80 -p 443:443 --dns 1.1.1.1 -e CATTLE_BOOTSTRAP_PASSWORD=password rancher/rancher

Build the terraform plugin:

make build 

Move the binary under the right directory for plugins:

mkdir -p ~/.terraform.d/plugins/terraform.local/local/rancher2/4.3.0/linux_amd64/
mv terraform-provider-rancher2 ~/.terraform.d/plugins/terraform.local/local/rancher2/4.3.0/linux_amd64/

Create a terraform file with the following content (main.tf):

provider "rancher2" {
  api_url    = "https://localhost:443/"
  access_key = "token-xxxx"
  secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  insecure = true
}

resource "rancher2_user" "testuser" {
  name     = "Test User"
  username = "testuser"
  password = "password12345"
  enabled     = true
}

# Assign global role bindings to the user (optional)
resource "rancher2_global_role_binding" "new_user_role" {
  user_id       = rancher2_user.testuser.id
  global_role_id = "user-base"
}

resource "rancher2_role_template" "foo-test" {
  name = "foo-test"
  context = "project"
  default_role = true
  description = "Terraform role template acceptance test"
  rules {
    api_groups = ["management.cattle.io"]
    resources = ["projects"]
    verbs = ["manage-namespaces", "updatepsa"]
  }
}

Replace access_key and secret_key with your rancher instance keys.

Create another file provider.tf:

terraform {
  required_providers {
    rancher2 = {
      source = "terraform.local/local/rancher2"
      version = "4.3.0"
    }
  }
}

Run terraform and check the resource has been created properly:

terraform init
terraform plan
terraform apply

@alegrey91 alegrey91 self-assigned this Sep 6, 2024
@alegrey91 alegrey91 marked this pull request as ready for review September 6, 2024 13:58
Copy link

@enrichman enrichman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Policy Rules are used also by the Global Role: https://github.com/rancher/terraform-provider-rancher2/blob/master/rancher2/schema_global_role.go#L39

So the docs of that needs to be updated in the same way.

Signed-off-by: Alessio Greggi <[email protected]>
@alegrey91 alegrey91 merged commit 4336cd6 into rancher:master Sep 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants