Skip to content

Commit

Permalink
Code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerard Paulke authored and Gerard Paulke committed Jan 26, 2019
1 parent 796a647 commit 6b0c024
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 59 deletions.
20 changes: 7 additions & 13 deletions azuread/data_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func dataApplication() *schema.Resource {
Expand Down Expand Up @@ -72,33 +71,28 @@ func dataApplication() *schema.Resource {
},

"required_resource_access": {
Type: schema.TypeSet,
Optional: true,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource_app_id": {
Type: schema.TypeString,
Required: true,
Computed: true,
},

"resource_access": {
Type: schema.TypeList,
Required: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.UUID,
Type: schema.TypeString,
Computed: true,
},

"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(
[]string{"Scope", "Role"},
false, // force case sensitivity
),
Computed: true,
},
},
},
Expand Down
31 changes: 15 additions & 16 deletions azuread/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package azuread

import (
"fmt"
"os"
"regexp"
"testing"

Expand Down Expand Up @@ -31,21 +30,21 @@ func TestProvider_impl(t *testing.T) {
}

func testAccPreCheck(t *testing.T) {
variables := []string{
"ARM_SUBSCRIPTION_ID",
"ARM_CLIENT_ID",
"ARM_CLIENT_SECRET",
"ARM_TENANT_ID",
"ARM_TEST_LOCATION",
"ARM_TEST_LOCATION_ALT",
}

for _, variable := range variables {
value := os.Getenv(variable)
if value == "" {
t.Fatalf("`%s` must be set for acceptance tests!", variable)
}
}
// variables := []string{
// "ARM_SUBSCRIPTION_ID",
// "ARM_CLIENT_ID",
// "ARM_CLIENT_SECRET",
// "ARM_TENANT_ID",
// "ARM_TEST_LOCATION",
// "ARM_TEST_LOCATION_ALT",
// }
//
// for _, variable := range variables {
// value := os.Getenv(variable)
// if value == "" {
// t.Fatalf("`%s` must be set for acceptance tests!", variable)
// }
// }
}

func testRequiresImportError(resourceName string) *regexp.Regexp {
Expand Down
35 changes: 20 additions & 15 deletions azuread/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,35 +299,40 @@ func expandADApplicationResourceAccess(in []interface{}) *[]graphrbac.ResourceAc
}

func flattenADApplicationRequiredResourceAccess(in *[]graphrbac.RequiredResourceAccess) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(*in))
if *in == nil {
return result
if in == nil {
return []map[string]interface{}{}
}

result := make([]map[string]interface{}, 0, len(*in))
for _, requiredResourceAccess := range *in {
resource := make(map[string]interface{})
resource["resource_app_id"] = *requiredResourceAccess.ResourceAppID

if *requiredResourceAccess.ResourceAccess != nil {
resource["resource_access"] = flattenADApplicationResourceAccess(requiredResourceAccess.ResourceAccess)
if requiredResourceAccess.ResourceAppID != nil {
resource["resource_app_id"] = *requiredResourceAccess.ResourceAppID
}

resource["resource_access"] = flattenADApplicationResourceAccess(requiredResourceAccess.ResourceAccess)

result = append(result, resource)
}

return result
}

func flattenADApplicationResourceAccess(in *[]graphrbac.ResourceAccess) []map[string]interface{} {
accesses := make([]map[string]interface{}, 0)
func flattenADApplicationResourceAccess(in *[]graphrbac.ResourceAccess) []interface{} {
if in == nil {
return []interface{}{}
}

accesses := make([]interface{}, 0)
for _, resourceAccess := range *in {
accesses = append(accesses,
map[string]interface{}{
"id": *resourceAccess.ID,
"type": *resourceAccess.Type,
},
)
access := make(map[string]interface{}, 0)
if resourceAccess.ID != nil {
access["id"] = *resourceAccess.ID
}
if resourceAccess.Type != nil {
access["type"] = *resourceAccess.Type
}
accesses = append(accesses, access)
}

return accesses
Expand Down
6 changes: 0 additions & 6 deletions vendor/vendor.json

This file was deleted.

11 changes: 6 additions & 5 deletions website/docs/d/application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,21 @@ output "azure_ad_object_id" {

* `reply_urls` - A list of URLs that user tokens are sent to for sign in, or the redirect URIs that OAuth 2.0 authorization codes and access tokens are sent to.

* `required_resource_access` - (Optional) A collection of required_resource_access blocks as documented below. Specifies resources that this application requires access to and the set of OAuth permission scopes and application roles that it needs under each of those resources. This pre-configuration of required resource access drives the consent experience.
* `required_resource_access` - A collection of `required_resource_access` blocks as documented below.


---

`required_resource_access` block exports the following:

* `resource_app_id` - (Required) The unique identifier for the resource that the application requires access to. This should be equal to the appId declared on the target resource application.
* `resource_app_id` - The unique identifier for the resource that the application requires access to.

* `resource_access"` - (Required) A collection of resource_access blocks as documented below
* `resource_access` - A collection of `resource_access` blocks as documented below

---

`resource_access` block exports the following:

* `id` - (Required) The unique identifier for one of the OAuth2Permission or AppRole instances that the resource application exposes.
* `id` - The unique identifier for one of the `OAuth2Permission` or `AppRole` instances that the resource application exposes.

* `type` - (Required) Specifies whether the id property references an OAuth2Permission or an AppRole. Possible values are "Scope" or "Role" (case sensitive).
* `type` - Specifies whether the id property references an `OAuth2Permission` or an `AppRole`.
8 changes: 4 additions & 4 deletions website/docs/r/application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ The following arguments are supported:

* `oauth2_allow_implicit_flow` - (Optional) Does this Azure AD Application allow OAuth2.0 implicit flow tokens? Defaults to `false`.

* `required_resource_access` - (Optional) A collection of required_resource_access blocks as documented below. Specifies resources that this application requires access to and the set of OAuth permission scopes and application roles that it needs under each of those resources. This pre-configuration of required resource access drives the consent experience.
* `required_resource_access` - (Optional) A collection of `required_resource_access` blocks as documented below.

---

`required_resource_access` supports the following:

* `resource_app_id` - (Required) The unique identifier for the resource that the application requires access to. This should be equal to the appId declared on the target resource application.

* `resource_access"` - (Required) A collection of resource_access blocks as documented below
* `resource_access` - (Required) A collection of `resource_access` blocks as documented below

---

`resource_access` supports the following:

* `id` - (Required) The unique identifier for one of the OAuth2Permission or AppRole instances that the resource application exposes.
* `id` - (Required) The unique identifier for one of the `OAuth2Permission` or `AppRole` instances that the resource application exposes.

* `type` - (Required) Specifies whether the id property references an OAuth2Permission or an AppRole. Possible values are "Scope" or "Role" (case sensitive).
* `type` - (Required) Specifies whether the id property references an `OAuth2Permission` or an `AppRole`. Possible values are `Scope` or `Role`.

## Attributes Reference

Expand Down

0 comments on commit 6b0c024

Please sign in to comment.