Skip to content

Commit

Permalink
Rename pre_authorized_application to application_pre_authorized
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Jul 1, 2021
1 parent 8c94fe9 commit b99c667
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subcategory: "Applications"
---

# Resource: azuread_pre_authorized_application
# Resource: azuread_application_pre_authorized

Manages client applications that are pre-authorized with the specified permissions to access an application's APIs without requiring user consent.

Expand Down Expand Up @@ -39,7 +39,7 @@ resource "azuread_application" "authorizer" {
}
}
resource "azuread_pre_authorized_application" "example" {
resource "azuread_application_pre_authorized" "example" {
application_object_id = azuread_application.authorizer.object_id
authorized_app_id = azuread_application.authorized.application_id
permission_ids = ["ced9c4c3-c273-4f0f-ac71-a20377b90f9c", "2d5e07ca-664d-4d9b-ad61-ec07fd215213"]
Expand All @@ -65,7 +65,7 @@ In addition to all arguments above, the following attributes are exported:
Pre-authorized applications can be imported using the object ID of the authorizing application and the application ID of the application being authorized, e.g.

```shell
terraform import azuread_pre_authorized_application.example 00000000-0000-0000-0000-000000000000/preAuthorizedApplication/11111111-1111-1111-1111-111111111111
terraform import azuread_application_pre_authorized.example 00000000-0000-0000-0000-000000000000/preAuthorizedApplication/11111111-1111-1111-1111-111111111111
```

-> **NOTE:** This ID format is unique to Terraform and is composed of the authorizing application's object ID, the string "preAuthorizedApplication" and the authorized application's application ID (client ID) in the format `{ObjectId}/preAuthorizedApplication/{ApplicationId}`.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"github.com/hashicorp/terraform-provider-azuread/internal/validate"
)

func preAuthorizedApplicationResource() *schema.Resource {
func applicationPreAuthorizedResource() *schema.Resource {
return &schema.Resource{
CreateContext: preAuthorizedApplicationResourceCreate,
ReadContext: preAuthorizedApplicationResourceRead,
UpdateContext: preAuthorizedApplicationResourceUpdate,
DeleteContext: preAuthorizedApplicationResourceDelete,
CreateContext: applicationPreAuthorizedResourceCreate,
ReadContext: applicationPreAuthorizedResourceRead,
UpdateContext: applicationPreAuthorizedResourceUpdate,
DeleteContext: applicationPreAuthorizedResourceDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Expand All @@ -35,7 +35,7 @@ func preAuthorizedApplicationResource() *schema.Resource {
},

Importer: tf.ValidateResourceIDPriorToImport(func(id string) error {
_, err := parse.PreAuthorizedApplicationID(id)
_, err := parse.ApplicationPreAuthorizedID(id)
return err
}),

Expand Down Expand Up @@ -69,9 +69,9 @@ func preAuthorizedApplicationResource() *schema.Resource {
}
}

func preAuthorizedApplicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func applicationPreAuthorizedResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*clients.Client).Applications.ApplicationsClient
id := parse.NewPreAuthorizedApplicationID(d.Get("application_object_id").(string), d.Get("authorized_app_id").(string))
id := parse.NewApplicationPreAuthorizedID(d.Get("application_object_id").(string), d.Get("authorized_app_id").(string))

tf.LockByName(applicationResourceName, id.ObjectId)
defer tf.UnlockByName(applicationResourceName, id.ObjectId)
Expand All @@ -91,7 +91,7 @@ func preAuthorizedApplicationResourceCreate(ctx context.Context, d *schema.Resou
if app.Api != nil && app.Api.PreAuthorizedApplications != nil {
for _, a := range *app.Api.PreAuthorizedApplications {
if a.AppId != nil && strings.EqualFold(*a.AppId, id.AppId) {
return tf.ImportAsExistsDiag("azuread_pre_authorized_application", id.String())
return tf.ImportAsExistsDiag("azuread_application_pre_authorized", id.String())
}
newPreAuthorizedApps = append(newPreAuthorizedApps, a)
}
Expand All @@ -115,12 +115,12 @@ func preAuthorizedApplicationResourceCreate(ctx context.Context, d *schema.Resou

d.SetId(id.String())

return preAuthorizedApplicationResourceRead(ctx, d, meta)
return applicationPreAuthorizedResourceRead(ctx, d, meta)
}

func preAuthorizedApplicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func applicationPreAuthorizedResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*clients.Client).Applications.ApplicationsClient
id, err := parse.PreAuthorizedApplicationID(d.Id())
id, err := parse.ApplicationPreAuthorizedID(d.Id())
if err != nil {
return tf.ErrorDiagPathF(err, "id", "Parsing pre-authorized application ID %q", d.Id())
}
Expand Down Expand Up @@ -166,12 +166,12 @@ func preAuthorizedApplicationResourceUpdate(ctx context.Context, d *schema.Resou
return tf.ErrorDiagF(err, "Updating pre-authorized application %q for application with object ID %q", id.AppId, id.ObjectId)
}

return preAuthorizedApplicationResourceRead(ctx, d, meta)
return applicationPreAuthorizedResourceRead(ctx, d, meta)
}

func preAuthorizedApplicationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func applicationPreAuthorizedResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*clients.Client).Applications.ApplicationsClient
id, err := parse.PreAuthorizedApplicationID(d.Id())
id, err := parse.ApplicationPreAuthorizedID(d.Id())
if err != nil {
return tf.ErrorDiagPathF(err, "id", "Parsing pre-authorized application ID %q", d.Id())
}
Expand Down Expand Up @@ -212,9 +212,9 @@ func preAuthorizedApplicationResourceRead(ctx context.Context, d *schema.Resourc
return nil
}

func preAuthorizedApplicationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func applicationPreAuthorizedResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*clients.Client).Applications.ApplicationsClient
id, err := parse.PreAuthorizedApplicationID(d.Id())
id, err := parse.ApplicationPreAuthorizedID(d.Id())
if err != nil {
return tf.ErrorDiagPathF(err, "id", "Parsing pre-authorized application ID %q", d.Id())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/hashicorp/terraform-provider-azuread/internal/utils"
)

type PreAuthorizedApplicationResource struct{}
type ApplicationPreAuthorizedResource struct{}

func TestAccPreAuthorizedApplication_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_pre_authorized_application", "test")
r := PreAuthorizedApplicationResource{}
func TestAccApplicationPreAuthorized_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_application_pre_authorized", "test")
r := ApplicationPreAuthorizedResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Expand All @@ -36,9 +36,9 @@ func TestAccPreAuthorizedApplication_basic(t *testing.T) {
})
}

func TestAccPreAuthorizedApplication_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_pre_authorized_application", "test")
r := PreAuthorizedApplicationResource{}
func TestAccApplicationPreAuthorized_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_application_pre_authorized", "test")
r := ApplicationPreAuthorizedResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Expand All @@ -51,11 +51,11 @@ func TestAccPreAuthorizedApplication_requiresImport(t *testing.T) {
})
}

func (PreAuthorizedApplicationResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
func (ApplicationPreAuthorizedResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
client := clients.Applications.ApplicationsClient
client.BaseClient.DisableRetries = true

id, err := parse.PreAuthorizedApplicationID(state.ID)
id, err := parse.ApplicationPreAuthorizedID(state.ID)
if err != nil {
return nil, fmt.Errorf("parsing Pre-Authorized Application ID: %v", err)
}
Expand All @@ -79,7 +79,7 @@ func (PreAuthorizedApplicationResource) Exists(ctx context.Context, clients *cli
return nil, fmt.Errorf("Pre-Authorized Application %q was not found for Application %q", id.AppId, id.ObjectId)
}

func (PreAuthorizedApplicationResource) basic(data acceptance.TestData) string {
func (ApplicationPreAuthorizedResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azuread_application" "authorized" {
display_name = "acctestApp-authorized-%[1]d"
Expand Down Expand Up @@ -111,21 +111,21 @@ resource "azuread_application" "authorizer" {
}
}
resource "azuread_pre_authorized_application" "test" {
resource "azuread_application_pre_authorized" "test" {
application_object_id = azuread_application.authorizer.object_id
authorized_app_id = azuread_application.authorized.application_id
permission_ids = ["%[2]s", "%[3]s"]
}
`, data.RandomInteger, data.UUID(), data.UUID())
}

func (r PreAuthorizedApplicationResource) requiresImport(data acceptance.TestData) string {
func (r ApplicationPreAuthorizedResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
resource "azuread_pre_authorized_application" "import" {
application_object_id = azuread_pre_authorized_application.test.application_object_id
authorized_app_id = azuread_pre_authorized_application.test.authorized_app_id
resource "azuread_application_pre_authorized" "import" {
application_object_id = azuread_application_pre_authorized.test.application_object_id
authorized_app_id = azuread_application_pre_authorized.test.authorized_app_id
permission_ids = ["%[2]s"]
}
`, r.basic(data), data.UUID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ package parse

import "fmt"

type PreAuthorizedApplicationId struct {
type ApplicationPreAuthorizedId struct {
ObjectId string
AppId string
}

func NewPreAuthorizedApplicationID(objectId, appId string) PreAuthorizedApplicationId {
return PreAuthorizedApplicationId{
func NewApplicationPreAuthorizedID(objectId, appId string) ApplicationPreAuthorizedId {
return ApplicationPreAuthorizedId{
ObjectId: objectId,
AppId: appId,
}
}

func (id PreAuthorizedApplicationId) String() string {
func (id ApplicationPreAuthorizedId) String() string {
return id.ObjectId + "/preAuthorizedApplication/" + id.AppId
}

func PreAuthorizedApplicationID(idString string) (*PreAuthorizedApplicationId, error) {
func ApplicationPreAuthorizedID(idString string) (*ApplicationPreAuthorizedId, error) {
id, err := ObjectSubResourceID(idString, "preAuthorizedApplication")
if err != nil {
return nil, fmt.Errorf("unable to parse Pre-Authorized Application ID: %v", err)
}

return &PreAuthorizedApplicationId{
return &ApplicationPreAuthorizedId{
ObjectId: id.objectId,
AppId: id.subId,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/services/applications/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func (r Registration) SupportedResources() map[string]*schema.Resource {
"azuread_application": applicationResource(),
"azuread_application_certificate": applicationCertificateResource(),
"azuread_application_password": applicationPasswordResource(),
"azuread_pre_authorized_application": preAuthorizedApplicationResource(),
"azuread_application_pre_authorized": applicationPreAuthorizedResource(),
}
}

0 comments on commit b99c667

Please sign in to comment.