terraform-provider-dynatrace icon indicating copy to clipboard operation
terraform-provider-dynatrace copied to clipboard

[Feature Request] Create New groups and assign users

Open jonormann opened this issue 3 years ago • 18 comments

Hi, we would like to have the ability to create groups and optionally also assign users. So a self-service based on terraform would be possibe to create a new management zone or environment, create a group for with permissions to that zone or env and assign users (also possible automatically done by mapping the group name to SSO or LDAP groups). Thanks, great work!

Best Joerg

jonormann avatar May 21 '21 08:05 jonormann

We're planning to add the ability to create Environments by the end of June. For that we'll anyways will be required to target additional REST APIs other than the Config API. I'm going to plan in your suggestions right after Environment Creation.

Would you be able and willing to contribute some samples regarding this feature request, for how the HCL code could look like? It doesn't need to be complete and thoroughly perfect. It would just give me an idea for how users expect the terraform files to look like.

I will keep this issue open for the time being as a way to communicate.

Dynatrace-Reinhard-Pilz avatar May 21 '21 11:05 Dynatrace-Reinhard-Pilz

@Dynatrace-Reinhard-Pilz sure i would like to participate.

jonormann avatar May 21 '21 11:05 jonormann

first mockup. Maybe the environments in the list of permissions could also be done by name and the provider gets the GUIDs.

ressource "dynatrace_usergroup" "group"{
	name = "dynatrace_users"
	isClusterAdminGroup = false
	isAccessAccount = true
	isManageAccount = true
	hasAccessAccountRole = true
	hasManageAccountAndViewProductUsageRole = true
	ldapGroupNames = {
		"dynatrace_user_group", 
		"dynatrace_admin_group"
	}
	ssoGroupNames = {
		"dynatrace_user_group", 
		"dynatrace_admin_group"
	}
	accessRight = {
		VIEWER = {
			xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
		}
		MANAGE_SETTINGS = {
			xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
		}
		AGENT_INSTALL = {
			xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
		}
		VIEW_SENSITIVE_REQUEST_DATA = {
			xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
		}
		CONFIGURE_REQUEST_CAPTURE_DATA = {
			xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
		}
	}
}

jonormann avatar May 25 '21 17:05 jonormann

You're right, it would be preferrable to work without GUIDs here. I'll try to stick with your proposal for the first version of this feature.

Dynatrace-Reinhard-Pilz avatar May 26 '21 07:05 Dynatrace-Reinhard-Pilz

Hi, could you tell when this ressource could be added? We need a automatic way to easily create groups and add users in a managed cluster. Would be nice to do that within our existing config pipeline :)

Best Joerg

jonormann avatar Dec 01 '21 10:12 jonormann

Hi, any new updates to this? Could you tell if this is coming in the next versions? Best Joerg

jonormann avatar Jan 28 '22 10:01 jonormann

Hello Joerg,

Sorry for the delays here. We're currently busy with preparations for Perform 2022. I'm planning to release a new version in the week of Feb 14th. User Groups will be among the new features.

best regards, Reinhard

Dynatrace-Reinhard-Pilz avatar Jan 28 '22 11:01 Dynatrace-Reinhard-Pilz

Hi, I currently get an error when I create a dynatrace_user_group

╷
│ Error: Post "/api/v1.0/onpremise/groups": unsupported protocol scheme ""
│
│   with module.dev.dynatrace_user_group.user_groups[0],
│   on modules/environment/user-groups.tf line 1, in resource "dynatrace_user_group" "user_groups":
│    1: resource "dynatrace_user_group" "user_groups" {
│
╵

my code:

resource "dynatrace_user_group" "user_groups" {
  count = length(var.user_groups)

  name =var.user_groups[count.index].name
  permissions{
    dynamic "grant"{
      for_each = var.user_groups[count.index].permissions
      content {
        permission = grant.value
        environments = [var.stage]
      }
    }
  }
}

my var:

user_groups = [
  {
    name = "DEV-DT-SRE",
    permissions = ["VIEWER", "VIEW_SENSITIVE_REQUEST_DATA"]
  },
  {
    name = "DEV-DT-TSM",
    permissions = ["VIEWER", "VIEW_SENSITIVE_REQUEST_DATA"]
  }
]

jonormann avatar Feb 22 '22 07:02 jonormann

Hello Joerg,

Can you check how the configuration of your provider looks like? In order to use the resources that target the Cluster REST API you need to specify dt_cluster_url and dt_cluster_api_token, simiarly like this:

  dt_cluster_api_token = "dt0c01.###############"
  dt_cluster_url = "https://<hostname-or-ip>"

The properties dt_env_url and dt_api_token are still required if you want to configure a specific environment.

I might have mentioned these two additional configuration parameters in previous release notes, but I have to shamefully admit, that they are not yet anywhere to find within the documentation. This will be taken care of with the next bug fix release.

Dynatrace-Reinhard-Pilz avatar Feb 22 '22 10:02 Dynatrace-Reinhard-Pilz

ahh... 👍

jonormann avatar Feb 22 '22 10:02 jonormann

unfortunately there is a new error during terraform apply.

╷
│ Error: invalid character '<' looking for beginning of value
│ 
│   with module.dev.dynatrace_user_group.user_groups[0],
│   on modules/environment/user-groups.tf line 1, in resource "dynatrace_user_group" "user_groups":
│    1: resource "dynatrace_user_group" "user_groups" {
│ 
╵

terraform plan looks okay, I think.

 # module.dev.dynatrace_user_group.user_groups[1] will be created
  + resource "dynatrace_user_group" "user_groups" {
      + id   = (known after apply)
      + name = "DEV-DT-TSM"

      + permissions {
          + grant {
              + environments = [
                  + "gb6aa68e-0670-6h16-8a8e-e51863f68h4k",
                ]
              + permission   = "VIEWER"
            }
          + grant {
              + environments = [
                  + "gb6aa68e-0670-6h16-8a8e-e51863f68h4k",
                ]
              + permission   = "VIEW_SENSITIVE_REQUEST_DATA"
            }
        }
    }

Do you have any idea?

jonormann avatar Feb 22 '22 13:02 jonormann

got the issue... my URL had /e/ at the end because I needed it for the other resources.

now it works.

jonormann avatar Feb 22 '22 14:02 jonormann

I was just about to respond with the same assumption. Fixing / allowing for that is on my bucket list for the next bugfix release.

Can you ping me here once you've successfully configured the users using the new version? I'll keep the issue open until then.

Dynatrace-Reinhard-Pilz avatar Feb 22 '22 14:02 Dynatrace-Reinhard-Pilz

Hi, sure, I can. I also found out that setting the permission to a spectic management zone for a group is currently not implemented. Are you implementing this in the next release?

jonormann avatar Feb 23 '22 12:02 jonormann

You are correct - that's not yet implemented. As far as the REST API is concerned, this is an additional endpoint. I'm at the moment still unsure whether to simply implement it as a separate resource (with a foreign key to the user group) or whether to embed it as an additional section within dynatrace_user_group. Both approaches come with pros and cons. I didn't want to push back last weeks release again, just because of that and decided to provide the core functionality first. But yes, you can expect to have it covered by mid March.

What by the way is also not properly covered are policies. They CAN get assigned via Cluster WebUI, but there doesn't exist yet anything within the Cluster REST API for that.

Dynatrace-Reinhard-Pilz avatar Feb 23 '22 12:02 Dynatrace-Reinhard-Pilz

Hi, any updates here for management zone permissions?

Best Joerg

jonormann avatar Apr 01 '22 09:04 jonormann

Sorry, I won't be able to get it into todays release anymore, but it's the next task I'm going to focus on.

Dynatrace-Reinhard-Pilz avatar Apr 01 '22 10:04 Dynatrace-Reinhard-Pilz

Hi, I'm also looking forward to have the feature that setting the permission to a specific management zone for a group, gave my thumbs up here.

MinsonTFW avatar Aug 25 '22 09:08 MinsonTFW

Hello, Nice work. Could you write a example in documentation for simple usage ? Thanks

hvad avatar Nov 30 '22 10:11 hvad

Hi, any updates here for management zone permissions?

Best Joerg

Hi @Dynatrace-Reinhard-Pilz the feature of setting permissions on Management zone level is not currently supported am I right? KR Michael

mbrunn avatar Mar 08 '23 17:03 mbrunn

Hi everyone, I will do my best to squeeze that in for v1.23.0. I know that resource is long overdue.

Dynatrace-Reinhard-Pilz avatar Mar 09 '23 09:03 Dynatrace-Reinhard-Pilz

v1.23.0 introduces the resource dynatrace_iam_permission.

Dynatrace-Reinhard-Pilz avatar Mar 15 '23 14:03 Dynatrace-Reinhard-Pilz

@Dynatrace-Reinhard-Pilz This only works for SaaS installations am I right?

v1.23.0 introduces the resource dynatrace_iam_permission.

mbrunn avatar Mar 15 '23 15:03 mbrunn

You're right, @mbrunn, my focus was on SaaS, didn't think of the counterpart for managed clusters. I will take care of managed with the next release. You can expect that to happen by the end of next week.

Dynatrace-Reinhard-Pilz avatar Mar 16 '23 07:03 Dynatrace-Reinhard-Pilz

Fixed with this commit - resource dynatrace_mgmz_permission

Dynatrace-Reinhard-Pilz avatar Mar 16 '23 10:03 Dynatrace-Reinhard-Pilz

Thank you very much. This will help me tremendously with my current project of migrating hundreds of users and their permissions from two seperate managed installations to one new managed installation.

mbrunn avatar Mar 16 '23 10:03 mbrunn