Skip to content

Commit

Permalink
Use configured client_secret in state to properly handle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBak committed Nov 4, 2024
1 parent 86cd874 commit 115332a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/4500.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_zero_trust_access_identity_provider: Fix `client_secret` attribute always causing update, even when not changed
```
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func resourceCloudflareAccessIdentityProviderRead(ctx context.Context, d *schema
d.Set("name", accessIdentityProvider.Name)
d.Set("type", accessIdentityProvider.Type)

config := convertAccessIDPConfigStructToSchema(accessIdentityProvider.Config)
config := convertAccessIDPConfigStructToSchema(d.Get("config.0.client_secret").(string), accessIdentityProvider.Config)
if configErr := d.Set("config", config); configErr != nil {
return diag.FromErr(fmt.Errorf("error setting Access Identity Provider configuration: %w", configErr))
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func convertScimConfigSchemaToStruct(d *schema.ResourceData) cloudflare.AccessId
return ScimConfig
}

func convertAccessIDPConfigStructToSchema(options cloudflare.AccessIdentityProviderConfiguration) []interface{} {
func convertAccessIDPConfigStructToSchema(clientSecret string, options cloudflare.AccessIdentityProviderConfiguration) []interface{} {
attributes := make([]string, 0)
for _, value := range options.Attributes {
attributes = append(attributes, value)
Expand All @@ -301,7 +301,7 @@ func convertAccessIDPConfigStructToSchema(options cloudflare.AccessIdentityProvi
"centrify_app_id": options.CentrifyAppID,
"certs_url": options.CertsURL,
"client_id": options.ClientID,
"client_secret": options.ClientSecret,
"client_secret": clientSecret,
"claims": options.Claims,
"scopes": options.Scopes,
"directory_id": options.DirectoryID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ func resourceCloudflareAccessIdentityProviderSchema() map[string]*schema.Schema
"client_secret": {
Type: schema.TypeString,
Optional: true,
// client_secret is a write only operation from the Cloudflare API
// and once it's set, it is no longer accessible. To avoid storing
// it and messing up the state, hardcode in the concealed version.
StateFunc: func(val interface{}) string {
return CONCEALED_STRING
},
Sensitive: true,
},
"claims": {
Type: schema.TypeList,
Expand Down

0 comments on commit 115332a

Please sign in to comment.