|
| 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 | +} |
0 commit comments