Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
improve handling of nil values from terraform by checking for HasChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkappa committed Sep 17, 2018
1 parent a3fe2dd commit 317c001
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func newClient() *schema.Resource {
"token_endpoint_auth_method": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"none",
"client_secret_post",
Expand Down
40 changes: 25 additions & 15 deletions auth0/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
)

func String(d *schema.ResourceData, key string) (s *string) {
v, ok := d.GetOkExists(key)
if ok {
s = auth0.String(v.(string))
if d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
s = auth0.String(v.(string))
}
}
return
}
Expand All @@ -22,9 +24,11 @@ func MapString(m map[string]interface{}, key string) (s *string) {
}

func Int(d *schema.ResourceData, key string) (i *int) {
v, ok := d.GetOkExists(key)
if ok {
i = auth0.Int(v.(int))
if d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
i = auth0.Int(v.(int))
}
}
return
}
Expand All @@ -38,9 +42,11 @@ func MapInt(m map[string]interface{}, key string) (i *int) {
}

func Bool(d *schema.ResourceData, key string) (b *bool) {
v, ok := d.GetOkExists(key)
if ok {
b = auth0.Bool(v.(bool))
if d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
b = auth0.Bool(v.(bool))
}
}
return
}
Expand All @@ -54,17 +60,21 @@ func MapBool(m map[string]interface{}, key string) (b *bool) {
}

func Slice(d *schema.ResourceData, key string) (s []interface{}) {
v, ok := d.GetOkExists(key)
if ok {
s = v.([]interface{})
if d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
s = v.([]interface{})
}
}
return
}

func Map(d *schema.ResourceData, key string) (m map[string]interface{}) {
v, ok := d.GetOkExists(key)
if ok {
m = v.(map[string]interface{})
if d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
m = v.(map[string]interface{})
}
}
return
}
2 changes: 1 addition & 1 deletion example/client/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "auth0_client" "my_app_client" {
description = "Example Application Loooooong Description"
app_type = "non_interactive"
is_first_party = true
oidc_conformant = true
oidc_conformant = false
callbacks = ["https://example.com/callback"]
allowed_origins = ["https://example.com"]
web_origins = ["https://example.com"]
Expand Down

0 comments on commit 317c001

Please sign in to comment.