Skip to content

Commit

Permalink
Update go client + support preferred langs + fix localized templates
Browse files Browse the repository at this point in the history
* feat: Updated the FusionAuth go client to the latest version for 1.47.1

* feat(resource_fusionauth_application): Support preferred languages

* fix(resource_fusionauth_email): Suppress diff in localized templates
  • Loading branch information
elliotdickison committed Oct 5, 2023
1 parent a7af842 commit 8bb1c43
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 28 deletions.
7 changes: 7 additions & 0 deletions docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ resource "fusionauth_application" "Forum" {
enabled = false
required = false
}
preferred_languages {
enabled = false
required = false
}
type = ""
}
passwordless_configuration_enabled = false
Expand Down Expand Up @@ -154,6 +158,9 @@ resource "fusionauth_application" "Forum" {
- `last_name` - (Optional)
* `enabled` - (Optional)
* `required` - (Optional)
- `preferred_languages` - (Optional)
* `enabled` - (Optional)
* `required` - (Optional)
- `login_id_type` - (Optional) The unique login Id that will be collected during registration, this value can be email or username. Leaving the default value of email is preferred because an email address is globally unique.
- `middle_name` - (Optional)
* `enabled` - (Optional)
Expand Down
6 changes: 6 additions & 0 deletions fusionauth/resource_fusionauth_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ func newRegistrationConfiguration() *schema.Resource {
Elem: requireable(),
Optional: true,
},
"preferred_languages": {
Type: schema.TypeList,
MaxItems: 1,
Elem: requireable(),
Optional: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
Expand Down
29 changes: 18 additions & 11 deletions fusionauth/resource_fusionauth_application_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,18 @@ func buildApplication(data *schema.ResourceData) fusionauth.Application {
Enableable: buildEnableable("passwordless_configuration_enabled", data),
},
RegistrationConfiguration: fusionauth.RegistrationConfiguration{
Enableable: buildEnableable("registration_configuration.0.enabled", data),
BirthDate: buildRequireable("registration_configuration.0.birth_date", data),
ConfirmPassword: data.Get("registration_configuration.0.confirm_password").(bool),
FormId: data.Get("registration_configuration.0.form_id").(string),
FirstName: buildRequireable("registration_configuration.0.first_name", data),
FullName: buildRequireable("registration_configuration.0.full_name", data),
LastName: buildRequireable("registration_configuration.0.last_name", data),
MiddleName: buildRequireable("registration_configuration.0.middle_name", data),
MobilePhone: buildRequireable("registration_configuration.0.mobile_phone", data),
LoginIdType: fusionauth.LoginIdType(data.Get("registration_configuration.0.login_id_type").(string)),
Type: fusionauth.RegistrationType(data.Get("registration_configuration.0.type").(string)),
Enableable: buildEnableable("registration_configuration.0.enabled", data),

Check failure on line 78 in fusionauth/resource_fusionauth_application_helpers.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
BirthDate: buildRequireable("registration_configuration.0.birth_date", data),
ConfirmPassword: data.Get("registration_configuration.0.confirm_password").(bool),
FormId: data.Get("registration_configuration.0.form_id").(string),
FirstName: buildRequireable("registration_configuration.0.first_name", data),
FullName: buildRequireable("registration_configuration.0.full_name", data),
LastName: buildRequireable("registration_configuration.0.last_name", data),
MiddleName: buildRequireable("registration_configuration.0.middle_name", data),
MobilePhone: buildRequireable("registration_configuration.0.mobile_phone", data),
PreferredLanguages: buildRequireable("registration_configuration.0.preferred_languages", data),
LoginIdType: fusionauth.LoginIdType(data.Get("registration_configuration.0.login_id_type").(string)),
Type: fusionauth.RegistrationType(data.Get("registration_configuration.0.type").(string)),
},
RegistrationDeletePolicy: fusionauth.ApplicationRegistrationDeletePolicy{
Unverified: fusionauth.TimeBasedDeletePolicy{
Expand Down Expand Up @@ -339,6 +340,12 @@ func buildResourceDataFromApplication(a fusionauth.Application, data *schema.Res
"required": a.RegistrationConfiguration.MobilePhone.Required,
},
},
"preferred_languages": []map[string]interface{}{
{
"enabled": a.RegistrationConfiguration.PreferredLanguages.Enabled,
"required": a.RegistrationConfiguration.PreferredLanguages.Required,
},
},
"login_id_type": a.RegistrationConfiguration.LoginIdType,
"type": a.RegistrationConfiguration.Type,
"form_id": a.RegistrationConfiguration.FormId,
Expand Down
2 changes: 2 additions & 0 deletions fusionauth/resource_fusionauth_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func newEmail() *schema.Resource {
Type: schema.TypeMap,

Check failure on line 61 in fusionauth/resource_fusionauth_email.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
Optional: true,
Description: "The HTML Email Template used when sending emails to users who speak other languages. This overrides the default HTML Email Template based on the user’s list of preferred languages.",
DiffSuppressFunc: diffSuppressTemplate,
},
"localized_subjects": {
Type: schema.TypeMap,
Expand All @@ -71,6 +72,7 @@ func newEmail() *schema.Resource {
Type: schema.TypeMap,
Optional: true,
Description: "The Text Email Template used when sending emails to users who speak other languages. This overrides the default Text Email Template based on the user’s list of preferred languages.",
DiffSuppressFunc: diffSuppressTemplate,
},
"name": {
Type: schema.TypeString,
Expand Down
28 changes: 14 additions & 14 deletions fusionauth/resource_fusionauth_generic_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func buildGenericConnector(data *schema.ResourceData) fusionauth.GenericConnecto
return connector
}

func createGenericConnector(_ context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
func createGenericConnector(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
client := i.(Client)
connector := buildGenericConnector(data)
resp, faErrs, err := CreateConnector(client.FAClient, connector.Id, GenericConnectorRequest{Connector: connector})
resp, faErrs, err := CreateConnector(client.FAClient, connector.Id, ctx, GenericConnectorRequest{Connector: connector})
if err != nil {
return diag.Errorf("CreateGenericConnector err: %v", err)
}
Expand All @@ -123,11 +123,11 @@ func createGenericConnector(_ context.Context, data *schema.ResourceData, i inte
return nil
}

func readGenericConnector(_ context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
func readGenericConnector(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
client := i.(Client)
id := data.Id()

resp, faErrs, err := RetrieveConnector(client.FAClient, id)
resp, faErrs, err := RetrieveConnector(client.FAClient, id, ctx)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -175,11 +175,11 @@ func readGenericConnector(_ context.Context, data *schema.ResourceData, i interf
return nil
}

func updateGenericConnector(_ context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
func updateGenericConnector(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
client := i.(Client)
connector := buildGenericConnector(data)

resp, faErrs, err := UpdateConnector(client.FAClient, data.Id(), GenericConnectorRequest{Connector: connector})
resp, faErrs, err := UpdateConnector(client.FAClient, data.Id(), ctx, GenericConnectorRequest{Connector: connector})
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -221,19 +221,19 @@ func (b *GenericConnectorResponse) SetStatus(status int) {
b.StatusCode = status
}

func CreateConnector(client fusionauth.FusionAuthClient, connectorID string, request GenericConnectorRequest) (*GenericConnectorResponse, *fusionauth.Errors, error) {
return makeConnectorRequest(client, connectorID, request, http.MethodPost)
func CreateConnector(client fusionauth.FusionAuthClient, connectorID string, ctx context.Context, request GenericConnectorRequest) (*GenericConnectorResponse, *fusionauth.Errors, error) {

Check warning on line 224 in fusionauth/resource_fusionauth_generic_connector.go

View workflow job for this annotation

GitHub Actions / lint

context-as-argument: context.Context should be the first parameter of a function (revive)
return makeConnectorRequest(client, connectorID, ctx, request, http.MethodPost)
}

func RetrieveConnector(client fusionauth.FusionAuthClient, connectorID string) (*GenericConnectorResponse, *fusionauth.Errors, error) {
return makeConnectorRequest(client, connectorID, GenericConnectorRequest{}, http.MethodGet)
func RetrieveConnector(client fusionauth.FusionAuthClient, connectorID string, ctx context.Context) (*GenericConnectorResponse, *fusionauth.Errors, error) {

Check warning on line 228 in fusionauth/resource_fusionauth_generic_connector.go

View workflow job for this annotation

GitHub Actions / lint

context-as-argument: context.Context should be the first parameter of a function (revive)
return makeConnectorRequest(client, connectorID, ctx, GenericConnectorRequest{}, http.MethodGet)
}

func UpdateConnector(client fusionauth.FusionAuthClient, connectorID string, request GenericConnectorRequest) (*GenericConnectorResponse, *fusionauth.Errors, error) {
return makeConnectorRequest(client, connectorID, request, http.MethodPut)
func UpdateConnector(client fusionauth.FusionAuthClient, connectorID string, ctx context.Context, request GenericConnectorRequest) (*GenericConnectorResponse, *fusionauth.Errors, error) {

Check warning on line 232 in fusionauth/resource_fusionauth_generic_connector.go

View workflow job for this annotation

GitHub Actions / lint

context-as-argument: context.Context should be the first parameter of a function (revive)
return makeConnectorRequest(client, connectorID, ctx, request, http.MethodPut)
}

func makeConnectorRequest(client fusionauth.FusionAuthClient, connectorID string, request GenericConnectorRequest, method string) (*GenericConnectorResponse, *fusionauth.Errors, error) {
func makeConnectorRequest(client fusionauth.FusionAuthClient, connectorID string, ctx context.Context, request GenericConnectorRequest, method string) (*GenericConnectorResponse, *fusionauth.Errors, error) {
var resp GenericConnectorResponse
var errors fusionauth.Errors

Expand All @@ -242,7 +242,7 @@ func makeConnectorRequest(client fusionauth.FusionAuthClient, connectorID string
WithUriSegment(connectorID).
WithJSONBody(request).
WithMethod(method).
Do()
Do(ctx)
if restClient.ErrorRef == nil {
return &resp, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions fusionauth/resource_fusionauth_generic_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func testAccCheckGenericConnectorExists(resourceName string) resource.TestCheckF
return fmt.Errorf("no resource id is set")
}

connector, faErrs, err := RetrieveConnector(fusionauthClient(), rs.Primary.ID)
connector, faErrs, err := RetrieveConnector(fusionauthClient(), rs.Primary.ID, context.Background())
if errs := checkFusionauthErrors(faErrs, err); errs != nil {
return err
}
Expand All @@ -136,7 +136,7 @@ func testAccCheckGenericConnectorDestroy(s *terraform.State) error {

// Ensure we retry for eventual consistency in HA setups.
err := resource.RetryContext(context.Background(), retryTimeout, func() *resource.RetryError {
connector, faErrs, err := RetrieveConnector(fusionauthClient(), rs.Primary.ID)
connector, faErrs, err := RetrieveConnector(fusionauthClient(), rs.Primary.ID, context.Background())
if errs := checkFusionauthRetryErrors(faErrs, err); errs != nil {
return errs
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gpsinsight/terraform-provider-fusionauth
go 1.18

require (
github.com/FusionAuth/go-client v0.0.0-20230313183733-29fd62bc04f7
github.com/FusionAuth/go-client v0.0.0-20230727220333-2d8a30ba4996
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/FusionAuth/go-client v0.0.0-20230313183733-29fd62bc04f7 h1:NQgZJFG6wHSr+R5ni/orajx1eB/O1GUPcxvgi7kZhJs=
github.com/FusionAuth/go-client v0.0.0-20230313183733-29fd62bc04f7/go.mod h1:SyRrXMJAzMVQLiJjKfQUR59dRI3jPyZv+BXIZ//HwE4=
github.com/FusionAuth/go-client v0.0.0-20230727220333-2d8a30ba4996 h1:m1BEFfqQRaTUdyxhHXTSBaQWCI22IULsDtObQX+uweU=
github.com/FusionAuth/go-client v0.0.0-20230727220333-2d8a30ba4996/go.mod h1:SyRrXMJAzMVQLiJjKfQUR59dRI3jPyZv+BXIZ//HwE4=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
Expand Down

0 comments on commit 8bb1c43

Please sign in to comment.