Skip to content

Commit ec45f46

Browse files
meer-nasser-alihkantare
authored andcommitted
Enterprise Management: Pagination changes and documentation updated
1 parent b3b9967 commit ec45f46

9 files changed

+86
-26
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/IBM/ibm-cos-sdk-go-config v1.0.1
1616
github.com/IBM/keyprotect-go-client v0.7.0
1717
github.com/IBM/networking-go-sdk v0.13.0
18-
github.com/IBM/platform-services-go-sdk v0.17.17
18+
github.com/IBM/platform-services-go-sdk v0.18.7
1919
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
2020
github.com/IBM/schematics-go-sdk v0.0.2
2121
github.com/IBM/secrets-manager-go-sdk v0.1.19
@@ -54,4 +54,4 @@ require (
5454

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

57-
replace github.ibm.com/ibmcloud/kubernetesservice-go-sdk => ./common/github.ibm.com/ibmcloud/kubernetesservice-go-sdk
57+
replace github.ibm.com/ibmcloud/kubernetesservice-go-sdk => ./common/github.ibm.com/ibmcloud/kubernetesservice-go-sdk

ibm/data_source_ibm_enterprise_account_groups.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,28 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
128128
if err != nil {
129129
return diag.FromErr(err)
130130
}
131+
next_docid := ""
131132
listAccountGroupsOptions := &enterprisemanagementv1.ListAccountGroupsOptions{}
132-
listAccountGroupsResponse, response, err := enterpriseManagementClient.ListAccountGroupsWithContext(context, listAccountGroupsOptions)
133-
if err != nil {
134-
log.Printf("[DEBUG] ListAccountGroupsWithContext failed %s\n%s", err, response)
135-
return diag.FromErr(err)
133+
var allRecs []enterprisemanagementv1.AccountGroup
134+
for {
135+
listAccountGroupsResponse, response, err := enterpriseManagementClient.ListAccountGroupsWithContext(context, listAccountGroupsOptions)
136+
if err != nil {
137+
log.Printf("[DEBUG] ListAccountGroupsWithContext failed %s\n%s", err, response)
138+
return diag.FromErr(err)
139+
}
140+
allRecs = append(allRecs, listAccountGroupsResponse.Resources...)
141+
if listAccountGroupsResponse.NextURL != nil {
142+
next_docid, err = getEnterpriseNext(listAccountGroupsResponse.NextURL)
143+
if err != nil {
144+
log.Printf("[DEBUG] Error while parsing %s\n%v", *listAccountGroupsResponse.NextURL, err)
145+
return diag.FromErr(err)
146+
}
147+
listAccountGroupsOptions.NextDocid = &next_docid
148+
log.Printf("[DEBUG] ListAccountsWithContext failed %s", next_docid)
149+
} else {
150+
next_docid = ""
151+
break
152+
}
136153
}
137154

138155
// Use the provided filter argument and construct a new list with only the requested resource(s)
@@ -142,17 +159,17 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
142159
if v, ok := d.GetOk("name"); ok {
143160
name = v.(string)
144161
suppliedFilter = true
145-
for _, data := range listAccountGroupsResponse.Resources {
162+
for _, data := range allRecs {
146163
if *data.Name == name {
147164
matchResources = append(matchResources, data)
148165
}
149166
}
150167
} else {
151-
matchResources = listAccountGroupsResponse.Resources
168+
matchResources = allRecs
152169
}
153-
listAccountGroupsResponse.Resources = matchResources
170+
allRecs = matchResources
154171

155-
if len(listAccountGroupsResponse.Resources) == 0 {
172+
if len(allRecs) == 0 {
156173
return diag.FromErr(fmt.Errorf("no Resources found with name %s", name))
157174
}
158175

@@ -161,8 +178,8 @@ func dataSourceIbmEnterpriseAccountGroupsRead(context context.Context, d *schema
161178
} else {
162179
d.SetId(dataSourceIbmAccountGroupsID(d))
163180
}
164-
if listAccountGroupsResponse.Resources != nil {
165-
err = d.Set("account_groups", dataSourceListEnterpriseAccountGroupsResponseFlattenResources(listAccountGroupsResponse.Resources))
181+
if allRecs != nil {
182+
err = d.Set("account_groups", dataSourceListEnterpriseAccountGroupsResponseFlattenResources(allRecs))
166183
if err != nil {
167184
return diag.FromErr(fmt.Errorf("Error setting resources %s", err))
168185
}

ibm/data_source_ibm_enterprise_accounts.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,29 @@ func dataSourceIbmEnterpriseAccountsRead(context context.Context, d *schema.Reso
130130
return diag.FromErr(err)
131131
}
132132
listAccountsOptions := &enterprisemanagementv1.ListAccountsOptions{}
133-
listAccountsResponse, response, err := enterpriseManagementClient.ListAccountsWithContext(context, listAccountsOptions)
134-
if err != nil {
135-
log.Printf("[DEBUG] ListAccountsWithContext failed %s\n%s", err, response)
136-
return diag.FromErr(err)
133+
next_docid := ""
134+
var allRecs []enterprisemanagementv1.Account
135+
for {
136+
listAccountsResponse, response, err := enterpriseManagementClient.ListAccountsWithContext(context, listAccountsOptions)
137+
if err != nil {
138+
log.Printf("[DEBUG] ListAccountsWithContext failed %s\n%s", err, response)
139+
return diag.FromErr(err)
140+
}
141+
allRecs = append(allRecs, listAccountsResponse.Resources...)
142+
if listAccountsResponse.NextURL != nil {
143+
next_docid, err = getEnterpriseNext(listAccountsResponse.NextURL)
144+
if err != nil {
145+
log.Printf("[DEBUG] Error while parsing %s\n%v", *listAccountsResponse.NextURL, err)
146+
return diag.FromErr(err)
147+
}
148+
listAccountsOptions.NextDocid = &next_docid
149+
log.Printf("[DEBUG] ListAccountsWithContext failed %s", next_docid)
150+
} else {
151+
next_docid = ""
152+
break
153+
}
137154
}
155+
138156
// Use the provided filter argument and construct a new list with only the requested resource(s)
139157
var matchResources []enterprisemanagementv1.Account
140158
var name string
@@ -143,17 +161,17 @@ func dataSourceIbmEnterpriseAccountsRead(context context.Context, d *schema.Reso
143161
if v, ok := d.GetOk("name"); ok {
144162
name = v.(string)
145163
suppliedFilter = true
146-
for _, data := range listAccountsResponse.Resources {
164+
for _, data := range allRecs {
147165
if *data.Name == name {
148166
matchResources = append(matchResources, data)
149167
}
150168
}
151169
} else {
152-
matchResources = listAccountsResponse.Resources
170+
matchResources = allRecs
153171
}
154-
listAccountsResponse.Resources = matchResources
172+
allRecs = matchResources
155173

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

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

166-
if listAccountsResponse.Resources != nil {
167-
err = d.Set("accounts", dataSourceListEnterpriseAccountsResponseFlattenResources(listAccountsResponse.Resources))
184+
if allRecs != nil {
185+
err = d.Set("accounts", dataSourceListEnterpriseAccountsResponseFlattenResources(allRecs))
168186
if err != nil {
169187
return diag.FromErr(fmt.Errorf("Error setting resources %s", err))
170188
}

website/docs/d/enterprise_account_groups.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported:
2929

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

32-
* `account_groups` - A list of account groups. Nested `resources` blocks have the following structure:
32+
* `account_groups` - A list of account groups. Nested `account_groups` blocks have the following structure:
3333
* `url` - The URL of the account group.
3434
* `id` - The account group ID.
3535
* `crn` - The Cloud Resource Name (CRN) of the account group.

website/docs/d/enterprise_accounts.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported:
2929

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

32-
* `accounts` - A list of accounts. Nested `resources` blocks have the following structure:
32+
* `accounts` - A list of accounts. Nested `accounts` blocks have the following structure:
3333
* `url` - The URL of the account.
3434
* `id` - The account ID.
3535
* `crn` - The Cloud Resource Name (CRN) of the account.

website/docs/d/enterprises.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported:
2929

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

32-
* `enterprises` - A list of enterprise objects. Nested `resources` blocks have the following structure:
32+
* `enterprises` - A list of enterprise objects. Nested `enterprises` blocks have the following structure:
3333
* `url` - The URL of the enterprise.
3434
* `id` - The enterprise ID.
3535
* `enterprise_account_id` - The enterprise account ID.

website/docs/r/enterprise.html.markdown

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ In addition to all arguments above, the following attributes are exported:
4444
* `created_by` - The IAM ID of the user or service that created the enterprise.
4545
* `updated_at` - The time stamp at which the enterprise was last updated.
4646
* `updated_by` - The IAM ID of the user or service that updated the enterprise.
47+
48+
## Import
49+
50+
ibm_enterprise can be imported using enterprise_id, eg.
51+
52+
```
53+
$ terraform import ibm_enterprise.enterprise_example c117bf3cb7a448fca830645865e3f1f2
54+
55+
```

website/docs/r/enterprise_account.html.markdown

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The following arguments are supported to create a new account in enterprise:
3636
* `name` - (Required, string) The name of the account. This field must have 3 - 60 characters.
3737
* `owner_iam_id` - (Required, string) The IAM ID of the account owner, such as `IBMid-0123ABC`. The IAM ID must already exist.
3838

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

4141
* `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.
4242
* `enterprise_id` - (Required, string) The enterprise ID where the account should be imported to.
@@ -62,3 +62,11 @@ In addition to all arguments above, the following attributes are exported:
6262
* `created_by` - The IAM ID of the user or service that created the account.
6363
* `updated_at` - The time stamp at which the account was last updated.
6464
* `updated_by` - The IAM ID of the user or service that updated the account.
65+
66+
## Import
67+
68+
ibm_enterprise_account can be imported using account_id, eg.
69+
70+
```
71+
$ terraform import ibm_enterprise_account.example 907ec1a69a354afc94d3a7b499d6784f
72+
```

website/docs/r/enterprise_account_group.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ In addition to all arguments above, the following attributes are exported:
4545
* `created_by` - The IAM ID of the user or service that created the account group.
4646
* `updated_at` - The time stamp at which the account group was last updated.
4747
* `updated_by` - The IAM ID of the user or service that updated the account group.
48+
49+
## Import
50+
51+
ibm_enterprise_account_group can be imported using account_group_id, eg.
52+
53+
```
54+
$ terraform import ibm_enterprise_account_group.example ae337d0b6cf6485a918a47e289ab4628
55+
```

0 commit comments

Comments
 (0)