Skip to content

Commit fd7f8e6

Browse files
committed
test(serviceuser): Adds dynatrace_iam_service_user E2E test
1 parent e3bccee commit fd7f8e6

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//go:build integration
2+
3+
/**
4+
* @license
5+
* Copyright 2025 Dynatrace LLC
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package serviceusers_test
21+
22+
import (
23+
"testing"
24+
25+
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/testing/api"
26+
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider"
27+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
28+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
29+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
30+
)
31+
32+
func TestAccServiceUsers(t *testing.T) {
33+
if !api.AccEnvsGiven(t) {
34+
return
35+
}
36+
37+
groupName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
38+
t.Setenv("TF_VAR_GROUP_NAME", groupName)
39+
serviceUserName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
40+
t.Setenv("TF_VAR_SERVICE_USER_NAME", serviceUserName)
41+
42+
configCreate, _ := api.ReadTfConfig(t, "testdata/create.tf")
43+
configUpdate, _ := api.ReadTfConfig(t, "testdata/update.tf")
44+
45+
providerFactories := map[string]func() (*schema.Provider, error){
46+
"dynatrace": func() (*schema.Provider, error) {
47+
return provider.Provider(), nil
48+
},
49+
}
50+
51+
t.Run("Updating description and groups of service user", func(t *testing.T) {
52+
testCase := resource.TestCase{
53+
ProviderFactories: providerFactories,
54+
Steps: []resource.TestStep{
55+
{Config: configCreate}, // creates service user with group
56+
{Config: configUpdate}, // updates description, removes group
57+
},
58+
}
59+
resource.Test(t, testCase)
60+
})
61+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "GROUP_NAME" {
2+
description = "The name of the group."
3+
type = string
4+
}
5+
6+
resource "dynatrace_iam_group" "my-group" {
7+
name = var.GROUP_NAME
8+
description = "A group created for e2e testing."
9+
}
10+
11+
variable "SERVICE_USER_NAME" {
12+
description = "The name of the service user."
13+
type = string
14+
}
15+
16+
resource "dynatrace_iam_service_user" "test_service_user" {
17+
name = var.SERVICE_USER_NAME
18+
description = "a service user for testing purposes"
19+
groups = [ dynatrace_iam_group.my-group.id ]
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "SERVICE_USER_NAME" {
2+
description = "The name of the service user."
3+
type = string
4+
}
5+
6+
resource "dynatrace_iam_service_user" "test_service_user" {
7+
name = var.SERVICE_USER_NAME
8+
description = "an updated description"
9+
groups = []
10+
}

0 commit comments

Comments
 (0)