Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add explicit object_id property to resources #99

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azuread/data_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func testAccAzureADApplicationDataSource_objectId(id string) string {
%s

data "azuread_application" "test" {
object_id = "${azuread_application.test.id}"
object_id = "${azuread_application.test.object_id}"
}
`, template)
}
Expand All @@ -116,7 +116,7 @@ func testAccAzureADApplicationDataSource_objectIdComplete(id string) string {
%s

data "azuread_application" "test" {
object_id = "${azuread_application.test.id}"
object_id = "${azuread_application.test.object_id}"
}
`, template)
}
Expand Down
2 changes: 1 addition & 1 deletion azuread/data_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func testAccDataSourceAzureADGroup_objectId(id string) string {
%s

data "azuread_group" "test" {
object_id = "${azuread_group.test.id}"
object_id = "${azuread_group.test.object_id}"
}
`, testAccAzureADGroup(id))
}
2 changes: 1 addition & 1 deletion azuread/data_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func testAccAzureADServicePrincipalDataSource_byObjectId(id string) string {
%s

data "azuread_service_principal" "test" {
object_id = "${azuread_service_principal.test.id}"
object_id = "${azuread_service_principal.test.object_id}"
}
`, template)
}
2 changes: 1 addition & 1 deletion azuread/data_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func testAccAzureADUserDataSource_byObjectId(id, password string) string {
%s

data "azuread_user" "test" {
object_id = "${azuread_user.test.id}"
object_id = "${azuread_user.test.object_id}"
}
`, testAccADUser_basic(id, password))
}
6 changes: 6 additions & 0 deletions azuread/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func resourceApplication() *schema.Resource {
},
},
},

"object_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -346,6 +351,7 @@ func resourceApplicationRead(d *schema.ResourceData, meta interface{}) error {
d.Set("homepage", resp.Homepage)
d.Set("available_to_other_tenants", resp.AvailableToOtherTenants)
d.Set("oauth2_allow_implicit_flow", resp.Oauth2AllowImplicitFlow)
d.Set("object_id", resp.ObjectID)

if groupMembershipClaims, ok := resp.AdditionalProperties["groupMembershipClaims"]; ok {
d.Set("group_membership_claims", groupMembershipClaims)
Expand Down
2 changes: 2 additions & 0 deletions azuread/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccAzureADApplication_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "oauth2_permissions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "oauth2_permissions.0.admin_consent_description", fmt.Sprintf("Access %s", fmt.Sprintf("acctest%s", id))),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
),
},
{
Expand Down Expand Up @@ -62,6 +63,7 @@ func TestAccAzureADApplication_complete(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "group_membership_claims", "All"),
resource.TestCheckResourceAttr(resourceName, "required_resource_access.#", "2"),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
),
},
{
Expand Down
12 changes: 9 additions & 3 deletions azuread/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func resourceGroup() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"object_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -42,9 +47,9 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {

properties := graphrbac.GroupCreateParameters{
DisplayName: &name,
MailEnabled: p.Bool(false), //we're defaulting to false, as the API currently only supports the creation of non-mail enabled security groups.
MailNickname: p.String(uuid.New().String()), //this matches the portal behavior
SecurityEnabled: p.Bool(true), //we're defaulting to true, as the API currently only supports the creation of non-mail enabled security groups.
MailEnabled: p.Bool(false), // we're defaulting to false, as the API currently only supports the creation of non-mail enabled security groups.
MailNickname: p.String(uuid.New().String()), // this matches the portal behavior
SecurityEnabled: p.Bool(true), // we're defaulting to true, as the API currently only supports the creation of non-mail enabled security groups.
}

group, err := client.Create(ctx, properties)
Expand Down Expand Up @@ -82,6 +87,7 @@ func resourceGroupRead(d *schema.ResourceData, meta interface{}) error {
}

d.Set("name", resp.DisplayName)
d.Set("object_id", resp.ObjectID)
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions azuread/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccAzureADGroup_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureADGroupExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
),
},
{
Expand Down Expand Up @@ -57,6 +58,7 @@ func TestAccAzureADGroup_complete(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureADGroupExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
),
},
{
Expand Down
6 changes: 6 additions & 0 deletions azuread/resource_service_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func resourceServicePrincipal() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"object_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -107,6 +112,7 @@ func resourceServicePrincipalRead(d *schema.ResourceData, meta interface{}) erro

d.Set("application_id", app.AppID)
d.Set("display_name", app.DisplayName)
d.Set("object_id", app.ObjectID)

// tags doesn't exist as a property, so extract it
if iTags, ok := app.AdditionalProperties["tags"]; ok {
Expand Down
2 changes: 2 additions & 0 deletions azuread/resource_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestAccAzureADServicePrincipal_basic(t *testing.T) {
testCheckADServicePrincipalExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "display_name"),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
),
},
{
Expand All @@ -51,6 +52,7 @@ func TestAccAzureADServicePrincipal_complete(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckADServicePrincipalExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.#", "3"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
),
},
{
Expand Down
6 changes: 6 additions & 0 deletions azuread/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func resourceUser() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"object_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -139,6 +144,7 @@ func resourceUserRead(d *schema.ResourceData, meta interface{}) error {
d.Set("mail", user.Mail)
d.Set("mail_nickname", user.MailNickname)
d.Set("account_enabled", user.AccountEnabled)
d.Set("object_id", user.ObjectID)
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions azuread/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestAccAzureADUser_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckADUserExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "user_principal_name"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "mail_nickname", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "account_enabled", "true"),
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestAccAzureADUser_complete(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckADUserExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "user_principal_name"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("acctestupdate%s", id)),
resource.TestCheckResourceAttr(resourceName, "mail_nickname", fmt.Sprintf("acctestupdate%s", id)),
resource.TestCheckResourceAttr(resourceName, "account_enabled", "false"),
Expand Down Expand Up @@ -93,6 +95,7 @@ func TestAccAzureADUser_update(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckADUserExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "user_principal_name"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "mail_nickname", fmt.Sprintf("acctest%s", id)),
resource.TestCheckResourceAttr(resourceName, "account_enabled", "true"),
Expand All @@ -103,6 +106,7 @@ func TestAccAzureADUser_update(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckADUserExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "user_principal_name"),
resource.TestCheckResourceAttrSet(resourceName, "object_id"),
resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("acctestupdate%s", id)),
resource.TestCheckResourceAttr(resourceName, "mail_nickname", fmt.Sprintf("acctestupdate%s", id)),
resource.TestCheckResourceAttr(resourceName, "account_enabled", "false"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ The following arguments are supported:
The following attributes are exported:

* `id` - The Object ID of the Azure AD Group.

2 changes: 2 additions & 0 deletions website/docs/r/application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ The following attributes are exported:

* `application_id` - The Application ID.

* `object_id` - The Application's Object ID.

* `oauth2_permissions` - A collection of OAuth 2.0 permission scopes that the web API (resource) app exposes to client apps. Each permission is covered by a `oauth2_permission` block as documented below.

---
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/service_principal.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ The following attributes are exported:

* `application_id` - The Application ID (appId) for the Service Principal.

* `object_id` - The Service Principal's Object ID.

* `display_name` - The Display Name of the Azure Active Directory Application associated with this Service Principal.

## Import
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ The following arguments are supported:

The following attributes are exported:

* `object_id` - The Object ID of the Azure AD User.
* `id` - The Object ID of the Azure AD User.
* `mail` - The primary email address of the Azure AD User.