From 16304ac0e7505c0b3aede617d0cbc7656d07e422 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Tue, 10 Aug 2021 15:10:31 +0200 Subject: [PATCH 01/18] First Stab Have not added tests. --- .../services/users/all_users_datasource.go | 175 ++++++++++++++++++ internal/services/users/registration.go | 1 + 2 files changed, 176 insertions(+) create mode 100644 internal/services/users/all_users_datasource.go diff --git a/internal/services/users/all_users_datasource.go b/internal/services/users/all_users_datasource.go new file mode 100644 index 000000000..82488002c --- /dev/null +++ b/internal/services/users/all_users_datasource.go @@ -0,0 +1,175 @@ +package users + +import ( + "context" + "crypto/sha1" + "encoding/base64" + "errors" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azuread/internal/clients" + "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/manicminer/hamilton/msgraph" + "github.com/manicminer/hamilton/odata" + "strings" + "time" +) + +func allUsersData() *schema.Resource { + return &schema.Resource{ + ReadContext: allUsersDataSourceRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: map[string]*schema.Schema{ + + "object_ids": { + Description: "The object IDs of the users", + Type: schema.TypeList, + Computed: true, + }, + + "user_principal_names": { + Description: "The user principal names (UPNs) of the users", + Type: schema.TypeList, + Computed: true, + + }, + + "users": { + Description: "The list of users", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_enabled": { + Description: "Whether or not the account is enabled", + Type: schema.TypeBool, + Computed: true, + }, + + "display_name": { + Description: "The display name of the user", + Type: schema.TypeString, + Computed: true, + }, + + "mail": { + Description: "The primary email address of the user", + Type: schema.TypeString, + Computed: true, + }, + + "mail_nickname": { + Description: "The email alias of the user", + Type: schema.TypeString, + Computed: true, + }, + + "object_id": { + Description: "The object ID of the user", + Type: schema.TypeString, + Computed: true, + }, + + "onpremises_immutable_id": { + Description: "The value used to associate an on-premises Active Directory user account with their Azure AD user object", + Type: schema.TypeString, + Computed: true, + }, + + "onpremises_sam_account_name": { + Description: "The on-premise SAM account name of the user", + Type: schema.TypeString, + Computed: true, + }, + + "onpremises_user_principal_name": { + Description: "The on-premise user principal name of the user", + Type: schema.TypeString, + Computed: true, + }, + + "usage_location": { + Description: "The usage location of the user", + Type: schema.TypeString, + Computed: true, + }, + + "user_principal_name": { + Description: "The user principal name (UPN) of the user", + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func allUsersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client := meta.(*clients.Client).Users.UsersClient + + var users []msgraph.User + + results, _, err := client.List(ctx, odata.Query{}) + if err != nil { + return tf.ErrorDiagF(err, "Error retrieving users from API.") + } + if results == nil { + //TODO: What do when no results are returned? (Because there can be no results) + return tf.ErrorDiagF(errors.New("API returned nil result"), "Bad API Response") + //I do not believe this is correct - Threpio + } + for _, user := range *results { + users = append(users, user) + } + + // Define other objects that we will want to return + upns := make([]string, 0) + objectIds := make([]string, 0) + userList := make([]map[string]interface{}, 0) + + // Parse and check user data to ensure it is intact + for _, u := range users { + if u.ID == nil || u.UserPrincipalName == nil { + return tf.ErrorDiagF(errors.New("API returned user with nil object ID or userPrincipalName"), "Bad API Response") + } + + objectIds = append(objectIds, *u.ID) + upns = append(upns, *u.UserPrincipalName) + + user := make(map[string]interface{}) + user["account_enabled"] = u.AccountEnabled + user["display_name"] = u.DisplayName + user["mail"] = u.Mail + user["mail_nickname"] = u.MailNickname + user["object_id"] = u.ID + user["onpremises_immutable_id"] = u.OnPremisesImmutableId + user["onpremises_sam_account_name"] = u.OnPremisesSamAccountName + user["onpremises_user_principal_name"] = u.OnPremisesUserPrincipalName + user["usage_location"] = u.UsageLocation + user["user_principal_name"] = u.UserPrincipalName + userList = append(userList, user) + } + + // Generate a unique ID based on result + h := sha1.New() + if _, err := h.Write([]byte(strings.Join(upns, "/"))); err != nil { + return tf.ErrorDiagF(err, "Unable to compute hash for UPNs") + } + + d.SetId("users#" + base64.URLEncoding.EncodeToString(h.Sum(nil))) + tf.Set(d, "object_ids", objectIds) + tf.Set(d, "user_principal_names", upns) + tf.Set(d, "users", userList) + + return nil +} diff --git a/internal/services/users/registration.go b/internal/services/users/registration.go index 346e7b8f8..07465fea5 100644 --- a/internal/services/users/registration.go +++ b/internal/services/users/registration.go @@ -23,6 +23,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azuread_user": userDataSource(), "azuread_users": usersData(), + "azuread_all_users": allUsersData(), } } From ed55c3bf2f8979b13607a4d72a91968bfd7a10bd Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Tue, 10 Aug 2021 16:16:10 +0200 Subject: [PATCH 02/18] Updated datasource - Include Elem --- internal/services/users/all_users_datasource.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/services/users/all_users_datasource.go b/internal/services/users/all_users_datasource.go index 82488002c..f0e6ffa2e 100644 --- a/internal/services/users/all_users_datasource.go +++ b/internal/services/users/all_users_datasource.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" "github.com/manicminer/hamilton/odata" "strings" @@ -33,13 +34,20 @@ func allUsersData() *schema.Resource { Description: "The object IDs of the users", Type: schema.TypeList, Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateDiagFunc: validate.UUID, + }, }, "user_principal_names": { Description: "The user principal names (UPNs) of the users", Type: schema.TypeList, Computed: true, - + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateDiagFunc: validate.NoEmptyStrings, + }, }, "users": { From fef16690ede64b163e624ed974d54a9c11b7c531 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 09:23:56 +0200 Subject: [PATCH 03/18] Refactor to data_source - Added basic test --- ...datasource.go => all_users_data_source.go} | 0 .../users/all_users_data_source_test.go | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+) rename internal/services/users/{all_users_datasource.go => all_users_data_source.go} (100%) create mode 100644 internal/services/users/all_users_data_source_test.go diff --git a/internal/services/users/all_users_datasource.go b/internal/services/users/all_users_data_source.go similarity index 100% rename from internal/services/users/all_users_datasource.go rename to internal/services/users/all_users_data_source.go diff --git a/internal/services/users/all_users_data_source_test.go b/internal/services/users/all_users_data_source_test.go new file mode 100644 index 000000000..77ada9a54 --- /dev/null +++ b/internal/services/users/all_users_data_source_test.go @@ -0,0 +1,28 @@ +package users_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" + "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" + "testing" +) + +type AllUsersDataSource struct{} + +func TestAccAllUsersDataSource(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azuread_all_users", "test") + r := AllUsersDataSource{} + + data.DataSourceTest(t, []resource.TestStep{{ + Check: r.testCheckFunc(data), + }}) +} + +func (AllUsersDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("user_principal_names.#").Exists(), + check.That(data.ResourceName).Key("object_ids.#").Exists(), + check.That(data.ResourceName).Key("users.#").Exists(), + ) +} + From e628fbdcf4f84a3b201c7415df4e4885ecfe8133 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 09:26:14 +0200 Subject: [PATCH 04/18] Small fmt and refactor --- internal/services/users/all_users_data_source_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/users/all_users_data_source_test.go b/internal/services/users/all_users_data_source_test.go index 77ada9a54..4e2decdf3 100644 --- a/internal/services/users/all_users_data_source_test.go +++ b/internal/services/users/all_users_data_source_test.go @@ -1,10 +1,11 @@ package users_test import ( + "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" - "testing" ) type AllUsersDataSource struct{} @@ -25,4 +26,3 @@ func (AllUsersDataSource) testCheckFunc(data acceptance.TestData) resource.TestC check.That(data.ResourceName).Key("users.#").Exists(), ) } - From a84be504eb1c4c91cccddecf610d272e07b2b3d9 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 09:46:49 +0200 Subject: [PATCH 05/18] Forgot Docs Added Documentation for the datasource. --- docs/data-sources/all_users.md | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docs/data-sources/all_users.md diff --git a/docs/data-sources/all_users.md b/docs/data-sources/all_users.md new file mode 100644 index 000000000..04bd722e7 --- /dev/null +++ b/docs/data-sources/all_users.md @@ -0,0 +1,42 @@ +--- +subcategory: "Users" +--- + +# Data Source: azuread_all_users + +Gets object IDs, user principal names and user objects for all Azure Active Directory users. + +## Example Usage + +```terraform +data "azuread_all_users" "allUsers" {} +``` + +## Argument Reference + +This datasource does not support any Arguments or filtering in the datasource itself. + +If you wish to query for all users with a filter then look at the Data Source: azuread_users + +## Attributes Reference + +The following attributes are exported: + +* `object_ids` - The object IDs of the users. +* `user_principal_names` - The user principal names (UPNs) of the users. +* `users` - A list of users. Each `user` object provides the attributes documented below. + +___ + +`user` object exports the following: + +* `account_enabled` - Whether or not the account is enabled. +* `display_name` - The display name of the user. +* `mail_nickname` - The email alias of the user. +* `mail` - The primary email address of the user. +* `object_id` - The object ID of the user. +* `onpremises_immutable_id` - The value used to associate an on-premises Active Directory user account with their Azure AD user object. +* `onpremises_sam_account_name` - The on-premise SAM account name of the user. +* `onpremises_user_principal_name` - The on-premise user principal name of the user. +* `usage_location` - The usage location of the user. +* `user_principal_name` - The user principal name (UPN) of the user. From e3dd94c04477a54c8ef708543f3cd1bdc9a1850f Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 12:07:19 +0200 Subject: [PATCH 06/18] Further Fmt'ing - Apologies --- internal/services/users/all_users_data_source.go | 12 ++++++------ internal/services/users/registration.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/services/users/all_users_data_source.go b/internal/services/users/all_users_data_source.go index f0e6ffa2e..293d16d3b 100644 --- a/internal/services/users/all_users_data_source.go +++ b/internal/services/users/all_users_data_source.go @@ -31,9 +31,9 @@ func allUsersData() *schema.Resource { Schema: map[string]*schema.Schema{ "object_ids": { - Description: "The object IDs of the users", - Type: schema.TypeList, - Computed: true, + Description: "The object IDs of the users", + Type: schema.TypeList, + Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.UUID, @@ -41,9 +41,9 @@ func allUsersData() *schema.Resource { }, "user_principal_names": { - Description: "The user principal names (UPNs) of the users", - Type: schema.TypeList, - Computed: true, + Description: "The user principal names (UPNs) of the users", + Type: schema.TypeList, + Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.NoEmptyStrings, diff --git a/internal/services/users/registration.go b/internal/services/users/registration.go index 07465fea5..d356e1b5a 100644 --- a/internal/services/users/registration.go +++ b/internal/services/users/registration.go @@ -21,8 +21,8 @@ func (r Registration) WebsiteCategories() []string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azuread_user": userDataSource(), - "azuread_users": usersData(), + "azuread_user": userDataSource(), + "azuread_users": usersData(), "azuread_all_users": allUsersData(), } } From d89336c2cbb4b78a8853a59b4628d798a79cc45e Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 13:10:52 +0200 Subject: [PATCH 07/18] Delete Documentation --- docs/data-sources/all_users.md | 42 ---------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 docs/data-sources/all_users.md diff --git a/docs/data-sources/all_users.md b/docs/data-sources/all_users.md deleted file mode 100644 index 04bd722e7..000000000 --- a/docs/data-sources/all_users.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -subcategory: "Users" ---- - -# Data Source: azuread_all_users - -Gets object IDs, user principal names and user objects for all Azure Active Directory users. - -## Example Usage - -```terraform -data "azuread_all_users" "allUsers" {} -``` - -## Argument Reference - -This datasource does not support any Arguments or filtering in the datasource itself. - -If you wish to query for all users with a filter then look at the Data Source: azuread_users - -## Attributes Reference - -The following attributes are exported: - -* `object_ids` - The object IDs of the users. -* `user_principal_names` - The user principal names (UPNs) of the users. -* `users` - A list of users. Each `user` object provides the attributes documented below. - -___ - -`user` object exports the following: - -* `account_enabled` - Whether or not the account is enabled. -* `display_name` - The display name of the user. -* `mail_nickname` - The email alias of the user. -* `mail` - The primary email address of the user. -* `object_id` - The object ID of the user. -* `onpremises_immutable_id` - The value used to associate an on-premises Active Directory user account with their Azure AD user object. -* `onpremises_sam_account_name` - The on-premise SAM account name of the user. -* `onpremises_user_principal_name` - The on-premise user principal name of the user. -* `usage_location` - The usage location of the user. -* `user_principal_name` - The user principal name (UPN) of the user. From 8a6a411c473ec7e9b354789b57e795e307b7245f Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 13:40:02 +0200 Subject: [PATCH 08/18] added show_all_users - Added show_all_users flag - Implemented cross flag logic - fetched all users logic and append to list --- internal/services/users/users_data_source.go | 41 ++++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index 3908c235e..b3ae52042 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -38,7 +38,7 @@ func usersData() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.NoEmptyStrings, @@ -50,7 +50,7 @@ func usersData() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.UUID, @@ -62,13 +62,22 @@ func usersData() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.NoEmptyStrings, }, }, + "show_all_users": { + Description: "Fetch all users with no filter and return all that were found. The data source will still fail if no users are found", + Type: schema.TypeBool, + Optional: true, + Computed: false, + Default: false, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, + }, + "ignore_missing": { Description: "Ignore missing users and return users that were found. The data source will still fail if no users are found", Type: schema.TypeBool, @@ -154,7 +163,16 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter var users []msgraph.User var expectedCount int ignoreMissing := d.Get("ignore_missing").(bool) + showAllUsers := d.Get("show_all_users").(bool) + // validate that flags where set correctly for showAllUsers + ignoreMissing as well as + if ignoreMissing && showAllUsers { + return tf.ErrorDiagF(errors.New("Both the ignore_missing and show_all_users flags were set. Please only use ignore_missing with a filter applied"),"Contradicting flags set") + } else if !showAllUsers && len(d.Get("user_principal_names").([]interface{})) == 0 && len(d.Get("object_ids").([]interface{})) == 0 && len(d.Get("mail_nicknames").([]interface{})) == 0 { + return tf.ErrorDiagF(errors.New("show_all_users set to false but no filter specified. Please either set to true or define a filter with user_principle_names, object_ids or mail_nicknames."), "Flags/filter set incorrectly") + } // This error might be redundant with the ExactlyOneOf + + // Do the actual querying through a filter if upns, ok := d.Get("user_principal_names").([]interface{}); ok && len(upns) > 0 { expectedCount = len(upns) for _, v := range upns { @@ -226,9 +244,24 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter } } - if !ignoreMissing && len(users) != expectedCount { + // Check that the right number of users where returned - Does not work for showAllUsers + if !showAllUsers && !ignoreMissing && len(users) != expectedCount { return tf.ErrorDiagF(fmt.Errorf("Expected: %d, Actual: %d", expectedCount, len(users)), "Unexpected number of users returned") } + // Fetch all users + if showAllUsers { + results, _, err := client.List(ctx, odata.Query{}) + if err != nil { + return tf.ErrorDiagF(err, "Error retrieving users from API.") + } + if results == nil { + return tf.ErrorDiagF(errors.New("API returned nil result"), "Bad API Response") + } + for _, user := range *results { + users = append(users, user) + } + } + upns := make([]string, 0) objectIds := make([]string, 0) From dc9c78718558258d1a4b754bed6bf34f1bf59856 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 13:59:29 +0200 Subject: [PATCH 09/18] Added basic test. - Added basic test for showAllUsers flag - Started second test to check for error but couldn't get it to work. --- internal/services/users/users_data_source.go | 13 +++--- .../services/users/users_data_source_test.go | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index b3ae52042..4b53b46a8 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -70,11 +70,11 @@ func usersData() *schema.Resource { }, "show_all_users": { - Description: "Fetch all users with no filter and return all that were found. The data source will still fail if no users are found", - Type: schema.TypeBool, - Optional: true, - Computed: false, - Default: false, + Description: "Fetch all users with no filter and return all that were found. The data source will still fail if no users are found", + Type: schema.TypeBool, + Optional: true, + Computed: false, + Default: false, ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, }, @@ -167,7 +167,7 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter // validate that flags where set correctly for showAllUsers + ignoreMissing as well as if ignoreMissing && showAllUsers { - return tf.ErrorDiagF(errors.New("Both the ignore_missing and show_all_users flags were set. Please only use ignore_missing with a filter applied"),"Contradicting flags set") + return tf.ErrorDiagF(errors.New("Both the ignore_missing and show_all_users flags were set. Please only use ignore_missing with a filter applied"), "Contradicting flags set") } else if !showAllUsers && len(d.Get("user_principal_names").([]interface{})) == 0 && len(d.Get("object_ids").([]interface{})) == 0 && len(d.Get("mail_nicknames").([]interface{})) == 0 { return tf.ErrorDiagF(errors.New("show_all_users set to false but no filter specified. Please either set to true or define a filter with user_principle_names, object_ids or mail_nicknames."), "Flags/filter set incorrectly") } // This error might be redundant with the ExactlyOneOf @@ -262,7 +262,6 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter } } - upns := make([]string, 0) objectIds := make([]string, 0) mailNicknames := make([]string, 0) diff --git a/internal/services/users/users_data_source_test.go b/internal/services/users/users_data_source_test.go index f22e4ee78..796aded13 100644 --- a/internal/services/users/users_data_source_test.go +++ b/internal/services/users/users_data_source_test.go @@ -106,6 +106,31 @@ func TestAccUsersDataSource_noNames(t *testing.T) { }}) } +func TestAccUsersDataSource_showAll(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azuread_users", "test") + + data.DataSourceTest(t, []resource.TestStep{{ + Config: UsersDataSource{}.showAll(), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("user_principal_names.#").Exists(), + check.That(data.ResourceName).Key("object_ids.#").Exists(), + check.That(data.ResourceName).Key("mail_nicknames.#").Exists(), + check.That(data.ResourceName).Key("users.#").Exists(), + ), + }}) +} + +//func TestAccUsersDataSource_showAllAndIgnoreMissing(t *testing.T) { +// data := acceptance.BuildTestData(t, "data.azuread_users", "test") +// +// data.DataSourceTest(t, []resource.TestStep{{ +// Config: UsersDataSource{}.showAllAndIgnoreMissing(), +// Check: resource.ComposeTestCheckFunc( +// check, . +// ), +// }}) +//} + func (UsersDataSource) byUserPrincipalNames(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -192,3 +217,20 @@ data "azuread_users" "test" { } ` } + +func (UsersDataSource) showAll() string { + return ` +data "azuread_users" "test" { + show_all_users = true +} +` +} + +func (UsersDataSource) showAllAndIgnoreMissing() string { + return ` +data "azuread_users" "test" { + show_all_users = true + ignore_missing = true +} +` +} From c72419e0bf384094fcd1ca34884057736a8e5fee Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 14:00:15 +0200 Subject: [PATCH 10/18] Deleted old spare datasources --- .../services/users/all_users_data_source.go | 183 ------------------ .../users/all_users_data_source_test.go | 28 --- internal/services/users/registration.go | 5 +- 3 files changed, 2 insertions(+), 214 deletions(-) delete mode 100644 internal/services/users/all_users_data_source.go delete mode 100644 internal/services/users/all_users_data_source_test.go diff --git a/internal/services/users/all_users_data_source.go b/internal/services/users/all_users_data_source.go deleted file mode 100644 index 293d16d3b..000000000 --- a/internal/services/users/all_users_data_source.go +++ /dev/null @@ -1,183 +0,0 @@ -package users - -import ( - "context" - "crypto/sha1" - "encoding/base64" - "errors" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-azuread/internal/clients" - "github.com/hashicorp/terraform-provider-azuread/internal/tf" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" - "github.com/manicminer/hamilton/msgraph" - "github.com/manicminer/hamilton/odata" - "strings" - "time" -) - -func allUsersData() *schema.Resource { - return &schema.Resource{ - ReadContext: allUsersDataSourceRead, - - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), - }, - - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - - Schema: map[string]*schema.Schema{ - - "object_ids": { - Description: "The object IDs of the users", - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, - }, - }, - - "user_principal_names": { - Description: "The user principal names (UPNs) of the users", - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, - }, - }, - - "users": { - Description: "The list of users", - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "account_enabled": { - Description: "Whether or not the account is enabled", - Type: schema.TypeBool, - Computed: true, - }, - - "display_name": { - Description: "The display name of the user", - Type: schema.TypeString, - Computed: true, - }, - - "mail": { - Description: "The primary email address of the user", - Type: schema.TypeString, - Computed: true, - }, - - "mail_nickname": { - Description: "The email alias of the user", - Type: schema.TypeString, - Computed: true, - }, - - "object_id": { - Description: "The object ID of the user", - Type: schema.TypeString, - Computed: true, - }, - - "onpremises_immutable_id": { - Description: "The value used to associate an on-premises Active Directory user account with their Azure AD user object", - Type: schema.TypeString, - Computed: true, - }, - - "onpremises_sam_account_name": { - Description: "The on-premise SAM account name of the user", - Type: schema.TypeString, - Computed: true, - }, - - "onpremises_user_principal_name": { - Description: "The on-premise user principal name of the user", - Type: schema.TypeString, - Computed: true, - }, - - "usage_location": { - Description: "The usage location of the user", - Type: schema.TypeString, - Computed: true, - }, - - "user_principal_name": { - Description: "The user principal name (UPN) of the user", - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - }, - } -} - -func allUsersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*clients.Client).Users.UsersClient - - var users []msgraph.User - - results, _, err := client.List(ctx, odata.Query{}) - if err != nil { - return tf.ErrorDiagF(err, "Error retrieving users from API.") - } - if results == nil { - //TODO: What do when no results are returned? (Because there can be no results) - return tf.ErrorDiagF(errors.New("API returned nil result"), "Bad API Response") - //I do not believe this is correct - Threpio - } - for _, user := range *results { - users = append(users, user) - } - - // Define other objects that we will want to return - upns := make([]string, 0) - objectIds := make([]string, 0) - userList := make([]map[string]interface{}, 0) - - // Parse and check user data to ensure it is intact - for _, u := range users { - if u.ID == nil || u.UserPrincipalName == nil { - return tf.ErrorDiagF(errors.New("API returned user with nil object ID or userPrincipalName"), "Bad API Response") - } - - objectIds = append(objectIds, *u.ID) - upns = append(upns, *u.UserPrincipalName) - - user := make(map[string]interface{}) - user["account_enabled"] = u.AccountEnabled - user["display_name"] = u.DisplayName - user["mail"] = u.Mail - user["mail_nickname"] = u.MailNickname - user["object_id"] = u.ID - user["onpremises_immutable_id"] = u.OnPremisesImmutableId - user["onpremises_sam_account_name"] = u.OnPremisesSamAccountName - user["onpremises_user_principal_name"] = u.OnPremisesUserPrincipalName - user["usage_location"] = u.UsageLocation - user["user_principal_name"] = u.UserPrincipalName - userList = append(userList, user) - } - - // Generate a unique ID based on result - h := sha1.New() - if _, err := h.Write([]byte(strings.Join(upns, "/"))); err != nil { - return tf.ErrorDiagF(err, "Unable to compute hash for UPNs") - } - - d.SetId("users#" + base64.URLEncoding.EncodeToString(h.Sum(nil))) - tf.Set(d, "object_ids", objectIds) - tf.Set(d, "user_principal_names", upns) - tf.Set(d, "users", userList) - - return nil -} diff --git a/internal/services/users/all_users_data_source_test.go b/internal/services/users/all_users_data_source_test.go deleted file mode 100644 index 4e2decdf3..000000000 --- a/internal/services/users/all_users_data_source_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package users_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" - "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" -) - -type AllUsersDataSource struct{} - -func TestAccAllUsersDataSource(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azuread_all_users", "test") - r := AllUsersDataSource{} - - data.DataSourceTest(t, []resource.TestStep{{ - Check: r.testCheckFunc(data), - }}) -} - -func (AllUsersDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("user_principal_names.#").Exists(), - check.That(data.ResourceName).Key("object_ids.#").Exists(), - check.That(data.ResourceName).Key("users.#").Exists(), - ) -} diff --git a/internal/services/users/registration.go b/internal/services/users/registration.go index d356e1b5a..346e7b8f8 100644 --- a/internal/services/users/registration.go +++ b/internal/services/users/registration.go @@ -21,9 +21,8 @@ func (r Registration) WebsiteCategories() []string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azuread_user": userDataSource(), - "azuread_users": usersData(), - "azuread_all_users": allUsersData(), + "azuread_user": userDataSource(), + "azuread_users": usersData(), } } From 43966de22b4902a5bf1188d6fbb5365407851766 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 14:13:42 +0200 Subject: [PATCH 11/18] Updated Documentation --- docs/data-sources/users.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/data-sources/users.md b/docs/data-sources/users.md index 19de02191..28bf8961a 100644 --- a/docs/data-sources/users.md +++ b/docs/data-sources/users.md @@ -20,10 +20,13 @@ The following arguments are supported: * `mail_nicknames` - (Optional) The email aliases of the users. * `ignore_missing` - (Optional) Ignore missing users and return users that were found. The data source will still fail if no users are found. Defaults to false. +* `show_all_users` - (Optional) Return all users. The data source will still fail if no users are found. Defaults to false. * `object_ids` - (Optional) The object IDs of the users. * `user_principal_names` - (Optional) The user principal names (UPNs) of the users. -~> **NOTE:** One of `user_principal_names`, `object_ids` or `mail_nicknames` must be specified. These _may_ be specified as an empty list, in which case no results will be returned. +~> **NOTE:** One of `user_principal_names`, `object_ids`, `mail_nicknames`, `show_all_users` must be specified. These _may_ be specified as an empty list, in which case no results will be returned. + +~> **NOTE:** `show_all_users`is a boolean value and not a list. If `show_all_users`and `ignore_missing`are both set to true then an error will be thrown. ## Attributes Reference From 901cb0d849f2934781b7151ab4a94249c8a8f1f0 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Wed, 11 Aug 2021 14:40:01 +0200 Subject: [PATCH 12/18] Fix first lint issue - removing redundent --- .../services/users/users_data_source_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/services/users/users_data_source_test.go b/internal/services/users/users_data_source_test.go index 796aded13..26c78b0ff 100644 --- a/internal/services/users/users_data_source_test.go +++ b/internal/services/users/users_data_source_test.go @@ -226,11 +226,11 @@ data "azuread_users" "test" { ` } -func (UsersDataSource) showAllAndIgnoreMissing() string { - return ` -data "azuread_users" "test" { - show_all_users = true - ignore_missing = true -} -` -} +//func (UsersDataSource) showAllAndIgnoreMissing() string { +// return ` +//data "azuread_users" "test" { +// show_all_users = true +// ignore_missing = true +//} +//` +//} From 38c2faa233d4c7e44f125c75f4598e4b47f0c210 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Thu, 12 Aug 2021 14:33:13 +0200 Subject: [PATCH 13/18] Trying to fix the linting --- internal/services/users/users_data_source.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index 4b53b46a8..ab9cf75fd 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -73,7 +73,6 @@ func usersData() *schema.Resource { Description: "Fetch all users with no filter and return all that were found. The data source will still fail if no users are found", Type: schema.TypeBool, Optional: true, - Computed: false, Default: false, ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, }, From 37d0789fe49f5698ea615ef879b84cfa412350b0 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Thu, 12 Aug 2021 14:39:38 +0200 Subject: [PATCH 14/18] Fixing linting and syntax --- internal/services/users/users_data_source.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index ab9cf75fd..e2b79a02f 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -249,15 +249,15 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter } // Fetch all users if showAllUsers { - results, _, err := client.List(ctx, odata.Query{}) + result, _, err := client.List(ctx, odata.Query{}) if err != nil { return tf.ErrorDiagF(err, "Error retrieving users from API.") } - if results == nil { + if result == nil { return tf.ErrorDiagF(errors.New("API returned nil result"), "Bad API Response") } - for _, user := range *results { - users = append(users, user) + for x := range *result { + users = append(users, (*result)[x]) } } From 846986e2ea9f9d96bed7ef0b855fd2afb2177f86 Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Thu, 12 Aug 2021 17:15:59 +0200 Subject: [PATCH 15/18] Fixing lint? Last one? --- internal/services/users/user_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/users/user_data_source_test.go b/internal/services/users/user_data_source_test.go index e88a2ede2..558e80f42 100644 --- a/internal/services/users/user_data_source_test.go +++ b/internal/services/users/user_data_source_test.go @@ -80,7 +80,7 @@ func (UserDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheck check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestUser-%d-DisplayName", data.RandomInteger)), check.That(data.ResourceName).Key("given_name").HasValue(fmt.Sprintf("acctestUser-%d-GivenName", data.RandomInteger)), check.That(data.ResourceName).Key("job_title").HasValue(fmt.Sprintf("acctestUser-%d-Job", data.RandomInteger)), - //check.That(data.ResourceName).Key("mail").Exists(), // TODO only set for O365 domains + // check.That(data.ResourceName).Key("mail").Exists(), // TODO only set for O365 domains check.That(data.ResourceName).Key("mail_nickname").HasValue(fmt.Sprintf("acctestUser-%d-MailNickname", data.RandomInteger)), check.That(data.ResourceName).Key("mobile_phone").HasValue("(555) 555-5555"), check.That(data.ResourceName).Key("object_id").IsUuid(), From 5787cfab3240f39b65685008c8cfef677da5797e Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Thu, 12 Aug 2021 19:26:05 +0200 Subject: [PATCH 16/18] Removed redundent commented Test - Linting again?! --- internal/services/users/users_data_source_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/internal/services/users/users_data_source_test.go b/internal/services/users/users_data_source_test.go index 26c78b0ff..cfc6f68e2 100644 --- a/internal/services/users/users_data_source_test.go +++ b/internal/services/users/users_data_source_test.go @@ -225,12 +225,3 @@ data "azuread_users" "test" { } ` } - -//func (UsersDataSource) showAllAndIgnoreMissing() string { -// return ` -//data "azuread_users" "test" { -// show_all_users = true -// ignore_missing = true -//} -//` -//} From e21f52005906ee486b018c97ee9d2c999424d14a Mon Sep 17 00:00:00 2001 From: Threpio <Theomorris@hotmail.co.uk> Date: Mon, 16 Aug 2021 09:28:39 +0200 Subject: [PATCH 17/18] Fixing linting issues (thanks) --- internal/services/users/users_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/users/users_data_source_test.go b/internal/services/users/users_data_source_test.go index cfc6f68e2..d30458ccf 100644 --- a/internal/services/users/users_data_source_test.go +++ b/internal/services/users/users_data_source_test.go @@ -221,7 +221,7 @@ data "azuread_users" "test" { func (UsersDataSource) showAll() string { return ` data "azuread_users" "test" { - show_all_users = true + show_all_users = true } ` } From dd1227653990508cc3d2c0cdd5437df8392beb41 Mon Sep 17 00:00:00 2001 From: Tom Bamford <tom@bamford.io> Date: Thu, 2 Sep 2021 10:32:36 +0100 Subject: [PATCH 18/18] data.azuread_users: use ConflictsWith for ignore_missing, remove apply-time validation, rename `show_all_user` to `return_all_users` --- docs/data-sources/users.md | 8 +-- internal/services/users/users_data_source.go | 68 ++++++++----------- .../services/users/users_data_source_test.go | 19 ++---- 3 files changed, 36 insertions(+), 59 deletions(-) diff --git a/docs/data-sources/users.md b/docs/data-sources/users.md index 0670bf5cd..9bbd0f22d 100644 --- a/docs/data-sources/users.md +++ b/docs/data-sources/users.md @@ -26,15 +26,13 @@ data "azuread_users" "users" { The following arguments are supported: -* `mail_nicknames` - (Optional) The email aliases of the users. * `ignore_missing` - (Optional) Ignore missing users and return users that were found. The data source will still fail if no users are found. Defaults to false. -* `show_all_users` - (Optional) Return all users. The data source will still fail if no users are found. Defaults to false. +* `mail_nicknames` - (Optional) The email aliases of the users. * `object_ids` - (Optional) The object IDs of the users. +* `return_all_users` - (Optional) When `true`, the data source will return all users. Cannot be used with `ignore_missing`. Defaults to false. * `user_principal_names` - (Optional) The user principal names (UPNs) of the users. -One of `user_principal_names`, `object_ids`, `mail_nicknames`, `show_all_users` must be specified. These _may_ be specified as an empty list, in which case no results will be returned. - -`show_all_users`is a boolean value and not a list. If `show_all_users`and `ignore_missing`are both set to true then an error will be thrown. +~> Either `return_all_users`, or one of `user_principal_names`, `object_ids` or `mail_nicknames` must be specified. These _may_ be specified as an empty list, in which case no results will be returned. ## Attributes Reference diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index 54ac7473a..d1e0f40d6 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -34,7 +34,7 @@ func usersData() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "return_all_users"}, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.NoEmptyStrings, @@ -46,7 +46,7 @@ func usersData() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "return_all_users"}, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.UUID, @@ -58,26 +58,28 @@ func usersData() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "return_all_users"}, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: validate.NoEmptyStrings, }, }, - "show_all_users": { - Description: "Fetch all users with no filter and return all that were found. The data source will still fail if no users are found", - Type: schema.TypeBool, - Optional: true, - Default: false, - ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "show_all_users"}, + "ignore_missing": { + Description: "Ignore missing users and return users that were found. The data source will still fail if no users are found", + Type: schema.TypeBool, + Optional: true, + Default: false, + ConflictsWith: []string{"return_all_users"}, }, - "ignore_missing": { - Description: "Ignore missing users and return users that were found. The data source will still fail if no users are found", - Type: schema.TypeBool, - Optional: true, - Default: false, + "return_all_users": { + Description: "Fetch all users with no filter and return all that were found. The data source will still fail if no users are found.", + Type: schema.TypeBool, + Optional: true, + Default: false, + ConflictsWith: []string{"ignore_missing"}, + ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "return_all_users"}, }, "users": { @@ -159,17 +161,18 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter var users []msgraph.User var expectedCount int ignoreMissing := d.Get("ignore_missing").(bool) - showAllUsers := d.Get("show_all_users").(bool) + returnAllUsers := d.Get("return_all_users").(bool) - // validate that flags where set correctly for showAllUsers + ignoreMissing as well as - if ignoreMissing && showAllUsers { - return tf.ErrorDiagF(errors.New("Both the ignore_missing and show_all_users flags were set. Please only use ignore_missing with a filter applied"), "Contradicting flags set") - } else if !showAllUsers && len(d.Get("user_principal_names").([]interface{})) == 0 && len(d.Get("object_ids").([]interface{})) == 0 && len(d.Get("mail_nicknames").([]interface{})) == 0 { - return tf.ErrorDiagF(errors.New("show_all_users set to false but no filter specified. Please either set to true or define a filter with user_principle_names, object_ids or mail_nicknames."), "Flags/filter set incorrectly") - } // This error might be redundant with the ExactlyOneOf - - // Do the actual querying through a filter - if upns, ok := d.Get("user_principal_names").([]interface{}); ok && len(upns) > 0 { + if returnAllUsers { + result, _, err := client.List(ctx, odata.Query{}) + if err != nil { + return tf.ErrorDiagF(err, "Could not retrieve users") + } + if result == nil { + return tf.ErrorDiagF(errors.New("API returned nil result"), "Bad API Response") + } + users = append(users, *result...) + } else if upns, ok := d.Get("user_principal_names").([]interface{}); ok && len(upns) > 0 { expectedCount = len(upns) for _, v := range upns { query := odata.Query{ @@ -240,23 +243,10 @@ func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter } } - // Check that the right number of users where returned - Does not work for showAllUsers - if !showAllUsers && !ignoreMissing && len(users) != expectedCount { + // Check that the right number of users were returned + if !returnAllUsers && !ignoreMissing && len(users) != expectedCount { return tf.ErrorDiagF(fmt.Errorf("Expected: %d, Actual: %d", expectedCount, len(users)), "Unexpected number of users returned") } - // Fetch all users - if showAllUsers { - result, _, err := client.List(ctx, odata.Query{}) - if err != nil { - return tf.ErrorDiagF(err, "Error retrieving users from API.") - } - if result == nil { - return tf.ErrorDiagF(errors.New("API returned nil result"), "Bad API Response") - } - for x := range *result { - users = append(users, (*result)[x]) - } - } upns := make([]string, 0) objectIds := make([]string, 0) diff --git a/internal/services/users/users_data_source_test.go b/internal/services/users/users_data_source_test.go index d30458ccf..34ffdac80 100644 --- a/internal/services/users/users_data_source_test.go +++ b/internal/services/users/users_data_source_test.go @@ -106,11 +106,11 @@ func TestAccUsersDataSource_noNames(t *testing.T) { }}) } -func TestAccUsersDataSource_showAll(t *testing.T) { +func TestAccUsersDataSource_returnAll(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") data.DataSourceTest(t, []resource.TestStep{{ - Config: UsersDataSource{}.showAll(), + Config: UsersDataSource{}.returnAll(), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), @@ -120,17 +120,6 @@ func TestAccUsersDataSource_showAll(t *testing.T) { }}) } -//func TestAccUsersDataSource_showAllAndIgnoreMissing(t *testing.T) { -// data := acceptance.BuildTestData(t, "data.azuread_users", "test") -// -// data.DataSourceTest(t, []resource.TestStep{{ -// Config: UsersDataSource{}.showAllAndIgnoreMissing(), -// Check: resource.ComposeTestCheckFunc( -// check, . -// ), -// }}) -//} - func (UsersDataSource) byUserPrincipalNames(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -218,10 +207,10 @@ data "azuread_users" "test" { ` } -func (UsersDataSource) showAll() string { +func (UsersDataSource) returnAll() string { return ` data "azuread_users" "test" { - show_all_users = true + return_all_users = true } ` }