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

[datadog_synthetics] Add TOTP Parameters for Global Variables #1708

Merged
merged 13 commits into from
Jan 17, 2023
62 changes: 62 additions & 0 deletions datadog/resource_datadog_synthetics_global_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ func resourceDatadogSyntheticsGlobalVariable() *schema.Resource {
},
},
},
"options": {
Description: "Additional options to add for the variable, such as an MFA token.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"totp_parameters": {
Description: "Parameters needed for MFA/TOTP.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"digits": {
Description: "Number of digits for the OTP.",
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(4, 10),
},
"refresh_interval": {
Description: "Interval for which to refresh the token (in seconds).",
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(0, 999),
},
},
},
},
},
},
},
"restricted_roles": {
Description: "A list of role identifiers to associate with the Synthetics global variable.",
Type: schema.TypeSet,
Expand Down Expand Up @@ -232,6 +264,19 @@ func buildSyntheticsGlobalVariableStruct(d *schema.ResourceData) *datadogV1.Synt
syntheticsGlobalVariableValue.SetValue(d.Get("value").(string))
syntheticsGlobalVariableValue.SetSecure(d.Get("secure").(bool))

if _, ok := d.GetOk("options.0"); ok {
variableOptions := datadogV1.SyntheticsGlobalVariableOptions{}
totpParameters := datadogV1.SyntheticsGlobalVariableTOTPParameters{}
if digits, ok := d.GetOk("options.0.totp_parameters.0.digits"); ok {
totpParameters.SetDigits(digits.(int32))
}
if refresh_interval, ok := d.GetOk("options.0.totp_parameters.0.refresh_interval"); ok {
totpParameters.SetRefreshInterval(refresh_interval.(int32))
}
variableOptions.SetTotpParameters(totpParameters)
syntheticsGlobalVariableValue.SetOptions(variableOptions)
}

syntheticsGlobalVariable.SetValue(syntheticsGlobalVariableValue)

if parseTestID, ok := d.GetOk("parse_test_id"); ok {
Expand Down Expand Up @@ -326,6 +371,23 @@ func updateSyntheticsGlobalVariableLocalState(d *schema.ResourceData, synthetics
d.Set("parse_test_options", []map[string]interface{}{localParseTestOptions})
}

if syntheticsGlobalVariableValue.HasOptions() {
syntheticsGlobalVariableOptions := syntheticsGlobalVariableValue.GetOptions()
localVariableOptions := make(map[string]interface{})
if syntheticsGlobalVariableOptions.HasTotpParameters() {
syntheticsGlobalVariableTOTPParameters := syntheticsGlobalVariableOptions.GetTotpParameters()
localTotpParameters := make(map[string]interface{})
if syntheticsGlobalVariableTOTPParameters.HasDigits() {
localTotpParameters["digits"] = syntheticsGlobalVariableTOTPParameters.GetDigits()
}
if syntheticsGlobalVariableTOTPParameters.HasRefreshInterval() {
localTotpParameters["refresh_interval"] = syntheticsGlobalVariableTOTPParameters.GetRefreshInterval()
}
localVariableOptions["totp_parameters"] = localTotpParameters
}
d.Set("options", []map[string]interface{}{localVariableOptions})
}

if syntheticsGlobalVariable.HasAttributes() {
attributes := syntheticsGlobalVariable.GetAttributes()
variableRestrictedRoles := attributes.GetRestrictedRoles()
Expand Down
18 changes: 18 additions & 0 deletions docs/resources/synthetics_global_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ resource "datadog_synthetics_global_variable" "test_variable" {
### Optional

- `description` (String) Description of the global variable.
- `options` (Block List, Max: 1) Additional options to add for the variable, such as an MFA token. (see [below for nested schema](#nestedblock--options))
thestefanristovski marked this conversation as resolved.
Show resolved Hide resolved
- `parse_test_id` (String) Id of the Synthetics test to use for a variable from test.
- `parse_test_options` (Block List, Max: 1) ID of the Synthetics test to use a source of the global variable value. (see [below for nested schema](#nestedblock--parse_test_options))
- `restricted_roles` (Set of String) A list of role identifiers to associate with the Synthetics global variable.
Expand All @@ -42,6 +43,23 @@ resource "datadog_synthetics_global_variable" "test_variable" {

- `id` (String) The ID of this resource.

<a id="nestedblock--options"></a>
### Nested Schema for `options`

Optional:

- `totp_parameters` (Block List, Max: 1) Parameters needed for MFA/TOTP. (see [below for nested schema](#nestedblock--options--totp_parameters))

<a id="nestedblock--options--totp_parameters"></a>
### Nested Schema for `options.totp_parameters`

Required:

- `digits` (Number) Number of digits for the OTP.
- `refresh_interval` (Number) Interval for which to refresh the token (in seconds).



<a id="nestedblock--parse_test_options"></a>
### Nested Schema for `parse_test_options`

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go/v2 v2.7.0
github.com/DataDog/datadog-api-client-go/v2 v2.7.1-0.20230111182427-83361af91abe
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/dnaeon/go-vcr v1.0.1
github.com/hashicorp/go-cleanhttp v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-api-client-go/v2 v2.7.0 h1:ntksthF3deJ67aPg6GxO7lDaMUXI9LIKnPj044E54aA=
github.com/DataDog/datadog-api-client-go/v2 v2.7.0/go.mod h1:sHt3EuVMN8PSYJu065qwp3pZxCwR3RZP4sJnYwj/ZQY=
github.com/DataDog/datadog-api-client-go/v2 v2.7.1-0.20230111182427-83361af91abe h1:/e03MoNXq5+fEPA1dSPtikHrLatIzUfqpqEW91UjLmI=
github.com/DataDog/datadog-api-client-go/v2 v2.7.1-0.20230111182427-83361af91abe/go.mod h1:sHt3EuVMN8PSYJu065qwp3pZxCwR3RZP4sJnYwj/ZQY=
github.com/DataDog/datadog-go v4.4.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down