@@ -19,6 +19,11 @@ import (
1919 "github.com/grafana/terraform-provider-grafana/v4/internal/common"
2020)
2121
22+ const (
23+ pdcEnableSecureSocksProxy = "enableSecureSocksProxy"
24+ pdcSecureSocksProxyUsername = "secureSocksProxyUsername"
25+ )
26+
2227func resourceDataSource () * common.Resource {
2328 schema := & schema.Resource {
2429
@@ -167,6 +172,17 @@ func datasourceJSONDataAttribute() *schema.Schema {
167172 errors .New ("teamHttpHeaders is a reserved key and cannot be used in JSON data. Use the data_source_config_lbac_rules resource instead" ),
168173 }
169174 }
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+ }
170186 return validation .StringIsJSON (i , s )
171187 },
172188 StateFunc : func (v any ) string {
@@ -182,8 +198,8 @@ func datasourceJSONDataAttribute() *schema.Schema {
182198 json .Unmarshal ([]byte (newValue ), & newValueUnmarshalled )
183199 pdcNetworkID := d .Get ("private_data_source_connect_network_id" )
184200 if pdcNetworkID != "" {
185- newValueUnmarshalled ["enableSecureSocksProxy" ] = true
186- newValueUnmarshalled ["secureSocksProxyUsername" ] = pdcNetworkID
201+ newValueUnmarshalled [pdcEnableSecureSocksProxy ] = true
202+ newValueUnmarshalled [pdcSecureSocksProxyUsername ] = pdcNetworkID
187203 }
188204 newValue , _ = structure .FlattenJsonToString (newValueUnmarshalled )
189205
@@ -333,6 +349,14 @@ func datasourceToState(d *schema.ResourceData, dataSource *models.DataSource) di
333349
334350func datasourceConfigToState (d * schema.ResourceData , dataSource * models.DataSource ) diag.Diagnostics {
335351 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+
336360 encodedJSONData , err := json .Marshal (gottenJSONData )
337361 if err != nil {
338362 return diag .Errorf ("Failed to marshal JSON data: %s" , err )
@@ -390,8 +414,8 @@ func stateToDatasourceConfig(d *schema.ResourceData) (map[string]any, map[string
390414 pdcNetworkID := d .Get ("private_data_source_connect_network_id" )
391415 if pdcNetworkID != nil {
392416 if id := pdcNetworkID .(string ); id != "" {
393- jd ["enableSecureSocksProxy" ] = true
394- jd ["secureSocksProxyUsername" ] = pdcNetworkID
417+ jd [pdcEnableSecureSocksProxy ] = true
418+ jd [pdcSecureSocksProxyUsername ] = pdcNetworkID
395419 }
396420 }
397421
0 commit comments