Skip to content

Commit a4a6a3d

Browse files
wyattfrymbfrahry
andauthored
azurerm_datadog_monitor_sso_configuration deprecate single_sign_on_enabled property (#28520)
* resolving 4.0 TODOs * missed docs * attempt at adding tests for the other two SSO states * changes moved to PR #28529 * moved to PRs 28530 28531 * sort imports * feedback * rename property * wip * fix tflint * Apply suggestions from code review Co-authored-by: Matthew Frahry <[email protected]> * wip * feedback * organize imports * docs update for datadog monitor sso conf * remove 4.0 properties * WIP add 2024-10-01-preview sdk * Revert "WIP add 2024-10-01-preview sdk" This reverts commit 6e898f2. * add other possible values --------- Co-authored-by: Matthew Frahry <[email protected]>
1 parent 1b658d2 commit a4a6a3d

File tree

4 files changed

+92
-26
lines changed

4 files changed

+92
-26
lines changed

internal/services/datadog/azurerm_datadog_monitor_sso_configuration.go

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/singlesignon"
1515
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
1616
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
17+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
1718
"github.com/hashicorp/terraform-provider-azurerm/internal/services/datadog/validate"
1819
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1920
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
@@ -25,7 +26,7 @@ import (
2526
// since this appears to be a 1:1 with it (given the name defaults to `default`)
2627

2728
func resourceDatadogSingleSignOnConfigurations() *pluginsdk.Resource {
28-
return &pluginsdk.Resource{
29+
resource := &pluginsdk.Resource{
2930
Create: resourceDatadogSingleSignOnConfigurationsCreate,
3031
Read: resourceDatadogSingleSignOnConfigurationsRead,
3132
Update: resourceDatadogSingleSignOnConfigurationsUpdate,
@@ -63,15 +64,10 @@ func resourceDatadogSingleSignOnConfigurations() *pluginsdk.Resource {
6364
ValidateFunc: validate.DatadogEnterpriseApplicationID,
6465
},
6566

66-
"single_sign_on_enabled": {
67-
Type: pluginsdk.TypeString,
68-
Required: true,
69-
ValidateFunc: validation.StringInSlice([]string{
70-
// @tombuildsstuff: other options are available, but the Create handles this as a boolean for now
71-
// should the field be a boolean? one to consider for 4.0 when this resource is inlined
72-
string(singlesignon.SingleSignOnStatesEnable),
73-
string(singlesignon.SingleSignOnStatesDisable),
74-
}, false),
67+
"single_sign_on": {
68+
Type: pluginsdk.TypeString,
69+
Required: true,
70+
ValidateFunc: validation.StringInSlice(singlesignon.PossibleValuesForSingleSignOnStates(), false),
7571
},
7672

7773
"login_url": {
@@ -80,6 +76,29 @@ func resourceDatadogSingleSignOnConfigurations() *pluginsdk.Resource {
8076
},
8177
},
8278
}
79+
80+
if !features.FivePointOh() {
81+
resource.Schema["single_sign_on"] = &pluginsdk.Schema{
82+
Type: pluginsdk.TypeString,
83+
Optional: true,
84+
Computed: true,
85+
ValidateFunc: validation.StringInSlice(singlesignon.PossibleValuesForSingleSignOnStates(), false),
86+
}
87+
88+
resource.Schema["single_sign_on_enabled"] = &pluginsdk.Schema{
89+
Type: pluginsdk.TypeString,
90+
Optional: true,
91+
Computed: true,
92+
ValidateFunc: validation.StringInSlice([]string{
93+
string(singlesignon.SingleSignOnStatesEnable),
94+
string(singlesignon.SingleSignOnStatesDisable),
95+
}, false),
96+
ExactlyOneOf: []string{"single_sign_on", "single_sign_on_enabled"},
97+
Deprecated: "`single_sign_on_enabled` has been deprecated in favour of the `single_sign_on` property and will be removed in v5.0 of the AzureRM Provider.",
98+
}
99+
}
100+
101+
return resource
83102
}
84103

85104
func resourceDatadogSingleSignOnConfigurationsCreate(d *pluginsdk.ResourceData, meta interface{}) error {
@@ -105,11 +124,16 @@ func resourceDatadogSingleSignOnConfigurationsCreate(d *pluginsdk.ResourceData,
105124

106125
payload := singlesignon.DatadogSingleSignOnResource{
107126
Properties: &singlesignon.DatadogSingleSignOnProperties{
108-
SingleSignOnState: pointer.To(singlesignon.SingleSignOnStates(d.Get("single_sign_on_enabled").(string))),
109-
EnterpriseAppId: utils.String(d.Get("enterprise_application_id").(string)),
127+
EnterpriseAppId: pointer.To(d.Get("enterprise_application_id").(string)),
110128
},
111129
}
112130

131+
if v, ok := d.GetOk("single_sign_on"); ok {
132+
payload.Properties.SingleSignOnState = pointer.To(singlesignon.SingleSignOnStates(v.(string)))
133+
} else if !features.FivePointOh() {
134+
payload.Properties.SingleSignOnState = pointer.To(singlesignon.SingleSignOnStates(d.Get("single_sign_on_enabled").(string)))
135+
}
136+
113137
if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, id, payload); err != nil {
114138
return fmt.Errorf("creating %s: %+v", id, err)
115139
}
@@ -143,10 +167,13 @@ func resourceDatadogSingleSignOnConfigurationsRead(d *pluginsdk.ResourceData, me
143167
if model := resp.Model; model != nil {
144168
if props := model.Properties; props != nil {
145169
// per the create func
146-
singleSignOnEnabled := props.SingleSignOnState != nil && *props.SingleSignOnState == singlesignon.SingleSignOnStatesEnable
147-
d.Set("single_sign_on_enabled", singleSignOnEnabled)
170+
d.Set("single_sign_on", string(pointer.From(props.SingleSignOnState)))
148171
d.Set("login_url", props.SingleSignOnURL)
149172
d.Set("enterprise_application_id", props.EnterpriseAppId)
173+
174+
if !features.FivePointOh() {
175+
d.Set("single_sign_on_enabled", string(pointer.From(props.SingleSignOnState)))
176+
}
150177
}
151178
}
152179

@@ -165,11 +192,16 @@ func resourceDatadogSingleSignOnConfigurationsUpdate(d *pluginsdk.ResourceData,
165192

166193
payload := singlesignon.DatadogSingleSignOnResource{
167194
Properties: &singlesignon.DatadogSingleSignOnProperties{
168-
SingleSignOnState: pointer.To(singlesignon.SingleSignOnStates(d.Get("single_sign_on_enabled").(string))),
169-
EnterpriseAppId: utils.String(d.Get("enterprise_application_id").(string)),
195+
EnterpriseAppId: pointer.To(d.Get("enterprise_application_id").(string)),
170196
},
171197
}
172198

199+
if v, ok := d.GetOk("single_sign_on"); ok && d.HasChange("single_sign_on") {
200+
payload.Properties.SingleSignOnState = pointer.To(singlesignon.SingleSignOnStates(v.(string)))
201+
} else if !features.FivePointOh() {
202+
payload.Properties.SingleSignOnState = pointer.To(singlesignon.SingleSignOnStates(d.Get("single_sign_on_enabled").(string)))
203+
}
204+
173205
if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, *id, payload); err != nil {
174206
return fmt.Errorf("updating %s: %+v", id, err)
175207
}

internal/services/datadog/azurerm_datadog_monitor_sso_configuration_test.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
1414
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
1515
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
16+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
1617
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1718
"github.com/hashicorp/terraform-provider-azurerm/utils"
1819
)
@@ -48,7 +49,24 @@ func TestAccDatadogMonitorSSO_basic(t *testing.T) {
4849
Config: r.basic(data),
4950
Check: acceptance.ComposeTestCheckFunc(
5051
check.That(data.ResourceName).ExistsInAzure(r),
51-
check.That(data.ResourceName).Key("single_sign_on_enabled").HasValue("Enable"),
52+
),
53+
},
54+
data.ImportStep(),
55+
})
56+
}
57+
58+
func TestAccDatadogMonitorSSO_singleSignOnEnabled(t *testing.T) {
59+
if features.FivePointOh() {
60+
t.Skip("Skipping as single_sign_on_enabled is not supported in 5.0")
61+
}
62+
data := acceptance.BuildTestData(t, "azurerm_datadog_monitor_sso_configuration", "test")
63+
r := SSODatadogMonitorResource{}
64+
r.populateValuesFromEnvironment(t)
65+
data.ResourceTest(t, r, []acceptance.TestStep{
66+
{
67+
Config: r.singleSignOnEnabled(data),
68+
Check: acceptance.ComposeTestCheckFunc(
69+
check.That(data.ResourceName).ExistsInAzure(r),
5270
),
5371
},
5472
data.ImportStep(),
@@ -64,7 +82,6 @@ func TestAccDatadogMonitorSSO_requiresImport(t *testing.T) {
6482
Config: r.basic(data),
6583
Check: acceptance.ComposeTestCheckFunc(
6684
check.That(data.ResourceName).ExistsInAzure(r),
67-
check.That(data.ResourceName).Key("single_sign_on_enabled").HasValue("Enable"),
6885
),
6986
},
7087
data.RequiresImportErrorStep(r.requiresImport),
@@ -80,23 +97,20 @@ func TestAccDatadogMonitorSSO_update(t *testing.T) {
8097
Config: r.basic(data),
8198
Check: acceptance.ComposeTestCheckFunc(
8299
check.That(data.ResourceName).ExistsInAzure(r),
83-
check.That(data.ResourceName).Key("single_sign_on_enabled").HasValue("Enable"),
84100
),
85101
},
86102
data.ImportStep(),
87103
{
88104
Config: r.update(data),
89105
Check: acceptance.ComposeTestCheckFunc(
90106
check.That(data.ResourceName).ExistsInAzure(r),
91-
check.That(data.ResourceName).Key("single_sign_on_enabled").HasValue("Disable"),
92107
),
93108
},
94109
data.ImportStep(),
95110
{
96111
Config: r.basic(data),
97112
Check: acceptance.ComposeTestCheckFunc(
98113
check.That(data.ResourceName).ExistsInAzure(r),
99-
check.That(data.ResourceName).Key("single_sign_on_enabled").HasValue("Enable"),
100114
),
101115
},
102116
data.ImportStep(),
@@ -152,6 +166,22 @@ provider "azurerm" {
152166
153167
%s
154168
169+
resource "azurerm_datadog_monitor_sso_configuration" "test" {
170+
datadog_monitor_id = azurerm_datadog_monitor.test.id
171+
single_sign_on = "Enable"
172+
enterprise_application_id = %q
173+
}
174+
`, r.template(data), r.enterpriseAppId)
175+
}
176+
177+
func (r SSODatadogMonitorResource) singleSignOnEnabled(data acceptance.TestData) string {
178+
return fmt.Sprintf(`
179+
provider "azurerm" {
180+
features {}
181+
}
182+
183+
%s
184+
155185
resource "azurerm_datadog_monitor_sso_configuration" "test" {
156186
datadog_monitor_id = azurerm_datadog_monitor.test.id
157187
single_sign_on_enabled = "Enable"
@@ -166,7 +196,7 @@ func (r SSODatadogMonitorResource) requiresImport(data acceptance.TestData) stri
166196
167197
resource "azurerm_datadog_monitor_sso_configuration" "import" {
168198
datadog_monitor_id = azurerm_datadog_monitor_sso_configuration.test.datadog_monitor_id
169-
single_sign_on_enabled = azurerm_datadog_monitor_sso_configuration.test.single_sign_on_enabled
199+
single_sign_on = azurerm_datadog_monitor_sso_configuration.test.single_sign_on
170200
enterprise_application_id = azurerm_datadog_monitor_sso_configuration.test.enterprise_application_id
171201
}
172202
`, r.basic(data))
@@ -182,7 +212,7 @@ provider "azurerm" {
182212
183213
resource "azurerm_datadog_monitor_sso_configuration" "test" {
184214
datadog_monitor_id = azurerm_datadog_monitor.test.id
185-
single_sign_on_enabled = "Disable"
215+
single_sign_on = "Disable"
186216
enterprise_application_id = %q
187217
}
188218
`, r.template(data), r.enterpriseAppId)

website/docs/5.0-upgrade-guide.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ Please follow the format in the example below for listing breaking changes in re
128128

129129
* The `logs_destination` property is no longer Computed and now must be set to `log-analytics` to be able to specify a value for `log_analytics_workspace_id`. It will now default to empty, meaning Streaming Only in the Azure Portal.
130130

131+
### `azurerm_datadog_monitor_sso_configuration`
132+
133+
* The deprecated `single_sign_on_enabled` property has been removed in favour of the `single_sign_on` property.
134+
131135
### `azurerm_eventhub`
132136

133137
* The deprecated `namespace_name` property has been removed in favour of the `namespace_id` property.

website/docs/r/datadog_monitor_sso_configuration.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ resource "azurerm_datadog_monitor" "example" {
3939
4040
resource "azurerm_datadog_monitor_sso_configuration" "example" {
4141
datadog_monitor_id = azurerm_datadog_monitor.example.id
42-
single_sign_on_enabled = "Enable"
43-
enterprise_application_id = "XXXX"
42+
single_sign_on = "Enable"
43+
enterprise_application_id = "00000000-0000-0000-0000-000000000000"
4444
}
4545
```
4646

@@ -50,7 +50,7 @@ The following arguments are supported:
5050

5151
* `datadog_monitor_id` - (Required) The Datadog Monitor Id which should be used for this Datadog Monitor SSO Configuration. Changing this forces a new Datadog Monitor SSO Configuration to be created.
5252

53-
* `single_sign_on_enabled` - (Required) The state of SingleSignOn configuration. Possible values are `Enable` and `Disable`.
53+
* `single_sign_on` - (Required) The state of SingleSignOn configuration. Possible values are `Enable`, `Disable`, `Initial` and `Existing`.
5454

5555
* `enterprise_application_id` - (Required) The application Id to perform SSO operation.
5656

0 commit comments

Comments
 (0)