Skip to content

Commit

Permalink
DXCDT-524: auth0_organization_connections resource export support (#…
Browse files Browse the repository at this point in the history
…823)

* Adding organization connections resource export support

* Fixing unit test

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
willvedd and willvedd authored Sep 6, 2023
1 parent b3feb4a commit 8983521
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/auth/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var RequiredScopes = []string{
"read:anomaly_blocks", "delete:anomaly_blocks",
"create:log_streams", "delete:log_streams", "read:log_streams", "update:log_streams",
"create:actions", "delete:actions", "read:actions", "update:actions",
"create:organizations", "delete:organizations", "read:organizations", "update:organizations", "read:organization_members", "read:organization_member_roles",
"create:organizations", "delete:organizations", "read:organizations", "update:organizations", "read:organization_members", "read:organization_member_roles", "read:organization_connections",
"read:prompts", "update:prompts",
"read:attack_protection", "update:attack_protection",
}
Expand Down
20 changes: 20 additions & 0 deletions internal/auth0/mock/organization_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/auth0/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ type OrganizationAPI interface {
//
// See: https://auth0.com/docs/api/management/v2#!/Organizations/get_organization_member_roles
MemberRoles(ctx context.Context, id string, userID string, opts ...management.RequestOption) (r *management.OrganizationMemberRoleList, err error)

// Connections retrieves connections enabled for an organization.
//
// See: https://auth0.com/docs/api/management/v2/#!/Organizations/get_enabled_connections
Connections(ctx context.Context, id string, opts ...management.RequestOption) (c *management.OrganizationConnectionList, err error)
}
16 changes: 14 additions & 2 deletions internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,22 @@ func (f *organizationResourceFetcher) FetchData(ctx context.Context) (importData
}

for _, org := range orgs {
organization := org.(*management.Organization)
data = append(data, importDataItem{
ResourceName: "auth0_organization." + sanitizeResourceName(org.(*management.Organization).GetName()),
ImportID: org.(*management.Organization).GetID(),
ResourceName: "auth0_organization." + sanitizeResourceName(organization.GetName()),
ImportID: organization.GetID(),
})

conns, err := f.api.Organization.Connections(ctx, organization.GetID())
if err != nil {
return data, err
}
if len(conns.OrganizationConnections) > 0 {
data = append(data, importDataItem{
ResourceName: "auth0_organization_connections." + sanitizeResourceName(organization.GetName()),
ImportID: organization.GetID(),
})
}
}

return data, nil
Expand Down
60 changes: 58 additions & 2 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,30 @@ func TestOrganizationResourceFetcher_FetchData(t *testing.T) {
},
nil,
)
orgAPI.EXPECT().
Connections(gomock.Any(), gomock.Any(), gomock.Any()).
Return(
&management.OrganizationConnectionList{
OrganizationConnections: []*management.OrganizationConnection{
{
ConnectionID: auth0.String("conn-1"),
},
},
},
nil,
)
orgAPI.EXPECT().
Connections(gomock.Any(), gomock.Any(), gomock.Any()).
Return(
&management.OrganizationConnectionList{
OrganizationConnections: []*management.OrganizationConnection{
{
ConnectionID: auth0.String("conn-1"),
},
},
},
nil,
)
orgAPI.EXPECT().
List(gomock.Any(), gomock.Any(), gomock.Any()).
Return(
Expand All @@ -684,12 +708,32 @@ func TestOrganizationResourceFetcher_FetchData(t *testing.T) {
},
{
ID: auth0.String("org_4"),
Name: auth0.String("Organization 4"),
Name: auth0.String("Organization 4 - NO CONNECTIONS!"),
},
},
},
nil,
)
orgAPI.EXPECT().
Connections(gomock.Any(), gomock.Any(), gomock.Any()).
Return(
&management.OrganizationConnectionList{
OrganizationConnections: []*management.OrganizationConnection{
{
ConnectionID: auth0.String("conn-1"),
},
},
},
nil,
)
orgAPI.EXPECT().
Connections(gomock.Any(), gomock.Any(), gomock.Any()).
Return(
&management.OrganizationConnectionList{
OrganizationConnections: []*management.OrganizationConnection{},
},
nil,
)

fetcher := organizationResourceFetcher{
api: &auth0.API{
Expand All @@ -702,16 +746,28 @@ func TestOrganizationResourceFetcher_FetchData(t *testing.T) {
ResourceName: "auth0_organization.Organization1",
ImportID: "org_1",
},
{
ResourceName: "auth0_organization_connections.Organization1",
ImportID: "org_1",
},
{
ResourceName: "auth0_organization.Organization2",
ImportID: "org_2",
},
{
ResourceName: "auth0_organization_connections.Organization2",
ImportID: "org_2",
},
{
ResourceName: "auth0_organization.Organization3",
ImportID: "org_3",
},
{
ResourceName: "auth0_organization.Organization4",
ResourceName: "auth0_organization_connections.Organization3",
ImportID: "org_3",
},
{
ResourceName: "auth0_organization.Organization4-NOCONNECTIONS",
ImportID: "org_4",
},
}
Expand Down

0 comments on commit 8983521

Please sign in to comment.