Skip to content

Commit 795dd33

Browse files
authored
Revert "delete pdc fields from json_data when generating updated state (#2439)" (#2450)
This reverts commit ef52330.
1 parent cec7259 commit 795dd33

File tree

2 files changed

+4
-105
lines changed

2 files changed

+4
-105
lines changed

internal/resources/grafana/resource_data_source.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ import (
1919
"github.com/grafana/terraform-provider-grafana/v4/internal/common"
2020
)
2121

22-
const (
23-
pdcEnableSecureSocksProxy = "enableSecureSocksProxy"
24-
pdcSecureSocksProxyUsername = "secureSocksProxyUsername"
25-
)
26-
2722
func resourceDataSource() *common.Resource {
2823
schema := &schema.Resource{
2924

@@ -172,17 +167,6 @@ func datasourceJSONDataAttribute() *schema.Schema {
172167
errors.New("teamHttpHeaders is a reserved key and cannot be used in JSON data. Use the data_source_config_lbac_rules resource instead"),
173168
}
174169
}
175-
176-
if strings.Contains(i.(string), pdcEnableSecureSocksProxy) {
177-
return nil, []error{
178-
errors.New(pdcEnableSecureSocksProxy + " is a reserved key and cannot be used in JSON data"),
179-
}
180-
}
181-
if strings.Contains(i.(string), pdcSecureSocksProxyUsername) {
182-
return nil, []error{
183-
errors.New(pdcSecureSocksProxyUsername + " is a reserved key and cannot be used in JSON data"),
184-
}
185-
}
186170
return validation.StringIsJSON(i, s)
187171
},
188172
StateFunc: func(v any) string {
@@ -198,8 +182,8 @@ func datasourceJSONDataAttribute() *schema.Schema {
198182
json.Unmarshal([]byte(newValue), &newValueUnmarshalled)
199183
pdcNetworkID := d.Get("private_data_source_connect_network_id")
200184
if pdcNetworkID != "" {
201-
newValueUnmarshalled[pdcEnableSecureSocksProxy] = true
202-
newValueUnmarshalled[pdcSecureSocksProxyUsername] = pdcNetworkID
185+
newValueUnmarshalled["enableSecureSocksProxy"] = true
186+
newValueUnmarshalled["secureSocksProxyUsername"] = pdcNetworkID
203187
}
204188
newValue, _ = structure.FlattenJsonToString(newValueUnmarshalled)
205189

@@ -349,14 +333,6 @@ func datasourceToState(d *schema.ResourceData, dataSource *models.DataSource) di
349333

350334
func datasourceConfigToState(d *schema.ResourceData, dataSource *models.DataSource) diag.Diagnostics {
351335
gottenJSONData, gottenHeaders := removeHeadersFromJSONData(dataSource.JSONData.(map[string]any))
352-
353-
// These PDC fields are added by the provider, so we should remove them from
354-
// the state so that the state matches the user config. The consequence of
355-
// having a diff here is suppressed in the DiffSuppressFunc, but there is
356-
// a risk that the encoding of the map provides an inconsistent result.
357-
delete(gottenJSONData, pdcEnableSecureSocksProxy)
358-
delete(gottenJSONData, pdcSecureSocksProxyUsername)
359-
360336
encodedJSONData, err := json.Marshal(gottenJSONData)
361337
if err != nil {
362338
return diag.Errorf("Failed to marshal JSON data: %s", err)
@@ -414,8 +390,8 @@ func stateToDatasourceConfig(d *schema.ResourceData) (map[string]any, map[string
414390
pdcNetworkID := d.Get("private_data_source_connect_network_id")
415391
if pdcNetworkID != nil {
416392
if id := pdcNetworkID.(string); id != "" {
417-
jd[pdcEnableSecureSocksProxy] = true
418-
jd[pdcSecureSocksProxyUsername] = pdcNetworkID
393+
jd["enableSecureSocksProxy"] = true
394+
jd["secureSocksProxyUsername"] = pdcNetworkID
419395
}
420396
}
421397

internal/resources/grafana/resource_data_source_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -341,83 +341,6 @@ func TestAccDataSource_ValidateHttpHeaders(t *testing.T) {
341341
})
342342
}
343343

344-
func TestAccDataSource_PDCReservedProperties(t *testing.T) {
345-
testutils.CheckOSSTestsEnabled(t)
346-
347-
t.Run("enableSecureSocksProxy", func(t *testing.T) {
348-
resource.ParallelTest(t, resource.TestCase{
349-
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
350-
Steps: []resource.TestStep{
351-
{
352-
Config: `
353-
resource "grafana_data_source" "influx" {
354-
type = "influxdb"
355-
name = "anything"
356-
url = "http://acc-test.invalid/"
357-
json_data_encoded = jsonencode({
358-
enableSecureSocksProxy = true
359-
})
360-
}`,
361-
ExpectError: regexp.MustCompile(`enableSecureSocksProxy is a reserved key and cannot be used in JSON data`),
362-
},
363-
},
364-
})
365-
})
366-
367-
t.Run("secureSocksProxyUsername", func(t *testing.T) {
368-
resource.ParallelTest(t, resource.TestCase{
369-
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
370-
Steps: []resource.TestStep{
371-
{
372-
Config: `
373-
resource "grafana_data_source" "influx" {
374-
type = "influxdb"
375-
name = "anything"
376-
url = "http://acc-test.invalid/"
377-
json_data_encoded = jsonencode({
378-
secureSocksProxyUsername = "pdc-network-id"
379-
})
380-
}`,
381-
ExpectError: regexp.MustCompile(`secureSocksProxyUsername is a reserved key and cannot be used in JSON data`),
382-
},
383-
},
384-
})
385-
})
386-
}
387-
388-
func TestAccDatasource_PDCPropertiesRemovedFromState(t *testing.T) {
389-
testutils.CheckOSSTestsEnabled(t)
390-
391-
var dataSource models.DataSource
392-
var org models.OrgDetailsDTO
393-
394-
resource.ParallelTest(t, resource.TestCase{
395-
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
396-
CheckDestroy: datasourceCheckExists.destroyed(&dataSource, &org),
397-
Steps: []resource.TestStep{
398-
{
399-
Config: `
400-
resource "grafana_data_source" "pdc" {
401-
type = "influxdb"
402-
name = "pdc"
403-
url = "http://acc-test.invalid/"
404-
json_data_encoded = jsonencode({
405-
organization = "organization"
406-
tlsAuth = false
407-
})
408-
private_data_source_connect_network_id = "pdc-network-id"
409-
}`,
410-
Check: resource.ComposeTestCheckFunc(
411-
// Check that the datasource is in the correct organization
412-
datasourceCheckExists.exists("grafana_data_source.pdc", &dataSource),
413-
// Check that the PDC-related fields are not in the state json data
414-
resource.TestCheckResourceAttr("grafana_data_source.pdc", "json_data_encoded", "{\"organization\":\"organization\",\"tlsAuth\":false}"),
415-
),
416-
},
417-
},
418-
})
419-
}
420-
421344
func TestAccDataSource_SeparateConfig(t *testing.T) {
422345
testutils.CheckOSSTestsEnabled(t, ">=v9.0.0")
423346

0 commit comments

Comments
 (0)