Skip to content

Commit

Permalink
[WR-418] Add UpdateContext to Realm resource (#40)
Browse files Browse the repository at this point in the history
* [WR-418] Add UpdateContext to Realm resource

- Enables in-place updating of MPC and TozID federation settings
  for a Realm
  • Loading branch information
Mrhea authored Mar 16, 2022
1 parent 137d0d0 commit 44bd81d
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BINARY=terraform-provider-tozny
VERSION=0.17.0
VERSION=0.18.0

default: build

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down Expand Up @@ -360,10 +360,10 @@ You should see that the tozny/tozny was self signed. If it does not say this, we
Initializing the backend...
Initializing provider plugins...
- Finding tozny/tozny versions matching "0.17.0"...
- Finding tozny/tozny versions matching "0.18.0"...
- Finding latest version of hashicorp/random...
- Installing tozny/tozny v0.17.0...
- Installed tozny/tozny v0.17.0 (self-signed, key ID 16B47290885B0598)
- Installing tozny/tozny v0.18.0...
- Installed tozny/tozny v0.18.0 (self-signed, key ID 16B47290885B0598)
- Installing hashicorp/random v3.1.0...
- Installed hashicorp/random v3.1.0 (signed by HashiCorp)
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/tozny_realm_application_access_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/accounts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/providers/ldap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/providers/ldap/mappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/applications/SAMLDescription/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/applications/clientSecret/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/applications/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/applications/mappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/applications/roles/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/autoDerivedClientCredentials/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/groups/defaultGroups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/groups/roleMappings/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/identities/groupMembership/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/identities/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/roles/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/realms/toznyHostedBroker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
# for Tozny registry.terraform.io/tozny
source = "tozny/tozny"
# Pin Tozny provider version
version = ">=0.17.0"
version = ">=0.18.0"
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions tozny/resource_realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func resourceRealm() *schema.Resource {
CreateContext: resourceRealmCreate,
ReadContext: resourceRealmRead,
DeleteContext: resourceRealmDelete,
UpdateContext: resourceRealmUpdate,
Schema: map[string]*schema.Schema{
"realm_id": {
Description: "Service defined unique identifier for the realm.",
Expand Down Expand Up @@ -107,14 +108,12 @@ func resourceRealm() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
"tozid_federation_enabled": {
Description: "Flag to enable TozID Federation for the Realm.",
Type: schema.TypeBool,
Default: false,
Optional: true,
ForceNew: true,
},
},
}
Expand Down Expand Up @@ -227,3 +226,27 @@ func resourceRealmDelete(ctx context.Context, d *schema.ResourceData, m interfac

return diags
}

func resourceRealmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics
toznySDK, err := MakeToznySDK(d, m)
if err != nil {
return diag.FromErr(err)
}

if d.HasChanges("mpc_enabled", "tozid_federation_enabled") {
federation_setting := d.Get("tozid_federation_enabled").(bool)
mpc_setting := d.Get("mpc_enabled").(bool)
err = toznySDK.RealmSettingsUpdate(ctx, d.Get("realm_name").(string), identityClient.RealmSettingsUpdateRequest{
MPCEnabled: &mpc_setting,
TozIDFederationEnabled: &federation_setting,
})
if err != nil {
return diag.FromErr(err)
}
d.Set("mpc_enabled", d.Get("mpc_enabled"))
d.Set("tozid_federation_enabled", d.Get("tozid_federation_enabled"))
}

return diags
}

0 comments on commit 44bd81d

Please sign in to comment.