Skip to content

Commit

Permalink
Fix for Api validation/setup/request ordering (#28)
Browse files Browse the repository at this point in the history
* update api/http check validations/requests to use TypeList rather than TypeSet. Update docs.

* fix a docs line for clarity

* another fix from docs generation
  • Loading branch information
greatestusername authored Nov 9, 2023
1 parent e05590b commit c52056e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=github.com
NAMESPACE=splunk
NAME=synthetics
BINARY=terraform-provider-${NAME}
VERSION=2.0.1
VERSION=2.0.2

default: install

Expand Down
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: |-
terraform {
required_providers {
synthetics = {
version = "2.0.1"
version = "2.0.2"
source = "splunk/synthetics"
}
}
Expand All @@ -37,3 +37,5 @@ provider "synthetics" {
- `apikey` (String) Splunk Observability API Key. Will pull from `OBSERVABILITY_API_TOKEN` environment variable if available.
- `product` (String) One of: `observability` or `rigor`
- `realm` (String) Splunk Observability Realm (E.G. `us1`). Will pull from `REALM` environment variable if available. For Rigor use realm rigor


8 changes: 4 additions & 4 deletions docs/resources/create_api_check_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ Required:

Optional:

- `requests` (Block Set) (see [below for nested schema](#nestedblock--test--requests))
- `requests` (Block List) (see [below for nested schema](#nestedblock--test--requests))
- `scheduling_strategy` (String)

<a id="nestedblock--test--requests"></a>
### Nested Schema for `test.requests`

Optional:

- `configuration` (Block Set) (see [below for nested schema](#nestedblock--test--requests--configuration))
- `setup` (Block Set) (see [below for nested schema](#nestedblock--test--requests--setup))
- `validations` (Block Set) (see [below for nested schema](#nestedblock--test--requests--validations))
- `configuration` (Block List) (see [below for nested schema](#nestedblock--test--requests--configuration))
- `setup` (Block List) (see [below for nested schema](#nestedblock--test--requests--setup))
- `validations` (Block List) (see [below for nested schema](#nestedblock--test--requests--validations))

<a id="nestedblock--test--requests--configuration"></a>
### Nested Schema for `test.requests.configuration`
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/create_http_check_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Optional:
- `scheduling_strategy` (String)
- `type` (String)
- `user_agent` (String)
- `validations` (Block Set) (see [below for nested schema](#nestedblock--test--validations))
- `validations` (Block List) (see [below for nested schema](#nestedblock--test--validations))

Read-Only:

Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
synthetics = {
version = "2.0.1"
version = "2.0.2"
source = "splunk/synthetics"
}
}
Expand Down
8 changes: 4 additions & 4 deletions synthetics/resource_api_check_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func resourceApiCheckV2() *schema.Resource {
Required: true,
},
"requests": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"configuration": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -102,7 +102,7 @@ func resourceApiCheckV2() *schema.Resource {
},
},
"setup": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -138,7 +138,7 @@ func resourceApiCheckV2() *schema.Resource {
},
},
"validations": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion synthetics/resource_http_check_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func resourceHttpCheckV2() *schema.Resource {
},
},
"validations": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
33 changes: 16 additions & 17 deletions synthetics/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ func buildApiV2Data(d *schema.ResourceData) sc2.ApiCheckV2Input {
apiv2.Test.Frequency = api["frequency"].(int)
apiv2.Test.Locationids = buildLocationIdData(api["location_ids"].([]interface{}))
apiv2.Test.Name = api["name"].(string)
apiv2.Test.Requests = buildRequestsData(api["requests"].(*schema.Set))
apiv2.Test.Requests = buildRequestsData(api["requests"].(([]interface{})))
apiv2.Test.Schedulingstrategy = api["scheduling_strategy"].(string)
}
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ func buildHttpV2Data(d *schema.ResourceData) sc2.HttpCheckV2Input {
userAgentString := http["user_agent"].(string)
httpv2.Test.UserAgent = &userAgentString
httpv2.Test.HttpHeaders = buildHttpHeadersData(http["headers"].(*schema.Set))
httpv2.Test.Validations = buildValidationsData(http["validations"].(*schema.Set))
httpv2.Test.Validations = buildValidationsData(http["validations"].([]interface{}))
i++
}
}
Expand Down Expand Up @@ -1191,15 +1191,14 @@ func buildLocationIdData(d []interface{}) []string {
return locationsList
}

func buildRequestsData(requests *schema.Set) []sc2.Requests {
requestsList := make([]sc2.Requests, len(requests.List()))

for i, request := range requests.List() {
func buildRequestsData(requests []interface{}) []sc2.Requests {
requestsList := make([]sc2.Requests, len(requests))
for i, request := range requests {
request := request.(map[string]interface{})
req := sc2.Requests{
Configuration: buildConfigurationData(request["configuration"].(*schema.Set)),
Setup: buildSetupData(request["setup"].(*schema.Set)),
Validations: buildValidationsData(request["validations"].(*schema.Set)),
Configuration: buildConfigurationData(request["configuration"].([]interface{})),
Setup: buildSetupData(request["setup"].([]interface{})),
Validations: buildValidationsData(request["validations"].([]interface{})),
}
requestsList[i] = req

Expand Down Expand Up @@ -1262,10 +1261,10 @@ func buildStepV2Data(steps []interface{}) []sc2.StepsV2 {
return stepsList
}

func buildSetupData(setups *schema.Set) []sc2.Setup {
setupsList := make([]sc2.Setup, len(setups.List()))
func buildSetupData(setups []interface{}) []sc2.Setup {
setupsList := make([]sc2.Setup, len(setups))

for i, setup := range setups.List() {
for i, setup := range setups {
setup := setup.(map[string]interface{})
set := sc2.Setup{
Extractor: setup["extractor"].(string),
Expand All @@ -1282,10 +1281,10 @@ func buildSetupData(setups *schema.Set) []sc2.Setup {
return setupsList
}

func buildValidationsData(validations *schema.Set) []sc2.Validations {
validationsList := make([]sc2.Validations, len(validations.List()))
func buildValidationsData(validations []interface{}) []sc2.Validations {
validationsList := make([]sc2.Validations, len(validations))

for i, validation := range validations.List() {
for i, validation := range validations {
validation := validation.(map[string]interface{})
val := sc2.Validations{
Actual: validation["actual"].(string),
Expand All @@ -1306,10 +1305,10 @@ func buildValidationsData(validations *schema.Set) []sc2.Validations {
return validationsList
}

func buildConfigurationData(configuration *schema.Set) sc2.Configuration {
func buildConfigurationData(configuration []interface{}) sc2.Configuration {
var configurationData sc2.Configuration

config_list := configuration.List()
config_list := configuration
config_map := config_list[0].(map[string]interface{})

configurationData.Body = config_map["body"].(string)
Expand Down

0 comments on commit c52056e

Please sign in to comment.