Skip to content

Commit

Permalink
Enterprise Management: Pagination changes and documentation updated
Browse files Browse the repository at this point in the history
  • Loading branch information
meer-nasser-ali authored and hkantare committed Apr 12, 2021
1 parent b3b9967 commit ec45f46
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 26 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/IBM/ibm-cos-sdk-go-config v1.0.1
github.com/IBM/keyprotect-go-client v0.7.0
github.com/IBM/networking-go-sdk v0.13.0
github.com/IBM/platform-services-go-sdk v0.17.17
github.com/IBM/platform-services-go-sdk v0.18.7
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/schematics-go-sdk v0.0.2
github.com/IBM/secrets-manager-go-sdk v0.1.19
Expand Down Expand Up @@ -54,4 +54,4 @@ require (

replace github.com/softlayer/softlayer-go v0.0.0-20190814165317-b9062a914a22 => ./common/github.com/softlayer/softlayer-go

replace github.ibm.com/ibmcloud/kubernetesservice-go-sdk => ./common/github.ibm.com/ibmcloud/kubernetesservice-go-sdk
replace github.ibm.com/ibmcloud/kubernetesservice-go-sdk => ./common/github.ibm.com/ibmcloud/kubernetesservice-go-sdk
37 changes: 27 additions & 10 deletions ibm/data_source_ibm_enterprise_account_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,28 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
if err != nil {
return diag.FromErr(err)
}
next_docid := ""
listAccountGroupsOptions := &enterprisemanagementv1.ListAccountGroupsOptions{}
listAccountGroupsResponse, response, err := enterpriseManagementClient.ListAccountGroupsWithContext(context, listAccountGroupsOptions)
if err != nil {
log.Printf("[DEBUG] ListAccountGroupsWithContext failed %s\n%s", err, response)
return diag.FromErr(err)
var allRecs []enterprisemanagementv1.AccountGroup
for {
listAccountGroupsResponse, response, err := enterpriseManagementClient.ListAccountGroupsWithContext(context, listAccountGroupsOptions)
if err != nil {
log.Printf("[DEBUG] ListAccountGroupsWithContext failed %s\n%s", err, response)
return diag.FromErr(err)
}
allRecs = append(allRecs, listAccountGroupsResponse.Resources...)
if listAccountGroupsResponse.NextURL != nil {
next_docid, err = getEnterpriseNext(listAccountGroupsResponse.NextURL)
if err != nil {
log.Printf("[DEBUG] Error while parsing %s\n%v", *listAccountGroupsResponse.NextURL, err)
return diag.FromErr(err)
}
listAccountGroupsOptions.NextDocid = &next_docid
log.Printf("[DEBUG] ListAccountsWithContext failed %s", next_docid)
} else {
next_docid = ""
break
}
}

// Use the provided filter argument and construct a new list with only the requested resource(s)
Expand All @@ -142,17 +159,17 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
if v, ok := d.GetOk("name"); ok {
name = v.(string)
suppliedFilter = true
for _, data := range listAccountGroupsResponse.Resources {
for _, data := range allRecs {
if *data.Name == name {
matchResources = append(matchResources, data)
}
}
} else {
matchResources = listAccountGroupsResponse.Resources
matchResources = allRecs
}
listAccountGroupsResponse.Resources = matchResources
allRecs = matchResources

if len(listAccountGroupsResponse.Resources) == 0 {
if len(allRecs) == 0 {
return diag.FromErr(fmt.Errorf("no Resources found with name %s", name))
}

Expand All @@ -161,8 +178,8 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
} else {
d.SetId(dataSourceIbmAccountGroupsID(d))
}
if listAccountGroupsResponse.Resources != nil {
err = d.Set("account_groups", dataSourceListEnterpriseAccountGroupsResponseFlattenResources(listAccountGroupsResponse.Resources))
if allRecs != nil {
err = d.Set("account_groups", dataSourceListEnterpriseAccountGroupsResponseFlattenResources(allRecs))
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting resources %s", err))
}
Expand Down
38 changes: 28 additions & 10 deletions ibm/data_source_ibm_enterprise_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,29 @@ func dataSourceIbmEnterpriseAccountsRead(context context.Context, d *schema.Reso
return diag.FromErr(err)
}
listAccountsOptions := &enterprisemanagementv1.ListAccountsOptions{}
listAccountsResponse, response, err := enterpriseManagementClient.ListAccountsWithContext(context, listAccountsOptions)
if err != nil {
log.Printf("[DEBUG] ListAccountsWithContext failed %s\n%s", err, response)
return diag.FromErr(err)
next_docid := ""
var allRecs []enterprisemanagementv1.Account
for {
listAccountsResponse, response, err := enterpriseManagementClient.ListAccountsWithContext(context, listAccountsOptions)
if err != nil {
log.Printf("[DEBUG] ListAccountsWithContext failed %s\n%s", err, response)
return diag.FromErr(err)
}
allRecs = append(allRecs, listAccountsResponse.Resources...)
if listAccountsResponse.NextURL != nil {
next_docid, err = getEnterpriseNext(listAccountsResponse.NextURL)
if err != nil {
log.Printf("[DEBUG] Error while parsing %s\n%v", *listAccountsResponse.NextURL, err)
return diag.FromErr(err)
}
listAccountsOptions.NextDocid = &next_docid
log.Printf("[DEBUG] ListAccountsWithContext failed %s", next_docid)
} else {
next_docid = ""
break
}
}

// Use the provided filter argument and construct a new list with only the requested resource(s)
var matchResources []enterprisemanagementv1.Account
var name string
Expand All @@ -143,17 +161,17 @@ func dataSourceIbmEnterpriseAccountsRead(context context.Context, d *schema.Reso
if v, ok := d.GetOk("name"); ok {
name = v.(string)
suppliedFilter = true
for _, data := range listAccountsResponse.Resources {
for _, data := range allRecs {
if *data.Name == name {
matchResources = append(matchResources, data)
}
}
} else {
matchResources = listAccountsResponse.Resources
matchResources = allRecs
}
listAccountsResponse.Resources = matchResources
allRecs = matchResources

if len(listAccountsResponse.Resources) == 0 {
if len(allRecs) == 0 {
return diag.FromErr(fmt.Errorf("no Resources found with name %s\nIf not specified, please specify more filters", name))
}

Expand All @@ -163,8 +181,8 @@ func dataSourceIbmEnterpriseAccountsRead(context context.Context, d *schema.Reso
d.SetId(dataSourceIbmEnterpriseAccountsID(d))
}

if listAccountsResponse.Resources != nil {
err = d.Set("accounts", dataSourceListEnterpriseAccountsResponseFlattenResources(listAccountsResponse.Resources))
if allRecs != nil {
err = d.Set("accounts", dataSourceListEnterpriseAccountsResponseFlattenResources(allRecs))
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting resources %s", err))
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/enterprise_account_groups.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The unique identifier of the account_groups.

* `account_groups` - A list of account groups. Nested `resources` blocks have the following structure:
* `account_groups` - A list of account groups. Nested `account_groups` blocks have the following structure:
* `url` - The URL of the account group.
* `id` - The account group ID.
* `crn` - The Cloud Resource Name (CRN) of the account group.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/enterprise_accounts.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The unique identifier of the accounts.

* `accounts` - A list of accounts. Nested `resources` blocks have the following structure:
* `accounts` - A list of accounts. Nested `accounts` blocks have the following structure:
* `url` - The URL of the account.
* `id` - The account ID.
* `crn` - The Cloud Resource Name (CRN) of the account.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/enterprises.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The unique identifier of the enterprises.

* `enterprises` - A list of enterprise objects. Nested `resources` blocks have the following structure:
* `enterprises` - A list of enterprise objects. Nested `enterprises` blocks have the following structure:
* `url` - The URL of the enterprise.
* `id` - The enterprise ID.
* `enterprise_account_id` - The enterprise account ID.
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/enterprise.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ In addition to all arguments above, the following attributes are exported:
* `created_by` - The IAM ID of the user or service that created the enterprise.
* `updated_at` - The time stamp at which the enterprise was last updated.
* `updated_by` - The IAM ID of the user or service that updated the enterprise.

## Import

ibm_enterprise can be imported using enterprise_id, eg.

```
$ terraform import ibm_enterprise.enterprise_example c117bf3cb7a448fca830645865e3f1f2
```
10 changes: 9 additions & 1 deletion website/docs/r/enterprise_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The following arguments are supported to create a new account in enterprise:
* `name` - (Required, string) The name of the account. This field must have 3 - 60 characters.
* `owner_iam_id` - (Required, string) The IAM ID of the account owner, such as `IBMid-0123ABC`. The IAM ID must already exist.

The following arguments are supported to import a new account in enterprise:
The following arguments are supported to import an existing standalone account in enterprise:

* `parent` - (Required, string) The CRN of the parent under which the account will be created. The parent can be an existing account group or the enterprise itself.
* `enterprise_id` - (Required, string) The enterprise ID where the account should be imported to.
Expand All @@ -62,3 +62,11 @@ In addition to all arguments above, the following attributes are exported:
* `created_by` - The IAM ID of the user or service that created the account.
* `updated_at` - The time stamp at which the account was last updated.
* `updated_by` - The IAM ID of the user or service that updated the account.

## Import

ibm_enterprise_account can be imported using account_id, eg.

```
$ terraform import ibm_enterprise_account.example 907ec1a69a354afc94d3a7b499d6784f
```
8 changes: 8 additions & 0 deletions website/docs/r/enterprise_account_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ In addition to all arguments above, the following attributes are exported:
* `created_by` - The IAM ID of the user or service that created the account group.
* `updated_at` - The time stamp at which the account group was last updated.
* `updated_by` - The IAM ID of the user or service that updated the account group.

## Import

ibm_enterprise_account_group can be imported using account_group_id, eg.

```
$ terraform import ibm_enterprise_account_group.example ae337d0b6cf6485a918a47e289ab4628
```

0 comments on commit ec45f46

Please sign in to comment.