Skip to content

Commit

Permalink
feat: set id for identity provider
Browse files Browse the repository at this point in the history
  • Loading branch information
MCBrandenburg committed Aug 31, 2021
1 parent ed6f2d7 commit a01a067
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/resources/idp_external_jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resource "fusionauth_idp_external_jwt" "jwt" {

## Argument Reference

* `idp_id` - (Optional) The ID to use for the new identity provider. If not specified a secure random UUID will be generated.
* `application_configuration` - (Optional) The configuration for each Application that the identity provider is enabled for.
- `application_id` - (Optional) ID of the Application to apply this configuration to.
- `create_registration` - (Optional) Determines if a UserRegistration is created for the User automatically or not. If a user doesn’t exist in FusionAuth and logs in through an identity provider, this boolean controls whether or not FusionAuth creates a registration for the User in the Application they are logging into.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/idp_open_id_connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ resource "fusionauth_idp_open_id_connect" "OpenID" {

## Argument Reference

* `idp_id` - (Optional) The ID to use for the new identity provider. If not specified a secure random UUID will be generated.
* `application_configuration` - (Optional) The configuration for each Application that the identity provider is enabled for.
- `application_id` - (Optional) ID of the Application to apply this configuration to.
- `button_image_url` - (Optional) This is an optional Application specific override for the top level button image URL.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/idp_saml_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "fusionauth_idp_saml_v2" "Saml" {

## Argument Reference

* `idp_id` - (Optional) The ID to use for the new identity provider. If not specified a secure random UUID will be generated.
* `application_configuration` - (Optional) The configuration for each Application that the identity provider is enabled for.
- `application_id` - (Optional) ID of the Application to apply this configuration to.
- `button_image_url` - (Optional) This is an optional Application specific override for the top level button image URL.
Expand Down
11 changes: 9 additions & 2 deletions fusionauth/idphelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ func readIdentityProvider(id string, client Client) ([]byte, error) {
return b, nil
}

func createIdentityProvider(b []byte, client Client) ([]byte, error) {
func createIdentityProvider(b []byte, client Client, idpID string) ([]byte, error) {
var u string
if idpID != "" {
u = fmt.Sprintf("%s/%s/%s", strings.TrimRight(client.Host, "/"), "api/identity-provider", idpID)
} else {
u = fmt.Sprintf("%s/%s", strings.TrimRight(client.Host, "/"), "api/identity-provider")
}

req, err := http.NewRequest(
http.MethodPost,
fmt.Sprintf("%s/%s", strings.TrimRight(client.Host, "/"), "api/identity-provider"),
u,
bytes.NewBuffer(b),
)

Expand Down
2 changes: 1 addition & 1 deletion fusionauth/resource_fusionauth_idp_apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func createIDPApple(data *schema.ResourceData, i interface{}) error {

client := i.(Client)

bb, err := createIdentityProvider(b, client)
bb, err := createIdentityProvider(b, client, "")
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion fusionauth/resource_fusionauth_idp_external_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func resourceIDPExternalJWT() *schema.Resource {
Update: updateIDPExternalJWT,
Delete: deleteIdentityProvider,
Schema: map[string]*schema.Schema{
"idp_id": {
Type: schema.TypeString,
Optional: true,
Description: "The ID to use for the new identity provider. If not specified a secure random UUID will be generated.",
ValidateFunc: validation.IsUUID,
ForceNew: true,
},
"application_configuration": {
Optional: true,
Type: schema.TypeSet,
Expand Down Expand Up @@ -144,7 +151,7 @@ func createIDPExternalJWT(data *schema.ResourceData, i interface{}) error {

client := i.(Client)

bb, err := createIdentityProvider(b, client)
bb, err := createIdentityProvider(b, client, data.Get("idp_id").(string))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion fusionauth/resource_fusionauth_idp_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func createIDPGoogle(data *schema.ResourceData, i interface{}) error {

client := i.(Client)

bb, err := createIdentityProvider(b, client)
bb, err := createIdentityProvider(b, client, "")
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion fusionauth/resource_fusionauth_idp_open_id_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func newIDPOpenIDConnect() *schema.Resource {
Update: updateOpenIDConnect,
Delete: deleteIdentityProvider,
Schema: map[string]*schema.Schema{
"idp_id": {
Type: schema.TypeString,
Optional: true,
Description: "The ID to use for the new identity provider. If not specified a secure random UUID will be generated.",
ValidateFunc: validation.IsUUID,
ForceNew: true,
},
"application_configuration": {
Optional: true,
Type: schema.TypeSet,
Expand Down Expand Up @@ -279,7 +286,7 @@ func createOpenIDConnect(data *schema.ResourceData, i interface{}) error {
}

client := i.(Client)
bb, err := createIdentityProvider(b, client)
bb, err := createIdentityProvider(b, client, data.Get("idp_id").(string))
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion fusionauth/resource_fusionauth_idp_samlv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func resourceIDPSAMLv2() *schema.Resource {
Update: updateIDPSAMLv2,
Delete: deleteIdentityProvider,
Schema: map[string]*schema.Schema{
"idp_id": {
Type: schema.TypeString,
Optional: true,
Description: "The ID to use for the new identity provider. If not specified a secure random UUID will be generated.",
ValidateFunc: validation.IsUUID,
ForceNew: true,
},
"application_configuration": {
Optional: true,
Type: schema.TypeSet,
Expand Down Expand Up @@ -185,7 +192,7 @@ func createIDPSAMLv2(data *schema.ResourceData, i interface{}) error {
}

client := i.(Client)
bb, err := createIdentityProvider(b, client)
bb, err := createIdentityProvider(b, client, data.Get("idp_id").(string))
if err != nil {
return err
}
Expand Down

0 comments on commit a01a067

Please sign in to comment.