From ec45f46b08639506cb5418777403aede82b0c048 Mon Sep 17 00:00:00 2001 From: Meer Nasser Ali Date: Fri, 9 Apr 2021 15:46:29 +0530 Subject: [PATCH] Enterprise Management: Pagination changes and documentation updated --- go.mod | 4 +- ...ta_source_ibm_enterprise_account_groups.go | 37 +++++++++++++----- ibm/data_source_ibm_enterprise_accounts.go | 38 ++++++++++++++----- .../d/enterprise_account_groups.html.markdown | 2 +- .../docs/d/enterprise_accounts.html.markdown | 2 +- website/docs/d/enterprises.html.markdown | 2 +- website/docs/r/enterprise.html.markdown | 9 +++++ .../docs/r/enterprise_account.html.markdown | 10 ++++- .../r/enterprise_account_group.html.markdown | 8 ++++ 9 files changed, 86 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 17ea3e0b80..d35d8ff1d0 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 \ No newline at end of file diff --git a/ibm/data_source_ibm_enterprise_account_groups.go b/ibm/data_source_ibm_enterprise_account_groups.go index 935ec87a10..fdf07b88e8 100644 --- a/ibm/data_source_ibm_enterprise_account_groups.go +++ b/ibm/data_source_ibm_enterprise_account_groups.go @@ -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) @@ -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)) } @@ -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)) } diff --git a/ibm/data_source_ibm_enterprise_accounts.go b/ibm/data_source_ibm_enterprise_accounts.go index e0eb0823e9..9683b27390 100644 --- a/ibm/data_source_ibm_enterprise_accounts.go +++ b/ibm/data_source_ibm_enterprise_accounts.go @@ -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 @@ -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)) } @@ -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)) } diff --git a/website/docs/d/enterprise_account_groups.html.markdown b/website/docs/d/enterprise_account_groups.html.markdown index 46af61a7b9..b28ab6c4de 100644 --- a/website/docs/d/enterprise_account_groups.html.markdown +++ b/website/docs/d/enterprise_account_groups.html.markdown @@ -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. diff --git a/website/docs/d/enterprise_accounts.html.markdown b/website/docs/d/enterprise_accounts.html.markdown index bcb5189f82..2275e7a469 100644 --- a/website/docs/d/enterprise_accounts.html.markdown +++ b/website/docs/d/enterprise_accounts.html.markdown @@ -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. diff --git a/website/docs/d/enterprises.html.markdown b/website/docs/d/enterprises.html.markdown index 8d215039e7..d3c154e03b 100644 --- a/website/docs/d/enterprises.html.markdown +++ b/website/docs/d/enterprises.html.markdown @@ -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. diff --git a/website/docs/r/enterprise.html.markdown b/website/docs/r/enterprise.html.markdown index 1c68e95aaa..01eb4edad2 100644 --- a/website/docs/r/enterprise.html.markdown +++ b/website/docs/r/enterprise.html.markdown @@ -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 + +``` diff --git a/website/docs/r/enterprise_account.html.markdown b/website/docs/r/enterprise_account.html.markdown index 0d7f6ceeda..65d1a8c0b2 100644 --- a/website/docs/r/enterprise_account.html.markdown +++ b/website/docs/r/enterprise_account.html.markdown @@ -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. @@ -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 +``` diff --git a/website/docs/r/enterprise_account_group.html.markdown b/website/docs/r/enterprise_account_group.html.markdown index 631624e992..e8e8f21e63 100644 --- a/website/docs/r/enterprise_account_group.html.markdown +++ b/website/docs/r/enterprise_account_group.html.markdown @@ -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 +```