Skip to content

Commit

Permalink
Add support for show_as_button and is_signup_enabled (#974)
Browse files Browse the repository at this point in the history
* Add support for show_as_button and is_signup_enabled

* clean up expansion of OrganizationConnections

* Resolve PR comments to improve tests and clean up the connection mapping

* Add test recordings
  • Loading branch information
acwest authored Jun 18, 2024
1 parent 5b2e3ed commit a57c0ca
Show file tree
Hide file tree
Showing 15 changed files with 14,637 additions and 2,799 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ override.tf.json
!.vscode/tasks.json
*.code-workspace
.idea
.*.sw?

# Environment
.env
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ Read-Only:

- `assign_membership_on_login` (Boolean)
- `connection_id` (String)
- `is_signup_enabled` (Boolean)
- `show_as_button` (Boolean)


6 changes: 5 additions & 1 deletion docs/resources/organization_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ resource "auth0_organization_connection" "my_org_conn" {
organization_id = auth0_organization.my_organization.id
connection_id = auth0_connection.my_connection.id
assign_membership_on_login = true
is_signup_enabled = false
show_as_button = true
}
```

Expand All @@ -43,7 +45,9 @@ resource "auth0_organization_connection" "my_org_conn" {

### Optional

- `assign_membership_on_login` (Boolean) When true, all users that log in with this connection will be automatically granted membership in the organization. When false, users must be granted membership in the organization before logging in with this connection.
- `assign_membership_on_login` (Boolean) When `true`, all users that log in with this connection will be automatically granted membership in the organization. When `false`, users must be granted membership in the organization before logging in with this connection.
- `is_signup_enabled` (Boolean) Determines whether organization sign-up should be enabled for this organization connection. Only applicable for database connections. Note: `is_signup_enabled` can only be `true` if `assign_membership_on_login` is `true`.
- `show_as_button` (Boolean) Determines whether a connection should be displayed on this organization’s login prompt. Only applicable for enterprise connections.

### Read-Only

Expand Down
8 changes: 7 additions & 1 deletion docs/resources/organization_connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ resource "auth0_organization_connections" "one-to-many" {
enabled_connections {
connection_id = auth0_connection.my_connection-1.id
assign_membership_on_login = true
is_signup_enabled = false
show_as_button = true
}
enabled_connections {
connection_id = auth0_connection.my_connection-2.id
assign_membership_on_login = true
is_signup_enabled = false
show_as_button = true
}
}
```
Expand All @@ -67,7 +71,9 @@ Required:

Optional:

- `assign_membership_on_login` (Boolean) When true, all users that log in with this connection will be automatically granted membership in the organization. When false, users must be granted membership in the organization before logging in with this connection.
- `assign_membership_on_login` (Boolean) When `true`, all users that log in with this connection will be automatically granted membership in the organization. When `false`, users must be granted membership in the organization before logging in with this connection.
- `is_signup_enabled` (Boolean) Determines whether organization sign-up should be enabled for this organization connection. Only applicable for database connections. Note: `is_signup_enabled` can only be `true` if `assign_membership_on_login` is `true`.
- `show_as_button` (Boolean) Determines whether a connection should be displayed on this organization’s login prompt. Only applicable for enterprise connections.

## Import

Expand Down
2 changes: 2 additions & 0 deletions examples/resources/auth0_organization_connection/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ resource "auth0_organization_connection" "my_org_conn" {
organization_id = auth0_organization.my_organization.id
connection_id = auth0_connection.my_connection.id
assign_membership_on_login = true
is_signup_enabled = false
show_as_button = true
}
4 changes: 4 additions & 0 deletions examples/resources/auth0_organization_connections/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ resource "auth0_organization_connections" "one-to-many" {
enabled_connections {
connection_id = auth0_connection.my_connection-1.id
assign_membership_on_login = true
is_signup_enabled = false
show_as_button = true
}

enabled_connections {
connection_id = auth0_connection.my_connection-2.id
assign_membership_on_login = true
is_signup_enabled = false
show_as_button = true
}
}
13 changes: 13 additions & 0 deletions internal/auth0/organization/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ func dataSourceSchema() map[string]*schema.Schema {
"automatically granted membership in the organization. When `false`, users must be " +
"granted membership in the organization before logging in with this connection.",
},
"is_signup_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Determines whether organization sign-up should be enabled for this " +
"organization connection. Only applicable for database connections. " +
"Note: `is_signup_enabled` can only be `true` if `assign_membership_on_login` is `true`.",
},
"show_as_button": {
Type: schema.TypeBool,
Computed: true,
Description: "Determines whether a connection should be displayed on this organization’s " +
"login prompt. Only applicable for enterprise connections.",
},
},
},
}
Expand Down
14 changes: 10 additions & 4 deletions internal/auth0/organization/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ func expandOrganizationBranding(brandingList cty.Value) *management.Organization
return organizationBranding
}

func expandOrganizationConnection(connectionCfg cty.Value) *management.OrganizationConnection {
return &management.OrganizationConnection{
ConnectionID: value.String(connectionCfg.GetAttr("connection_id")),
AssignMembershipOnLogin: value.Bool(connectionCfg.GetAttr("assign_membership_on_login")),
IsSignupEnabled: value.Bool(connectionCfg.GetAttr("is_signup_enabled")),
ShowAsButton: value.Bool(connectionCfg.GetAttr("show_as_button")),
}
}

func expandOrganizationConnections(cfg cty.Value) []*management.OrganizationConnection {
connections := make([]*management.OrganizationConnection, 0)

cfg.ForEachElement(func(_ cty.Value, connectionCfg cty.Value) (stop bool) {
connections = append(connections, &management.OrganizationConnection{
ConnectionID: value.String(connectionCfg.GetAttr("connection_id")),
AssignMembershipOnLogin: value.Bool(connectionCfg.GetAttr("assign_membership_on_login")),
})
connections = append(connections, expandOrganizationConnection(connectionCfg))

return stop
})
Expand Down
4 changes: 4 additions & 0 deletions internal/auth0/organization/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func flattenOrganizationBranding(organizationBranding *management.OrganizationBr
func flattenOrganizationConnection(data *schema.ResourceData, orgConn *management.OrganizationConnection) error {
result := multierror.Append(
data.Set("assign_membership_on_login", orgConn.GetAssignMembershipOnLogin()),
data.Set("is_signup_enabled", orgConn.GetIsSignupEnabled()),
data.Set("show_as_button", orgConn.GetShowAsButton()),
data.Set("name", orgConn.GetConnection().GetName()),
data.Set("strategy", orgConn.GetConnection().GetStrategy()),
)
Expand All @@ -74,6 +76,8 @@ func flattenOrganizationEnabledConnections(connections []*management.Organizatio
result[index] = map[string]interface{}{
"connection_id": connection.GetConnectionID(),
"assign_membership_on_login": connection.GetAssignMembershipOnLogin(),
"is_signup_enabled": connection.GetIsSignupEnabled(),
"show_as_button": connection.GetShowAsButton(),
}
}

Expand Down
44 changes: 24 additions & 20 deletions internal/auth0/organization/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package organization
import (
"context"

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand Down Expand Up @@ -38,9 +37,24 @@ func NewConnectionResource() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "When true, all users that log in with this connection will be automatically granted " +
"membership in the organization. When false, users must be granted membership in the organization" +
" before logging in with this connection.",
Description: "When `true`, all users that log in with this connection will be automatically granted " +
"membership in the organization. When `false`, users must be granted membership in the organization " +
"before logging in with this connection.",
},
"is_signup_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Determines whether organization sign-up should be enabled for this " +
"organization connection. Only applicable for database connections. " +
"Note: `is_signup_enabled` can only be `true` if `assign_membership_on_login` is `true`.",
},
"show_as_button": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Determines whether a connection should be displayed on this organization’s " +
"login prompt. Only applicable for enterprise connections.",
},
"name": {
Type: schema.TypeString,
Expand All @@ -58,22 +72,14 @@ func NewConnectionResource() *schema.Resource {

func createOrganizationConnection(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

organizationID := data.Get("organization_id").(string)

connectionID := data.Get("connection_id").(string)
assignMembershipOnLogin := data.Get("assign_membership_on_login").(bool)

organizationConnection := &management.OrganizationConnection{
ConnectionID: &connectionID,
AssignMembershipOnLogin: &assignMembershipOnLogin,
}
organizationConnection := expandOrganizationConnection(data.GetRawConfig())

if err := api.Organization.AddConnection(ctx, organizationID, organizationConnection); err != nil {
return diag.FromErr(err)
}

internalSchema.SetResourceGroupID(data, organizationID, connectionID)
internalSchema.SetResourceGroupID(data, organizationID, organizationConnection.GetConnectionID())

return readOrganizationConnection(ctx, data, meta)
}
Expand All @@ -96,13 +102,11 @@ func updateOrganizationConnection(ctx context.Context, data *schema.ResourceData
api := meta.(*config.Config).GetAPI()

organizationID := data.Get("organization_id").(string)
organizationConnection := expandOrganizationConnection(data.GetRawConfig())
connectionID := organizationConnection.GetConnectionID()

connectionID := data.Get("connection_id").(string)
assignMembershipOnLogin := data.Get("assign_membership_on_login").(bool)

organizationConnection := &management.OrganizationConnection{
AssignMembershipOnLogin: &assignMembershipOnLogin,
}
// UpdateConnection doesn't like this to be set.
organizationConnection.ConnectionID = nil

if err := api.Organization.UpdateConnection(ctx, organizationID, connectionID, organizationConnection); err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
Expand Down
Loading

0 comments on commit a57c0ca

Please sign in to comment.