From 803cc67bd0e2d3539ef563c864e0b43ff21130ea Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Tue, 14 Sep 2021 17:18:30 +0300 Subject: [PATCH 1/2] Fixed constant change-loops in the 'okta_app_group_assignments' resource --- .travis.yml | 31 --------------------- okta/resource_okta_app_group_assignments.go | 7 ++--- 2 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2ca42104c..000000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -dist: bionic -sudo: required -services: - - docker -language: go - -env: - - GOFLAGS=-mod=readonly - -install: - - make build - - make tools - -branches: - only: - - master - -matrix: - fast_finish: true - allow_failures: - - go: tip - include: - - go: '1.15.x' - name: 'Code Lint' - script: make lint - - go: '1.15.x' - name: 'Code Vet' - script: make vet - - go: '1.15.x' - name: 'Code UnitTest' - script: make test diff --git a/okta/resource_okta_app_group_assignments.go b/okta/resource_okta_app_group_assignments.go index 4b46c1dda..14611319a 100644 --- a/okta/resource_okta_app_group_assignments.go +++ b/okta/resource_okta_app_group_assignments.go @@ -67,6 +67,7 @@ func resourceAppGroupAssignments() *schema.Resource { DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { return new == "" }, + Default: "{}", }, }, }, @@ -129,16 +130,14 @@ func resourceAppGroupAssignmentsRead(ctx context.Context, d *schema.ResourceData func resourceAppGroupAssignmentsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := getOktaClientFromMetadata(m) - for _, rawGroup := range d.Get("group").(*schema.Set).List() { group := rawGroup.(map[string]interface{}) - - _, err := client.Application.DeleteApplicationGroupAssignment( + resp, err := client.Application.DeleteApplicationGroupAssignment( ctx, d.Get("app_id").(string), group["id"].(string), ) - if err != nil { + if err := suppressErrorOn404(resp, err); err != nil { return diag.Errorf("failed to delete application group assignment: %v", err) } } From a1b2fb23b4b93d381d516e773fe3b41cabd177c5 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Tue, 14 Sep 2021 18:02:53 +0300 Subject: [PATCH 2/2] Added 404 error handling --- okta/app.go | 12 ++++++------ okta/resource_okta_app_group_assignments.go | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/okta/app.go b/okta/app.go index 8e9e3546a..fa9163f52 100644 --- a/okta/app.go +++ b/okta/app.go @@ -367,25 +367,25 @@ func handleAppGroups(ctx context.Context, id string, d *schema.ResourceData, cli return asyncActionList } -func listApplicationGroupAssignments(ctx context.Context, client *okta.Client, id string) ([]*okta.ApplicationGroupAssignment, error) { +func listApplicationGroupAssignments(ctx context.Context, client *okta.Client, id string) ([]*okta.ApplicationGroupAssignment, *okta.Response, error) { var resGroups []*okta.ApplicationGroupAssignment groups, resp, err := client.Application.ListApplicationGroupAssignments(ctx, id, &query.Params{Limit: defaultPaginationLimit}) if err != nil { - return nil, err + return nil, resp, err } for { resGroups = append(resGroups, groups...) if resp.HasNextPage() { resp, err = resp.Next(ctx, &groups) if err != nil { - return nil, err + return nil, resp, err } continue } else { break } } - return resGroups, nil + return resGroups, resp, nil } func containsAppUser(userList []*okta.AppUser, id string) bool { @@ -571,7 +571,7 @@ func syncGroupsAndUsers(ctx context.Context, id string, d *schema.ResourceData, } } if ignoreGroups := d.Get("skip_groups").(bool); !ignoreGroups { - appGroups, err := listApplicationGroupAssignments(ctx, getOktaClientFromMetadata(m), id) + appGroups, _, err := listApplicationGroupAssignments(ctx, getOktaClientFromMetadata(m), id) if err != nil { return err } @@ -686,7 +686,7 @@ func listAppUsersIDsAndGroupsIDs(ctx context.Context, client *okta.Client, id st if err != nil { return nil, nil, err } - appGroups, err := listApplicationGroupAssignments(ctx, client, id) + appGroups, _, err := listApplicationGroupAssignments(ctx, client, id) if err != nil { return nil, nil, err } diff --git a/okta/resource_okta_app_group_assignments.go b/okta/resource_okta_app_group_assignments.go index 14611319a..0378297d8 100644 --- a/okta/resource_okta_app_group_assignments.go +++ b/okta/resource_okta_app_group_assignments.go @@ -102,16 +102,18 @@ func resourceAppGroupAssignmentsCreate(ctx context.Context, d *schema.ResourceDa func resourceAppGroupAssignmentsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := getOktaClientFromMetadata(m) - - assignments, err := listApplicationGroupAssignments( + assignments, resp, err := listApplicationGroupAssignments( ctx, client, d.Get("app_id").(string), ) - if err != nil { + if err := suppressErrorOn404(resp, err); err != nil { return diag.Errorf("failed to fetch group assignments: %v", err) } - + if assignments == nil { + d.SetId("") + return nil + } tfFlattenedAssignments := make([]interface{}, len(assignments)) for i, assignment := range assignments { tfAssignment, err := groupAssignmentToTFGroup(assignment)