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

Make IsNewResource and HasChange optional #194

Merged
merged 7 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion auth0/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/meta"

"gopkg.in/auth0.v4"
"gopkg.in/auth0.v4/management"
)

Expand Down Expand Up @@ -68,7 +69,8 @@ func Configure(data *schema.ResourceData) (interface{}, error) {
secret := data.Get("client_secret").(string)
debug := data.Get("debug").(bool)

userAgent := fmt.Sprintf("Go-Auth0-SDK/v3; Terraform/%s",
userAgent := fmt.Sprintf("Go-Auth0-SDK/%s; Terraform-SDK/%s",
auth0.VersionMajor(),
meta.SDKVersionString())

return management.New(domain, id, secret,
Expand Down
6 changes: 3 additions & 3 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func buildClient(d *schema.ResourceData) *management.Client {
c := &management.Client{
Name: String(d, "name"),
Description: String(d, "description"),
AppType: String(d, "app_type"),
AppType: String(d, "app_type", IsNewResource(), HasChange()),
LogoURI: String(d, "logo_uri"),
IsFirstParty: Bool(d, "is_first_party"),
IsTokenEndpointIPHeaderTrusted: Bool(d, "is_token_endpoint_ip_header_trusted"),
Expand All @@ -579,12 +579,12 @@ func buildClient(d *schema.ResourceData) *management.Client {
SSO: Bool(d, "sso"),
SSODisabled: Bool(d, "sso_disabled"),
CrossOriginAuth: Bool(d, "cross_origin_auth"),
CrossOriginLocation: String(d, "cross_origin_loc"),
CrossOriginLocation: String(d, "cross_origin_loc", IsNewResource(), HasChange()),
CustomLoginPageOn: Bool(d, "custom_login_page_on"),
CustomLoginPage: String(d, "custom_login_page"),
CustomLoginPagePreview: String(d, "custom_login_page_preview"),
FormTemplate: String(d, "form_template"),
TokenEndpointAuthMethod: String(d, "token_endpoint_auth_method"),
TokenEndpointAuthMethod: String(d, "token_endpoint_auth_method", IsNewResource(), HasChange()),
InitiateLoginURI: String(d, "initiate_login_uri"),
}

Expand Down
4 changes: 2 additions & 2 deletions auth0/resource_auth0_resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ func expandResourceServer(d *schema.ResourceData) *management.ResourceServer {
Name: String(d, "name"),
Identifier: String(d, "identifier"),
SigningAlgorithm: String(d, "signing_alg"),
SigningSecret: String(d, "signing_secret"),
SigningSecret: String(d, "signing_secret", IsNewResource(), HasChange()),
AllowOfflineAccess: Bool(d, "allow_offline_access"),
TokenLifetime: Int(d, "token_lifetime"),
TokenLifetimeForWeb: Int(d, "token_lifetime_for_web"),
VerificationLocation: String(d, "verification_location"),
Options: Map(d, "options"),
EnforcePolicies: Bool(d, "enforce_policies"),
TokenDialect: String(d, "token_dialect"),
TokenDialect: String(d, "token_dialect", IsNewResource(), HasChange()),

SkipConsentForVerifiableFirstPartyClients: Bool(d, "skip_consent_for_verifiable_first_party_clients"),
}
Expand Down
11 changes: 9 additions & 2 deletions auth0/resource_auth0_resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,25 @@ func TestAccResourceServer(t *testing.T) {
random.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "name", "Acceptance Test - {{.random}}", rand),
random.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "identifier", "https://uat.api.alexkappa.com/{{.random}}", rand),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "signing_alg", "RS256"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.#", "2"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "allow_offline_access", "true"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "token_lifetime", "7200"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "token_lifetime_for_web", "3600"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "skip_consent_for_verifiable_first_party_clients", "true"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "enforce_policies", "true"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.#", "2"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.1906583762.value", "create:foo"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.1906583762.description", "Create foos"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.3536702635.value", "create:bar"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.3536702635.description", "Create bars"),
),
},
{
Config: random.Template(testAccResourceServerConfigUpdate, rand),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "allow_offline_access", "false"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.#", "2"),
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.1448666690.value", "create:bar"), // set id changes
resource.TestCheckResourceAttr("auth0_resource_server.my_resource_server", "scopes.1448666690.description", "Create bars for bar reasons"),
),
},
},
Expand Down Expand Up @@ -112,7 +119,7 @@ resource "auth0_resource_server" "my_resource_server" {
}
scopes {
value = "create:bar"
description = "Create bars"
description = "Create bars for bar reasons"
}
allow_offline_access = false # <--- set to false
token_lifetime = 7200
Expand Down
6 changes: 3 additions & 3 deletions auth0/resource_auth0_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func readRole(d *schema.ResourceData, m interface{}) error {
d.Set("name", c.Name)
d.Set("description", c.Description)

permissions, err := api.Role.Permissions(d.Id())
l, err := api.Role.Permissions(d.Id())
if err != nil {
return err
}
d.Set("permissions", func() (m []map[string]interface{}) {
for _, permission := range permissions {
for _, permission := range l.Permissions {
m = append(m, map[string]interface{}{
"name": permission.Name,
"resource_server_identifier": permission.ResourceServerIdentifier,
Expand Down Expand Up @@ -152,7 +152,7 @@ func deleteRole(d *schema.ResourceData, m interface{}) error {

func buildRole(d *schema.ResourceData) *management.Role {
return &management.Role{
ID: String(d, "role_id"),
ID: String(d, "role_id", IsNewResource(), HasChange()),
Name: String(d, "name"),
Description: String(d, "description"),
}
Expand Down
36 changes: 33 additions & 3 deletions auth0/resource_auth0_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func newTenant() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand All @@ -45,6 +46,7 @@ func newTenant() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand All @@ -61,14 +63,17 @@ func newTenant() *schema.Resource {
"default_audience": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"default_directory": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"error_page": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -90,98 +95,120 @@ func newTenant() *schema.Resource {
"friendly_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"picture_url": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"support_email": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"support_url": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"allowed_logout_urls": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Computed: true,
},
"session_lifetime": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"sandbox_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"idle_session_lifetime": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntAtLeast(1),
},
"enabled_locales": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Computed: true,
},
"flags": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"change_pwd_flow_v1": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_client_connections": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_apis_section": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_pipeline2": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_dynamic_client_registration": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_custom_domain_in_emails": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"universal_login": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_legacy_logs_search_v2": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"disable_clickjack_protection_headers": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"enable_public_signup_user_exists_error": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"use_scope_descriptions_for_consent": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
},
"universal_login": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -194,10 +221,12 @@ func newTenant() *schema.Resource {
"primary": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"page_background": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
Expand All @@ -208,6 +237,7 @@ func newTenant() *schema.Resource {
"default_redirection_uri": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.All(
v.IsURLWithNoFragment,
validation.IsURLWithScheme([]string{"https"}),
Expand Down Expand Up @@ -287,7 +317,7 @@ func buildTenant(d *schema.ResourceData) *management.Tenant {
AllowedLogoutURLs: Slice(d, "allowed_logout_urls"),
SessionLifetime: Int(d, "session_lifetime"),
SandboxVersion: String(d, "sandbox_version"),
IdleSessionLifetime: Int(d, "idle_session_lifetime"),
IdleSessionLifetime: Int(d, "idle_session_lifetime", IsNewResource(), HasChange()),
EnabledLocales: Set(d, "enabled_locales").List(),
ChangePassword: expandTenantChangePassword(d),
GuardianMFAPage: expandTenantGuardianMFAPage(d),
Expand Down
4 changes: 1 addition & 3 deletions auth0/resource_auth0_tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-auth0/auth0/internal/debug"
)

func TestAccTenant(t *testing.T) {
Expand Down Expand Up @@ -45,7 +44,6 @@ func TestAccTenant(t *testing.T) {
resource.TestCheckResourceAttr("auth0_tenant.my_tenant", "universal_login.0.colors.0.primary", "#0059d6"),
resource.TestCheckResourceAttr("auth0_tenant.my_tenant", "universal_login.0.colors.0.page_background", "#000000"),
resource.TestCheckResourceAttr("auth0_tenant.my_tenant", "default_redirection_uri", "https://example.com/login"),
debug.DumpAttr("auth0_tenant.my_tenant"),
),
},
// This test case confirms issue #160 where boolean values from a
Expand Down Expand Up @@ -92,7 +90,7 @@ resource "auth0_tenant" "my_tenant" {
]
session_lifetime = 1080
sandbox_version = "8"
idle_session_lifetime = 720
// idle_session_lifetime = 720
enabled_locales = ["en", "de", "fr"]
flags {
universal_login = true
Expand Down
20 changes: 10 additions & 10 deletions auth0/resource_auth0_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ func readUser(d *schema.ResourceData, m interface{}) error {
}
d.Set("app_metadata", appMeta)

roles, err := api.User.Roles(d.Id())
l, err := api.User.Roles(d.Id())
if err != nil {
return err
}
d.Set("roles", func() (v []interface{}) {
for _, role := range roles {
for _, role := range l.Roles {
v = append(v, auth0.StringValue(role.ID))
}
return
Expand Down Expand Up @@ -224,19 +224,19 @@ func deleteUser(d *schema.ResourceData, m interface{}) error {
func buildUser(d *schema.ResourceData) (u *management.User, err error) {

u = new(management.User)
u.ID = String(d, "user_id")
u.ID = String(d, "user_id", IsNewResource())
u.Connection = String(d, "connection_name")
u.Username = String(d, "username")
u.Name = String(d, "name")
u.Username = String(d, "username", IsNewResource(), HasChange())
u.Name = String(d, "name", IsNewResource(), HasChange())
u.FamilyName = String(d, "family_name")
u.GivenName = String(d, "given_name")
u.Nickname = String(d, "nickname")
u.PhoneNumber = String(d, "phone_number")
u.EmailVerified = Bool(d, "email_verified")
u.PhoneNumber = String(d, "phone_number", IsNewResource(), HasChange())
u.EmailVerified = Bool(d, "email_verified", IsNewResource(), HasChange())
u.VerifyEmail = Bool(d, "verify_email")
u.PhoneVerified = Bool(d, "phone_verified")
u.Email = String(d, "email")
u.Password = String(d, "password")
u.PhoneVerified = Bool(d, "phone_verified", IsNewResource(), HasChange())
u.Email = String(d, "email", IsNewResource(), HasChange())
u.Password = String(d, "password", IsNewResource(), HasChange())
u.Blocked = Bool(d, "blocked")
u.Picture = String(d, "picture")

Expand Down
Loading