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_test] Add secure field to synthetics config variable #1696

Merged
merged 8 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ func syntheticsConfigVariable() *schema.Schema {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"example": {
Description: "Example for the variable.",
Description: "Example for the variable. This value is not returned by the api when `secure = true`. Avoid drift by only making updates to this value from within Terraform.",
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -1060,7 +1060,7 @@ func syntheticsConfigVariable() *schema.Schema {
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[A-Z][A-Z0-9_]+[A-Z0-9]$`), "must be all uppercase with underscores"),
},
"pattern": {
Description: "Pattern of the variable.",
Description: "Pattern of the variable. This value is not returned by the api when `secure = true`. Avoid drift by only making updates to this value from within Terraform.",
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -1075,6 +1075,12 @@ func syntheticsConfigVariable() *schema.Schema {
Type: schema.TypeString,
Optional: true,
},
"secure": {
Description: "Whether the value of this variable will be obfuscated in test results.",
Type: schema.TypeBool,
Optional: true,
nkzou marked this conversation as resolved.
Show resolved Hide resolved
Default: false,
},
},
},
}
Expand Down Expand Up @@ -1392,6 +1398,7 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA

variable.SetName(variableMap["name"].(string))
variable.SetType(datadogV1.SyntheticsConfigVariableType(variableMap["type"].(string)))
variable.SetSecure(variableMap["secure"].(bool))

if variable.GetType() != "global" {
variable.SetPattern(variableMap["pattern"].(string))
Expand Down Expand Up @@ -1979,6 +1986,7 @@ func buildSyntheticsBrowserTestStruct(d *schema.ResourceData) *datadogV1.Synthet

variable.SetName(variableMap["name"].(string))
variable.SetType(datadogV1.SyntheticsConfigVariableType(variableMap["type"].(string)))
variable.SetSecure(variableMap["secure"].(bool))

if variable.GetType() != "global" {
variable.SetPattern(variableMap["pattern"].(string))
Expand All @@ -1988,7 +1996,6 @@ func buildSyntheticsBrowserTestStruct(d *schema.ResourceData) *datadogV1.Synthet
if variableMap["id"] != "" {
variable.SetId(variableMap["id"].(string))
}

configVariables = append(configVariables, variable)
}
}
Expand Down Expand Up @@ -2546,13 +2553,20 @@ func updateSyntheticsBrowserTestLocalState(d *schema.ResourceData, syntheticsTes
if v, ok := configVariable.GetNameOk(); ok {
localVariable["name"] = *v
}
if v, ok := configVariable.GetSecureOk(); ok {
localVariable["secure"] = *v
}

if configVariable.GetType() != "global" {
if v, ok := configVariable.GetExampleOk(); ok {
localVariable["example"] = *v
} else if localVariable["secure"].(bool) {
localVariable["example"] = d.Get(fmt.Sprintf("config_variable.%d.example", i))
}
if v, ok := configVariable.GetPatternOk(); ok {
localVariable["pattern"] = *v
} else if localVariable["secure"].(bool) {
localVariable["pattern"] = d.Get(fmt.Sprintf("config_variable.%d.pattern", i))
}
}
if v, ok := configVariable.GetIdOk(); ok {
Expand Down Expand Up @@ -2858,13 +2872,20 @@ func updateSyntheticsAPITestLocalState(d *schema.ResourceData, syntheticsTest *d
if v, ok := configVariable.GetNameOk(); ok {
localVariable["name"] = *v
}
if v, ok := configVariable.GetSecureOk(); ok {
localVariable["secure"] = *v
}

if configVariable.GetType() != "global" {
if v, ok := configVariable.GetExampleOk(); ok {
localVariable["example"] = *v
} else if localVariable["secure"].(bool) {
localVariable["example"] = d.Get(fmt.Sprintf("config_variable.%d.example", i))
}
if v, ok := configVariable.GetPatternOk(); ok {
localVariable["pattern"] = *v
} else if localVariable["secure"].(bool) {
localVariable["pattern"] = d.Get(fmt.Sprintf("config_variable.%d.pattern", i))
}
}
if v, ok := configVariable.GetIdOk(); ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:06:26.139859-05:00
2023-01-03T14:15:03.054505-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:06:26.139819-05:00
2023-01-03T12:00:19.209307-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:06:09.724039-05:00
2023-01-03T14:14:04.914892-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:06:09.72404-05:00
2023-01-03T12:00:46.474025-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:07:15.578709-05:00
2023-01-03T14:14:20.983446-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:04:25.395068-05:00
2023-01-03T14:13:22.762164-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:05:50.841582-05:00
2023-01-03T14:13:37.237676-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:05:50.841582-05:00
2023-01-03T14:13:51.188725-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-10T13:07:01.055749-05:00
2023-01-03T14:14:37.02154-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-12-14T12:02:22.172566+01:00
2023-01-03T14:14:49.955164-05:00

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem
"datadog_synthetics_test.foo", "config_variable.0.pattern", "{{numeric(3)}}"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "config_variable.0.example", "123"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "config_variable.0.secure", "false"),
resource.TestCheckResourceAttrSet(
"datadog_synthetics_test.foo", "monitor_id"),
),
Expand Down Expand Up @@ -721,6 +723,7 @@ resource "datadog_synthetics_test" "foo" {
config_variable {
type = "text"
name = "VARIABLE_NAME"
secure = false
pattern = "{{numeric(3)}}"
example = "123"
}
Expand Down
5 changes: 3 additions & 2 deletions docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,10 @@ Required:

Optional:

- `example` (String) Example for the variable.
- `example` (String) Example for the variable. This value is not returned by the api when `secure = true`. Avoid drift by only making updates to this value from within Terraform.
- `id` (String) When type = `global`, ID of the global variable to use.
- `pattern` (String) Pattern of the variable.
- `pattern` (String) Pattern of the variable. This value is not returned by the api when `secure = true`. Avoid drift by only making updates to this value from within Terraform.
- `secure` (Boolean) Whether the value of this variable will be obfuscated in test results.


<a id="nestedblock--options_list"></a>
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.6.1
github.com/DataDog/datadog-api-client-go/v2 v2.6.2-0.20230103144058-206cab210054
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.6.1 h1:THstTY4UQUFbojIoOOKjWdomc6Q0Gl1bAoCY0UOo2XY=
github.com/DataDog/datadog-api-client-go/v2 v2.6.1/go.mod h1:sHt3EuVMN8PSYJu065qwp3pZxCwR3RZP4sJnYwj/ZQY=
github.com/DataDog/datadog-api-client-go/v2 v2.6.2-0.20230103144058-206cab210054 h1:gxTzc7oCnZJvdrJErVUVa79mckCSIHQUJPUmp9nFGUg=
github.com/DataDog/datadog-api-client-go/v2 v2.6.2-0.20230103144058-206cab210054/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