Skip to content

Commit 4e8abd7

Browse files
authored
feat: add secret variables support [sc-21027] (#300)
* feat: add secret variables support [sc-21027] * feat: use go sdk v1.8.1 * chore: trigger build & test * chore: revert last change * feat: add simple tests
1 parent 899cab8 commit 4e8abd7

9 files changed

+44
-8
lines changed

checkly/resource_check.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func resourceCheck() *schema.Resource {
132132
"environment_variable": {
133133
Type: schema.TypeList,
134134
Optional: true,
135-
Description: "Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden. These are only relevant for browser checks. Use global environment variables whenever possible.",
135+
Description: "Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden, add secret = true to create a secret variable. These are only relevant for browser checks. Use global environment variables whenever possible.",
136136
Elem: &schema.Resource{
137137
Schema: map[string]*schema.Schema{
138138
"key": {
@@ -148,6 +148,11 @@ func resourceCheck() *schema.Resource {
148148
Optional: true,
149149
Default: false,
150150
},
151+
"secret": {
152+
Type: schema.TypeBool,
153+
Optional: true,
154+
Default: false,
155+
},
151156
},
152157
},
153158
},
@@ -968,10 +973,12 @@ func environmentVariablesFromSet(s []interface{}) []checkly.EnvironmentVariable
968973
key := tm["key"].(string)
969974
value := tm["value"].(string)
970975
locked := tm["locked"].(bool)
976+
secret := tm["secret"].(bool)
971977
res = append(res, checkly.EnvironmentVariable{
972978
Key: key,
973979
Value: value,
974980
Locked: locked,
981+
Secret: secret,
975982
})
976983
}
977984

checkly/resource_check_group.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func resourceCheckGroup() *schema.Resource {
7676
"environment_variable": {
7777
Type: schema.TypeList,
7878
Optional: true,
79-
Description: "Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden. These are only relevant for browser checks. Use global environment variables whenever possible.",
79+
Description: "Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden, add secret = true to create a secret variable. These are only relevant for browser checks. Use global environment variables whenever possible.",
8080
Elem: &schema.Resource{
8181
Schema: map[string]*schema.Schema{
8282
"key": {
@@ -92,6 +92,11 @@ func resourceCheckGroup() *schema.Resource {
9292
Optional: true,
9393
Default: false,
9494
},
95+
"secret": {
96+
Type: schema.TypeBool,
97+
Optional: true,
98+
Default: false,
99+
},
95100
},
96101
},
97102
},

checkly/resource_environment_variable.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func resourceEnvironmentVariable() *schema.Resource {
3333
Optional: true,
3434
Default: false,
3535
},
36+
"secret": {
37+
Type: schema.TypeBool,
38+
Optional: true,
39+
Default: false,
40+
},
3641
},
3742
}
3843
}
@@ -57,13 +62,17 @@ func environmentVariableFromResourceData(d *schema.ResourceData) (checkly.Enviro
5762
Key: d.Get("key").(string),
5863
Value: d.Get("value").(string),
5964
Locked: d.Get("locked").(bool),
65+
Secret: d.Get("secret").(bool),
6066
}, nil
6167
}
6268

6369
func resourceDataFromEnvironmentVariable(s *checkly.EnvironmentVariable, d *schema.ResourceData) error {
6470
d.Set("key", s.Key)
65-
d.Set("value", s.Value)
71+
if !s.Secret {
72+
d.Set("value", s.Value)
73+
}
6674
d.Set("locked", s.Locked)
75+
d.Set("secret", s.Secret)
6776
return nil
6877
}
6978

checkly/resource_environment_variable_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ func TestAccEnvVarSuccess(t *testing.T) {
4444
},
4545
})
4646
}
47+
48+
func TestAccSecretEnvVarSuccess(t *testing.T) {
49+
accTestCase(t, []resource.TestStep{
50+
{
51+
Config: `resource "checkly_environment_variable" "test" {
52+
key = "SECRET"
53+
value = "https://api.checklyhq.com"
54+
secret = true
55+
}`,
56+
},
57+
})
58+
}

docs/resources/check.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ resource "checkly_check" "example_check" {
200200
- `alert_settings` (Block List, Max: 1) (see [below for nested schema](#nestedblock--alert_settings))
201201
- `degraded_response_time` (Number) The response time in milliseconds starting from which a check should be considered degraded. Possible values are between 0 and 30000. (Default `15000`).
202202
- `double_check` (Boolean, Deprecated) Setting this to `true` will trigger a retry when a check fails from the failing region and another, randomly selected region before marking the check as failed.
203-
- `environment_variable` (Block List) Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden. These are only relevant for browser checks. Use global environment variables whenever possible. (see [below for nested schema](#nestedblock--environment_variable))
203+
- `environment_variable` (Block List) Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden, add secret = true to create a secret variable. These are only relevant for browser checks. Use global environment variables whenever possible. (see [below for nested schema](#nestedblock--environment_variable))
204204
- `environment_variables` (Map of String, Deprecated) Key/value pairs for setting environment variables during check execution. These are only relevant for browser checks. Use global environment variables whenever possible.
205205
- `frequency_offset` (Number) This property only valid for API high frequency checks. To create a hight frequency check, the property `frequency` must be `0` and `frequency_offset` could be `10`, `20` or `30`.
206206
- `group_id` (Number) The id of the check group this check is part of.
@@ -304,6 +304,7 @@ Required:
304304
Optional:
305305

306306
- `locked` (Boolean)
307+
- `secret` (Boolean)
307308

308309

309310
<a id="nestedblock--request"></a>

docs/resources/check_group.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ resource "checkly_check_group" "test_group1" {
149149
- `alert_settings` (Block List, Max: 1) (see [below for nested schema](#nestedblock--alert_settings))
150150
- `api_check_defaults` (Block Set, Max: 1) (see [below for nested schema](#nestedblock--api_check_defaults))
151151
- `double_check` (Boolean, Deprecated) Setting this to `true` will trigger a retry when a check fails from the failing region and another, randomly selected region before marking the check as failed.
152-
- `environment_variable` (Block List) Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden. These are only relevant for browser checks. Use global environment variables whenever possible. (see [below for nested schema](#nestedblock--environment_variable))
152+
- `environment_variable` (Block List) Key/value pairs for setting environment variables during check execution, add locked = true to keep value hidden, add secret = true to create a secret variable. These are only relevant for browser checks. Use global environment variables whenever possible. (see [below for nested schema](#nestedblock--environment_variable))
153153
- `environment_variables` (Map of String, Deprecated) Key/value pairs for setting environment variables during check execution. These are only relevant for browser checks. Use global environment variables whenever possible.
154154
- `local_setup_script` (String) A valid piece of Node.js code to run in the setup phase of an API check in this group.
155155
- `local_teardown_script` (String) A valid piece of Node.js code to run in the teardown phase of an API check in this group.
@@ -282,6 +282,7 @@ Required:
282282
Optional:
283283

284284
- `locked` (Boolean)
285+
- `secret` (Boolean)
285286

286287

287288
<a id="nestedblock--retry_strategy"></a>

docs/resources/environment_variable.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ resource "checkly_environment_variable" "variable_2" {
3737
### Optional
3838

3939
- `locked` (Boolean)
40+
- `secret` (Boolean)
4041

4142
### Read-Only
4243

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22
44

55
require (
66
github.com/aws/aws-sdk-go v1.44.122 // indirect
7-
github.com/checkly/checkly-go-sdk v1.8.0
7+
github.com/checkly/checkly-go-sdk v1.8.1
88
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
99
github.com/google/go-cmp v0.6.0
1010
github.com/gruntwork-io/terratest v0.41.16

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTS
240240
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
241241
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
242242
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
243-
github.com/checkly/checkly-go-sdk v1.8.0 h1:8Bz0YYD1WiuL1tlBNGHOSv2n4kd6gVlrpzbYrgL5e+Q=
244-
github.com/checkly/checkly-go-sdk v1.8.0/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
243+
github.com/checkly/checkly-go-sdk v1.8.1 h1:s8TAlbruie1lxGVdkqwfimMBKnTrjso26yByJI1uoPI=
244+
github.com/checkly/checkly-go-sdk v1.8.1/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
245245
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
246246
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
247247
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=

0 commit comments

Comments
 (0)