Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fusion auth reactor resource #106

Merged
merged 1 commit into from
Dec 28, 2021

Conversation

einal3m
Copy link
Contributor

@einal3m einal3m commented Dec 22, 2021

This PR adds the FusionAuth reactor as a terraform resource.

The reactor apis aren't standard CRUD apis, so this implementation is a little different:

  • The create and update methods both use the same POST api to update the license attributes
  • The read method can't update the state when the reactor is licensed, since the GET api doesn't include the license attributes
  • The create method doesn't return the id of the reactor (aka fusion auth instance) so I have made up an id. I think this will be ok, since there can be only one reactor.

I've left some comments in the code where things are a little different than for a normal resource.

@einal3m einal3m force-pushed the add-reactor-resource branch 2 times, most recently from b33d365 to 1ede645 Compare December 22, 2021 04:03
client := i.(Client)
reactor := buildReactor(data)

resp, faErrs, err := client.FAClient.ActivateReactor(fusionauth.ReactorRequest{
Copy link
Contributor Author

@einal3m einal3m Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the create and update paths use the ActivateReactor method.

There really is no "create" endpoint for the reactor because it always exists, this endpoint sets the license data (for the first time or any subsequent times).

}

if err := checkResponse(resp.StatusCode, faErrs); err != nil {
data.Partial(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During local testing we discovered that the terraform state got updated even if the resource failed to update in FusionAuth. This is true of other resources too (we check with the webhook). After a little googling, we discovered this little snippet of code data.Partial(true) which tells terraform that something went wrong and not to update the state.

@einal3m einal3m marked this pull request as ready for review December 22, 2021 22:31
Copy link
Member

@robotdan robotdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @melm73.

I don't have any strong opinions here, and I am not a Terraform expert, so feel free to ignore my comments.

Since this isn't really a traditional CRUD as @melm73 mentions - would it read better to use function names such as:

  • activate() This could in theory replace both createReactor and updateReactor since the only two states are licensed and un-licensed, so updating just re-activates with a different license key.
  • decommission() Depends on how far we want to go with the Nuclear Reactor theme. 😁Could also use deactivate.
  • status() The read operation currently returns the license status of the FusionAuth instance.

@MCBrandenburg MCBrandenburg merged commit 3112f3c into FusionAuth:main Dec 28, 2021
@MCBrandenburg
Copy link
Contributor

@melm73 thanks for your contributions. Pushing this and building v0.1.59

@einal3m einal3m deleted the add-reactor-resource branch January 11, 2022 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants