Skip to content

Commit

Permalink
feat: add secret variables support [sc-21027] (#300)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maxigimenez authored Sep 3, 2024
1 parent 899cab8 commit 4e8abd7
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 8 deletions.
9 changes: 8 additions & 1 deletion checkly/resource_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func resourceCheck() *schema.Resource {
"environment_variable": {
Type: schema.TypeList,
Optional: true,
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.",
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.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Expand All @@ -148,6 +148,11 @@ func resourceCheck() *schema.Resource {
Optional: true,
Default: false,
},
"secret": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down Expand Up @@ -968,10 +973,12 @@ func environmentVariablesFromSet(s []interface{}) []checkly.EnvironmentVariable
key := tm["key"].(string)
value := tm["value"].(string)
locked := tm["locked"].(bool)
secret := tm["secret"].(bool)
res = append(res, checkly.EnvironmentVariable{
Key: key,
Value: value,
Locked: locked,
Secret: secret,
})
}

Expand Down
7 changes: 6 additions & 1 deletion checkly/resource_check_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func resourceCheckGroup() *schema.Resource {
"environment_variable": {
Type: schema.TypeList,
Optional: true,
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.",
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.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Expand All @@ -92,6 +92,11 @@ func resourceCheckGroup() *schema.Resource {
Optional: true,
Default: false,
},
"secret": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down
11 changes: 10 additions & 1 deletion checkly/resource_environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func resourceEnvironmentVariable() *schema.Resource {
Optional: true,
Default: false,
},
"secret": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand All @@ -57,13 +62,17 @@ func environmentVariableFromResourceData(d *schema.ResourceData) (checkly.Enviro
Key: d.Get("key").(string),
Value: d.Get("value").(string),
Locked: d.Get("locked").(bool),
Secret: d.Get("secret").(bool),
}, nil
}

func resourceDataFromEnvironmentVariable(s *checkly.EnvironmentVariable, d *schema.ResourceData) error {
d.Set("key", s.Key)
d.Set("value", s.Value)
if !s.Secret {
d.Set("value", s.Value)
}
d.Set("locked", s.Locked)
d.Set("secret", s.Secret)
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions checkly/resource_environment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ func TestAccEnvVarSuccess(t *testing.T) {
},
})
}

func TestAccSecretEnvVarSuccess(t *testing.T) {
accTestCase(t, []resource.TestStep{
{
Config: `resource "checkly_environment_variable" "test" {
key = "SECRET"
value = "https://api.checklyhq.com"
secret = true
}`,
},
})
}
3 changes: 2 additions & 1 deletion docs/resources/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ resource "checkly_check" "example_check" {
- `alert_settings` (Block List, Max: 1) (see [below for nested schema](#nestedblock--alert_settings))
- `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`).
- `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.
- `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))
- `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))
- `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.
- `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`.
- `group_id` (Number) The id of the check group this check is part of.
Expand Down Expand Up @@ -304,6 +304,7 @@ Required:
Optional:

- `locked` (Boolean)
- `secret` (Boolean)


<a id="nestedblock--request"></a>
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/check_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ resource "checkly_check_group" "test_group1" {
- `alert_settings` (Block List, Max: 1) (see [below for nested schema](#nestedblock--alert_settings))
- `api_check_defaults` (Block Set, Max: 1) (see [below for nested schema](#nestedblock--api_check_defaults))
- `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.
- `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))
- `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))
- `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.
- `local_setup_script` (String) A valid piece of Node.js code to run in the setup phase of an API check in this group.
- `local_teardown_script` (String) A valid piece of Node.js code to run in the teardown phase of an API check in this group.
Expand Down Expand Up @@ -282,6 +282,7 @@ Required:
Optional:

- `locked` (Boolean)
- `secret` (Boolean)


<a id="nestedblock--retry_strategy"></a>
Expand Down
1 change: 1 addition & 0 deletions docs/resources/environment_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ resource "checkly_environment_variable" "variable_2" {
### Optional

- `locked` (Boolean)
- `secret` (Boolean)

### Read-Only

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/checkly/checkly-go-sdk v1.8.0
github.com/checkly/checkly-go-sdk v1.8.1
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.6.0
github.com/gruntwork-io/terratest v0.41.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTS
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/checkly/checkly-go-sdk v1.8.0 h1:8Bz0YYD1WiuL1tlBNGHOSv2n4kd6gVlrpzbYrgL5e+Q=
github.com/checkly/checkly-go-sdk v1.8.0/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
github.com/checkly/checkly-go-sdk v1.8.1 h1:s8TAlbruie1lxGVdkqwfimMBKnTrjso26yByJI1uoPI=
github.com/checkly/checkly-go-sdk v1.8.1/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down

0 comments on commit 4e8abd7

Please sign in to comment.