diff --git a/docs/resources/pre_authorized_application.md b/docs/resources/application_pre_authorized.md similarity index 94% rename from docs/resources/pre_authorized_application.md rename to docs/resources/application_pre_authorized.md index 1330f2b3ee..fac746dc32 100644 --- a/docs/resources/pre_authorized_application.md +++ b/docs/resources/application_pre_authorized.md @@ -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. @@ -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"] @@ -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}`. diff --git a/internal/services/applications/pre_authorized_application_resource.go b/internal/services/applications/application_pre_authorized_resource.go similarity index 89% rename from internal/services/applications/pre_authorized_application_resource.go rename to internal/services/applications/application_pre_authorized_resource.go index 87a6aac4bd..e8e4b235d5 100644 --- a/internal/services/applications/pre_authorized_application_resource.go +++ b/internal/services/applications/application_pre_authorized_resource.go @@ -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), @@ -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 }), @@ -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) @@ -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) } @@ -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()) } @@ -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()) } @@ -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()) } diff --git a/internal/services/applications/pre_authorized_application_resource_test.go b/internal/services/applications/application_pre_authorized_resource_test.go similarity index 79% rename from internal/services/applications/pre_authorized_application_resource_test.go rename to internal/services/applications/application_pre_authorized_resource_test.go index 3148e23a28..ec243bae5d 100644 --- a/internal/services/applications/pre_authorized_application_resource_test.go +++ b/internal/services/applications/application_pre_authorized_resource_test.go @@ -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{ { @@ -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{ { @@ -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) } @@ -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" @@ -111,7 +111,7 @@ 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"] @@ -119,13 +119,13 @@ resource "azuread_pre_authorized_application" "test" { `, 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()) diff --git a/internal/services/applications/parse/pre_authorized_application.go b/internal/services/applications/parse/pre_authorized_application.go index 9a1798284d..cac93e4dd2 100644 --- a/internal/services/applications/parse/pre_authorized_application.go +++ b/internal/services/applications/parse/pre_authorized_application.go @@ -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 diff --git a/internal/services/applications/registration.go b/internal/services/applications/registration.go index 81cd8497b4..724977be1f 100644 --- a/internal/services/applications/registration.go +++ b/internal/services/applications/registration.go @@ -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(), } }