From 2eac106f56e9a06c66c78940c249226b6a9e7a6e Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Wed, 13 Sep 2023 12:08:40 +0100 Subject: [PATCH] Use pluginsdk shims, convert data.azuread_client_config to typed datasource --- internal/acceptance/data.go | 11 +- .../{tf/acctest.go => acceptance/random.go} | 13 +- .../random_test.go} | 8 +- internal/helpers/consistency.go | 6 +- internal/helpers/credentials.go | 6 +- internal/provider/provider.go | 2 +- internal/sdk/plugin_sdk_test.go | 16 +- .../administrative_unit_data_source.go | 40 +- .../administrative_unit_data_source_test.go | 13 +- .../administrative_unit_member_resource.go | 39 +- ...dministrative_unit_member_resource_test.go | 21 +- .../administrative_unit_resource.go | 60 +-- .../administrative_unit_resource_test.go | 19 +- ...dministrative_unit_role_member_resource.go | 40 +- ...strative_unit_role_member_resource_test.go | 17 +- .../administrativeunits/registration.go | 12 +- .../application_certificate_resource.go | 54 ++- .../application_certificate_resource_test.go | 25 +- .../applications/application_data_source.go | 240 ++++++------ .../application_data_source_test.go | 11 +- ..._federated_identity_credential_resource.go | 59 ++- ...rated_identity_credential_resource_test.go | 17 +- .../application_password_resource.go | 56 ++- .../application_password_resource_test.go | 13 +- .../application_pre_authorized_resource.go | 50 +-- ...pplication_pre_authorized_resource_test.go | 9 +- ...plication_published_app_ids_data_source.go | 20 +- ...tion_published_app_ids_data_source_test.go | 5 +- .../applications/application_resource.go | 364 +++++++++--------- .../applications/application_resource_test.go | 135 ++++--- .../application_template_data_source.go | 48 +-- .../application_template_data_source_test.go | 9 +- .../services/applications/applications.go | 23 +- .../application_password_resource.go | 31 +- .../migrations/application_resource.go | 260 ++++++------- .../services/applications/registration.go | 12 +- internal/services/applications/schema.go | 26 +- .../app_role_assignment_resource.go | 44 +-- .../app_role_assignment_resource_test.go | 21 +- .../approleassignments/registration.go | 12 +- .../conditional_access_policy_resource.go | 286 +++++++------- ...conditional_access_policy_resource_test.go | 63 ++- .../named_location_data_source.go | 48 +-- .../named_location_data_source_test.go | 9 +- .../named_location_resource.go | 67 ++-- .../named_location_resource_test.go | 33 +- .../conditionalaccess/registration.go | 12 +- .../directory_object_data_source.go | 22 +- .../directory_object_data_source_test.go | 13 +- .../services/directoryobjects/registration.go | 10 +- .../custom_directory_role_resource.go | 68 ++-- .../custom_directory_role_resource_test.go | 29 +- .../directory_role_assignment_resource.go | 55 ++- ...directory_role_assignment_resource_test.go | 29 +- .../directory_role_member_resource.go | 39 +- .../directory_role_member_resource_test.go | 21 +- .../directoryroles/directory_role_resource.go | 38 +- .../directory_role_resource_test.go | 9 +- .../directory_role_templates_data_source.go | 32 +- ...rectory_role_templates_data_source_test.go | 9 +- .../directory_roles_data_source.go | 40 +- .../directory_roles_data_source_test.go | 9 +- .../services/directoryroles/directoryroles.go | 4 +- .../services/directoryroles/registration.go | 12 +- .../services/domains/domains_data_source.go | 54 ++- internal/services/domains/registration.go | 10 +- internal/services/groups/group_data_source.go | 110 +++--- .../services/groups/group_data_source_test.go | 45 ++- .../services/groups/group_member_resource.go | 36 +- .../groups/group_member_resource_test.go | 29 +- internal/services/groups/group_resource.go | 174 ++++----- .../services/groups/group_resource_test.go | 139 ++++--- .../services/groups/groups_data_source.go | 44 +-- .../groups/groups_data_source_test.go | 41 +- internal/services/groups/registration.go | 12 +- ...cess_package_assignment_policy_resource.go | 143 ++++--- ...package_assignment_policy_resource_test.go | 21 +- .../access_package_catalog_data_source.go | 26 +- ...access_package_catalog_data_source_test.go | 9 +- .../access_package_catalog_resource.go | 42 +- .../access_package_catalog_resource_test.go | 17 +- ...ackage_catalog_role_assignment_resource.go | 40 +- ...e_catalog_role_assignment_resource_test.go | 13 +- ...access_package_catalog_role_data_source.go | 22 +- ...s_package_catalog_role_data_source_test.go | 5 +- .../access_package_data_source.go | 26 +- .../access_package_data_source_test.go | 9 +- .../access_package_resource.go | 44 +-- ...e_resource_catalog_association_resource.go | 30 +- ...ource_catalog_association_resource_test.go | 9 +- ...e_resource_package_association_resource.go | 32 +- ...ource_package_association_resource_test.go | 5 +- .../access_package_resource_test.go | 17 +- .../identitygovernance/registration.go | 12 +- .../services/identitygovernance/schema.go | 38 +- .../invitations/invitation_resource.go | 68 ++-- .../invitations/invitation_resource_test.go | 25 +- internal/services/invitations/registration.go | 12 +- .../claims_mapping_policy_resource.go | 26 +- .../claims_mapping_policy_resource_test.go | 7 +- internal/services/policies/registration.go | 12 +- .../client_config_data_source.go | 106 +++-- .../client_config_data_source_test.go | 5 +- .../service_principal_password_resource.go | 31 +- .../serviceprincipals/registration.go | 24 +- internal/services/serviceprincipals/schema.go | 54 +-- .../service_principal_certificate_resource.go | 54 ++- ...ice_principal_certificate_resource_test.go | 25 +- ...aims_mapping_policy_assignment_resource.go | 20 +- ...mapping_policy_assignment_resource_test.go | 5 +- .../service_principal_data_source.go | 130 +++---- .../service_principal_data_source_test.go | 13 +- ...pal_delegated_permission_grant_resource.go | 54 +-- ...elegated_permission_grant_resource_test.go | 9 +- .../service_principal_password_resource.go | 56 ++- ...ervice_principal_password_resource_test.go | 13 +- .../service_principal_resource.go | 182 ++++----- .../service_principal_resource_test.go | 71 ++-- ...ipal_token_signing_certificate_resource.go | 51 ++- ...token_signing_certificate_resource_test.go | 9 +- .../service_principals_data_source.go | 82 ++-- .../service_principals_data_source_test.go | 33 +- .../synchronization_job_resource.go | 53 ++- .../synchronization_job_resource_test.go | 9 +- .../synchronization_secret_resource.go | 45 ++- .../synchronization_secret_resource_test.go | 5 +- internal/services/userflows/registration.go | 10 +- .../userflows/user_flow_attribute_resource.go | 36 +- .../user_flow_attribute_resource_test.go | 15 +- internal/services/users/registration.go | 12 +- internal/services/users/user_data_source.go | 128 +++--- .../services/users/user_data_source_test.go | 25 +- internal/services/users/user_resource.go | 156 ++++---- internal/services/users/user_resource_test.go | 27 +- internal/services/users/users_data_source.go | 80 ++-- .../services/users/users_data_source_test.go | 41 +- internal/tf/import.go | 39 -- internal/tf/{marshall.go => marshal.go} | 0 .../{pluginsdk.go => pluginsdk/unknowns.go} | 2 +- internal/tf/suppress/string.go | 4 +- internal/{validate => tf/validation}/diag.go | 2 +- internal/{validate => tf/validation}/lang.go | 2 +- .../{validate => tf/validation}/lang_test.go | 2 +- .../validation/mail_nickname.go} | 2 +- .../validation/mail_nickname_test.go} | 2 +- internal/tf/validation/pluginsdk.go | 294 ++++++++++++++ internal/tf/validation/pluginsdk_test.go | 53 +++ .../{validate => tf/validation}/strings.go | 25 +- internal/tf/validation/strings_test.go | 44 +++ internal/{validate => tf/validation}/uri.go | 2 +- .../{validate => tf/validation}/uri_test.go | 2 +- internal/validate/strings_test.go | 138 ------- internal/validate/uuid.go | 32 -- internal/validate/uuid_test.go | 44 --- 154 files changed, 3332 insertions(+), 3254 deletions(-) rename internal/{tf/acctest.go => acceptance/random.go} (64%) rename internal/{tf/acctest_test.go => acceptance/random_test.go} (56%) delete mode 100644 internal/tf/import.go rename internal/tf/{marshall.go => marshal.go} (100%) rename internal/tf/{pluginsdk.go => pluginsdk/unknowns.go} (98%) rename internal/{validate => tf/validation}/diag.go (97%) rename internal/{validate => tf/validation}/lang.go (97%) rename internal/{validate => tf/validation}/lang_test.go (98%) rename internal/{validate/mail.go => tf/validation/mail_nickname.go} (97%) rename internal/{validate/mail_test.go => tf/validation/mail_nickname_test.go} (98%) create mode 100644 internal/tf/validation/pluginsdk.go create mode 100644 internal/tf/validation/pluginsdk_test.go rename internal/{validate => tf/validation}/strings.go (66%) create mode 100644 internal/tf/validation/strings_test.go rename internal/{validate => tf/validation}/uri.go (99%) rename internal/{validate => tf/validation}/uri_test.go (99%) delete mode 100644 internal/validate/strings_test.go delete mode 100644 internal/validate/uuid.go delete mode 100644 internal/validate/uuid_test.go diff --git a/internal/acceptance/data.go b/internal/acceptance/data.go index 97e8b7bedb..196fefd561 100644 --- a/internal/acceptance/data.go +++ b/internal/acceptance/data.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-provider-azuread/internal/tf" ) type TestData struct { @@ -28,7 +27,7 @@ type TestData struct { // This is not securely generated and only suitable for ephemeral test cases RandomPassword string - // ResourceName is the fully qualified resource name, comprising of the + // ResourceName is the fully qualified resource name, comprising the // resource type and then the resource label // e.g. `azuread_application.test` ResourceName string @@ -43,7 +42,7 @@ type TestData struct { TenantID string } -func (t *TestData) UUID() string { +func (t TestData) UUID() string { uuid, err := uuid.GenerateUUID() if err != nil { panic(err) @@ -56,7 +55,7 @@ func BuildTestData(t *testing.T, resourceType string, resourceLabel string) Test EnsureProvidersAreInitialised() testData := TestData{ - RandomInteger: tf.AccRandTimeInt(), + RandomInteger: RandTimeInt(), RandomString: acctest.RandString(5), RandomPassword: fmt.Sprintf("%s%s", "p@$$Wd", acctest.RandString(6)), ResourceName: fmt.Sprintf("%s.%s", resourceType, resourceLabel), @@ -71,7 +70,7 @@ func BuildTestData(t *testing.T, resourceType string, resourceLabel string) Test } // RandomIntOfLength is a random 8 to 18 digit integer which is unique to this test case -func (td *TestData) RandomIntOfLength(len int) int { +func (td TestData) RandomIntOfLength(len int) int { // len should not be // - greater then 18, longest a int can represent // - less then 8, as that gives us YYMMDDRR @@ -99,7 +98,7 @@ func (td *TestData) RandomIntOfLength(len int) int { } // RandomStringOfLength is a random 1 to 1024 character string which is unique to this test case -func (td *TestData) RandomStringOfLength(len int) string { +func (td TestData) RandomStringOfLength(len int) string { // len should not be less then 1 or greater than 1024 if 1 > len || len > 1024 { panic("Invalid Test: RandomStringOfLength: length argument must be between 1 and 1024 characters") diff --git a/internal/tf/acctest.go b/internal/acceptance/random.go similarity index 64% rename from internal/tf/acctest.go rename to internal/acceptance/random.go index d95ffeb7bd..bc57436dce 100644 --- a/internal/tf/acctest.go +++ b/internal/acceptance/random.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package tf +package acceptance import ( "strconv" @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" ) -func AccRandTimeInt() int { +func RandTimeInt() int { // acctest.RantInt() returns a value of size: // 000000000000000000 // YYMMddHHmmsshhRRRR @@ -28,3 +28,12 @@ func AccRandTimeInt() int { return i } + +// RandString generates a random alphanumeric string of the length specified +func RandString(strlen int) string { + return acctest.RandString(strlen) +} + +func RandStringFromCharSet(strlen int, charSet string) string { + return acctest.RandStringFromCharSet(strlen, charSet) +} diff --git a/internal/tf/acctest_test.go b/internal/acceptance/random_test.go similarity index 56% rename from internal/tf/acctest_test.go rename to internal/acceptance/random_test.go index 3d3e3a39b2..3e3ad41a54 100644 --- a/internal/tf/acctest_test.go +++ b/internal/acceptance/random_test.go @@ -1,20 +1,20 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package tf +package acceptance import "testing" func TestAccRandTimeInt(t *testing.T) { t.Run("Rand Date int", func(t *testing.T) { - ri := AccRandTimeInt() + ri := RandTimeInt() if ri < 100000000000000000 { - t.Fatalf("AccRandTimeInt returned a value (%d) shorter then expected", ri) + t.Fatalf("RandTimeInt returned a value (%d) shorter then expected", ri) } if ri > 999999999999999999 { - t.Fatalf("AccRandTimeInt returned a value (%d) longer then expected", ri) + t.Fatalf("RandTimeInt returned a value (%d) longer then expected", ri) } }) } diff --git a/internal/helpers/consistency.go b/internal/helpers/consistency.go index 2476b2388f..251b213ae4 100644 --- a/internal/helpers/consistency.go +++ b/internal/helpers/consistency.go @@ -9,7 +9,7 @@ import ( "fmt" "time" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) type ChangeFunc func(ctx context.Context) (*bool, error) @@ -21,7 +21,7 @@ func WaitForDeletion(ctx context.Context, f ChangeFunc) error { } timeout := time.Until(deadline) - _, err := (&resource.StateChangeConf{ //nolint:staticcheck + _, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Deleted"}, Timeout: timeout, @@ -56,7 +56,7 @@ func WaitForUpdate(ctx context.Context, f ChangeFunc) error { } func WaitForUpdateWithTimeout(ctx context.Context, timeout time.Duration, f ChangeFunc) (bool, error) { - res, err := (&resource.StateChangeConf{ //nolint:staticcheck + res, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: timeout, diff --git a/internal/helpers/credentials.go b/internal/helpers/credentials.go index 0707856362..c39ec257b3 100644 --- a/internal/helpers/credentials.go +++ b/internal/helpers/credentials.go @@ -15,7 +15,7 @@ import ( "time" "github.com/hashicorp/go-uuid" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) @@ -87,7 +87,7 @@ func GetTokenSigningCertificateThumbprint(certByte []byte) (string, error) { return buf.String(), nil } -func KeyCredentialForResource(d *schema.ResourceData) (*msgraph.KeyCredential, error) { +func KeyCredentialForResource(d *pluginsdk.ResourceData) (*msgraph.KeyCredential, error) { keyType := d.Get("type").(string) value := d.Get("value").(string) @@ -185,7 +185,7 @@ func KeyCredentialForResource(d *schema.ResourceData) (*msgraph.KeyCredential, e return &credential, nil } -func PasswordCredentialForResource(d *schema.ResourceData) (*msgraph.PasswordCredential, error) { +func PasswordCredentialForResource(d *pluginsdk.ResourceData) (*msgraph.PasswordCredential, error) { credential := msgraph.PasswordCredential{} // display_name, start_date and end_date support intentionally remains for if/when the API supports user-specified values for these diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 83b887f671..e03013dd51 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,7 +7,6 @@ import ( "context" "encoding/base64" "fmt" - "github.com/hashicorp/terraform-provider-azuread/internal/sdk" "log" "os" @@ -17,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" + "github.com/hashicorp/terraform-provider-azuread/internal/sdk" ) // Microsoft’s Terraform Partner ID is this specific GUID diff --git a/internal/sdk/plugin_sdk_test.go b/internal/sdk/plugin_sdk_test.go index 1d5d27c90b..bcb58276b1 100644 --- a/internal/sdk/plugin_sdk_test.go +++ b/internal/sdk/plugin_sdk_test.go @@ -5,6 +5,7 @@ package sdk import ( "fmt" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "os" "reflect" "testing" @@ -153,7 +154,7 @@ func TestAccPluginSDKAndDecoder(t *testing.T) { }, }, }, - Create: func(d *schema.ResourceData, i interface{}) error { + Create: func(d *schema.ResourceData, meta interface{}) error { d.SetId("some-id") d.Set("hello", "world") d.Set("random_number", 42) @@ -272,7 +273,7 @@ func TestAccPluginSDKAndDecoderOptionalComputed(t *testing.T) { ResourcesMap: map[string]*schema.Resource{ "validator_decoder_specified": { Schema: commonSchema, - Create: func(d *schema.ResourceData, i interface{}) error { //nolint:staticcheck + Create: func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck d.SetId("some-id") return nil }, @@ -288,7 +289,7 @@ func TestAccPluginSDKAndDecoderOptionalComputed(t *testing.T) { "validator_decoder_unspecified": { Schema: commonSchema, - Create: func(d *schema.ResourceData, i interface{}) error { //nolint:staticcheck + Create: func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck d.SetId("some-id") d.Set("hello", "value-from-create") d.Set("number", 42) @@ -374,7 +375,7 @@ func TestAccPluginSDKAndDecoderOptionalComputedOverride(t *testing.T) { Computed: true, }, }, - Create: func(d *schema.ResourceData, i interface{}) error { //nolint:staticcheck + Create: func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck d.SetId("some-id") d.Set("hello", "value-from-create") d.Set("number", 42) @@ -493,7 +494,7 @@ func TestAccPluginSDKAndDecoderSets(t *testing.T) { }, }, }, - Create: func(d *schema.ResourceData, i interface{}) error { //nolint:staticcheck + Create: func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck d.SetId("some-id") d.Set("set_of_strings", []string{ "some", @@ -766,7 +767,7 @@ func TestAccPluginSDKAndEncoder(t *testing.T) { }, }, }, - Create: func(d *schema.ResourceData, i interface{}) error { //nolint:staticcheck + Create: func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck wrapper := ResourceMetaData{ ResourceData: d, Logger: ConsoleLogger{}, @@ -991,6 +992,9 @@ func computedFieldsResource() *schema.Resource { Delete: func(_ *schema.ResourceData, _ interface{}) error { return nil }, + Importer: pluginsdk.ImporterValidatingResourceId(func(_ string) error { + return nil + }), } } diff --git a/internal/services/administrativeunits/administrative_unit_data_source.go b/internal/services/administrativeunits/administrative_unit_data_source.go index 6a70548911..499895c9af 100644 --- a/internal/services/administrativeunits/administrative_unit_data_source.go +++ b/internal/services/administrativeunits/administrative_unit_data_source.go @@ -6,71 +6,71 @@ package administrativeunits import ( "context" "fmt" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "net/http" "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "github.com/manicminer/hamilton/msgraph" ) -func administrativeUnitDataSource() *schema.Resource { - return &schema.Resource{ +func administrativeUnitDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: administrativeUnitDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_id": { Description: "The object ID of the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "display_name": { Description: "The display name for the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "description": { Description: "The description for the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "members": { Description: "A list of object IDs of members who are be present in this administrative unit.", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "visibility": { Description: "Whether the administrative unit and its members are hidden or publicly viewable in the directory", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func administrativeUnitDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient var administrativeUnit msgraph.AdministrativeUnit diff --git a/internal/services/administrativeunits/administrative_unit_data_source_test.go b/internal/services/administrativeunits/administrative_unit_data_source_test.go index 354117d3f9..d9c0d17829 100644 --- a/internal/services/administrativeunits/administrative_unit_data_source_test.go +++ b/internal/services/administrativeunits/administrative_unit_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,10 +16,10 @@ type AdministrativeUnitDataSource struct{} func TestAccAdministrativeUnitDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_administrative_unit", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: AdministrativeUnitDataSource{}.displayName(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestAdministrativeUnit-%d", data.RandomInteger)), ), }, @@ -30,10 +29,10 @@ func TestAccAdministrativeUnitDataSource_byDisplayName(t *testing.T) { func TestAccAdministrativeUnitDataSource_byObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_administrative_unit", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: AdministrativeUnitDataSource{}.objectId(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestAdministrativeUnit-%d", data.RandomInteger)), ), }, @@ -43,10 +42,10 @@ func TestAccAdministrativeUnitDataSource_byObjectId(t *testing.T) { func TestAccAdministrativeUnitDataSource_members(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_administrative_unit", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: AdministrativeUnitDataSource{}.members(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestAdministrativeUnit-%d", data.RandomInteger)), check.That(data.ResourceName).Key("members.#").HasValue("4"), ), diff --git a/internal/services/administrativeunits/administrative_unit_member_resource.go b/internal/services/administrativeunits/administrative_unit_member_resource.go index 63e74344b9..8df9790139 100644 --- a/internal/services/administrativeunits/administrative_unit_member_resource.go +++ b/internal/services/administrativeunits/administrative_unit_member_resource.go @@ -13,56 +13,55 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/administrativeunits/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func administrativeUnitMemberResource() *schema.Resource { - return &schema.Resource{ +func administrativeUnitMemberResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: administrativeUnitMemberResourceCreate, ReadContext: administrativeUnitMemberResourceRead, DeleteContext: administrativeUnitMemberResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.AdministrativeUnitMemberID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "administrative_unit_object_id": { Description: "The object ID of the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "member_object_id": { Description: "The object ID of the member", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, } } -func administrativeUnitMemberResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitMemberResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient directoryObjectsClient := meta.(*clients.Client).AdministrativeUnits.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -114,7 +113,7 @@ func administrativeUnitMemberResourceCreate(ctx context.Context, d *schema.Resou return tf.ErrorDiagF(errors.New("context has no deadline"), "Waiting for member %q to reflect for administrative unit %q", id.MemberId, id.AdministrativeUnitId) } timeout := time.Until(deadline) - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: timeout, @@ -140,7 +139,7 @@ func administrativeUnitMemberResourceCreate(ctx context.Context, d *schema.Resou return administrativeUnitMemberResourceRead(ctx, d, meta) } -func administrativeUnitMemberResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitMemberResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient id, err := parse.AdministrativeUnitMemberID(d.Id()) @@ -163,7 +162,7 @@ func administrativeUnitMemberResourceRead(ctx context.Context, d *schema.Resourc return nil } -func administrativeUnitMemberResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitMemberResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient id, err := parse.AdministrativeUnitMemberID(d.Id()) diff --git a/internal/services/administrativeunits/administrative_unit_member_resource_test.go b/internal/services/administrativeunits/administrative_unit_member_resource_test.go index e147bc394a..670424aea1 100644 --- a/internal/services/administrativeunits/administrative_unit_member_resource_test.go +++ b/internal/services/administrativeunits/administrative_unit_member_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAdministrativeUnitMember_group(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit_member", "test") r := AdministrativeUnitMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.group(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("administrative_unit_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -41,10 +40,10 @@ func TestAccAdministrativeUnitMember_user(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit_member", "testA") r := AdministrativeUnitMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("administrative_unit_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -59,10 +58,10 @@ func TestAccAdministrativeUnitMember_multipleUsers(t *testing.T) { dataB := acceptance.BuildTestData(t, "azuread_administrative_unit_member", "testB") r := AdministrativeUnitMemberResource{} - dataA.ResourceTest(t, r, []resource.TestStep{ + dataA.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("administrative_unit_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -71,7 +70,7 @@ func TestAccAdministrativeUnitMember_multipleUsers(t *testing.T) { dataA.ImportStep(), { Config: r.twoUsers(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("administrative_unit_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -84,7 +83,7 @@ func TestAccAdministrativeUnitMember_multipleUsers(t *testing.T) { dataB.ImportStep(), { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("administrative_unit_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -98,10 +97,10 @@ func TestAccAdministrativeUnitMember_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit_member", "test") r := AdministrativeUnitMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.group(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/administrativeunits/administrative_unit_resource.go b/internal/services/administrativeunits/administrative_unit_resource.go index 5f76294170..517ed91f2e 100644 --- a/internal/services/administrativeunits/administrative_unit_resource.go +++ b/internal/services/administrativeunits/administrative_unit_resource.go @@ -14,19 +14,19 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "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/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const administrativeUnitResourceName = "azuread_administrative_unit" -func administrativeUnitResource() *schema.Resource { - return &schema.Resource{ +func administrativeUnitResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: administrativeUnitResourceCreate, ReadContext: administrativeUnitResourceRead, UpdateContext: administrativeUnitResourceUpdate, @@ -34,74 +34,74 @@ func administrativeUnitResource() *schema.Resource { CustomizeDiff: administrativeUnitResourceCustomizeDiff, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name for the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "description": { Description: "The description for the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "members": { Description: "A set of object IDs of members who should be present in this administrative unit. Supported object types are Users or Groups", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, - Set: schema.HashString, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Set: pluginsdk.HashString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "prevent_duplicate_names": { Description: "If `true`, will return an error if an existing administrative unit is found with the same name", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "hidden_membership_enabled": { Description: "Whether the administrative unit and its members are hidden or publicly viewable in the directory", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "object_id": { Description: "The object ID of the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func administrativeUnitResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func administrativeUnitResourceCustomizeDiff(ctx context.Context, diff *pluginsdk.ResourceDiff, meta interface{}) error { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient // Check for duplicate names oldDisplayName, newDisplayName := diff.GetChange("display_name") - if diff.Get("prevent_duplicate_names").(bool) && tf.ValueIsNotEmptyOrUnknown(newDisplayName) && + if diff.Get("prevent_duplicate_names").(bool) && pluginsdk.ValueIsNotEmptyOrUnknown(newDisplayName) && (oldDisplayName.(string) == "" || oldDisplayName.(string) != newDisplayName.(string)) { result, err := administrativeUnitFindByName(ctx, client, newDisplayName.(string)) if err != nil { @@ -122,7 +122,7 @@ func administrativeUnitResourceCustomizeDiff(ctx context.Context, diff *schema.R return nil } -func administrativeUnitResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient directoryObjectsClient := meta.(*clients.Client).AdministrativeUnits.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -188,7 +188,7 @@ func administrativeUnitResourceCreate(ctx context.Context, d *schema.ResourceDat // Add members after the administrative unit is created members := make(msgraph.Members, 0) if v, ok := d.GetOk("members"); ok { - for _, memberId := range v.(*schema.Set).List() { + for _, memberId := range v.(*pluginsdk.Set).List() { memberObject, _, err := directoryObjectsClient.Get(ctx, memberId.(string), odata.Query{}) if err != nil { return tf.ErrorDiagF(err, "Could not retrieve member principal object %q", memberId) @@ -215,7 +215,7 @@ func administrativeUnitResourceCreate(ctx context.Context, d *schema.ResourceDat return administrativeUnitResourceRead(ctx, d, meta) } -func administrativeUnitResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient directoryObjectsClient := meta.(*clients.Client).AdministrativeUnits.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -267,7 +267,7 @@ func administrativeUnitResourceUpdate(ctx context.Context, d *schema.ResourceDat } existingMembers := *members - desiredMembers := *tf.ExpandStringSlicePtr(d.Get("members").(*schema.Set).List()) + desiredMembers := *tf.ExpandStringSlicePtr(d.Get("members").(*pluginsdk.Set).List()) membersForRemoval := utils.Difference(existingMembers, desiredMembers) membersToAdd := utils.Difference(desiredMembers, existingMembers) @@ -306,7 +306,7 @@ func administrativeUnitResourceUpdate(ctx context.Context, d *schema.ResourceDat return administrativeUnitResourceRead(ctx, d, meta) } -func administrativeUnitResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient administrativeUnit, status, err := client.Get(ctx, d.Id(), odata.Query{}) @@ -341,7 +341,7 @@ func administrativeUnitResourceRead(ctx context.Context, d *schema.ResourceData, return nil } -func administrativeUnitResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient administrativeUnitId := d.Id() diff --git a/internal/services/administrativeunits/administrative_unit_resource_test.go b/internal/services/administrativeunits/administrative_unit_resource_test.go index e6b4fc10cf..7551d343f1 100644 --- a/internal/services/administrativeunits/administrative_unit_resource_test.go +++ b/internal/services/administrativeunits/administrative_unit_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAdministrativeUnit_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit", "test") r := AdministrativeUnitResource{} - data.ResourceTestIgnoreDangling(t, r, []resource.TestStep{ + data.ResourceTestIgnoreDangling(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").IsUuid(), ), @@ -40,10 +39,10 @@ func TestAccAdministrativeUnit_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit", "test") r := AdministrativeUnitResource{} - data.ResourceTestIgnoreDangling(t, r, []resource.TestStep{ + data.ResourceTestIgnoreDangling(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").IsUuid(), ), @@ -56,10 +55,10 @@ func TestAccAdministrativeUnit_withMembers(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit", "test") r := AdministrativeUnitResource{} - data.ResourceTestIgnoreDangling(t, r, []resource.TestStep{ + data.ResourceTestIgnoreDangling(t, r, []acceptance.TestStep{ { Config: r.withMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").IsUuid(), ), @@ -72,10 +71,10 @@ func TestAccGroup_preventDuplicateNamesPass(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit", "test") r := AdministrativeUnitResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.preventDuplicateNamesPass(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestAdministrativeUnit-%d", data.RandomInteger)), ), }, @@ -87,7 +86,7 @@ func TestAccGroup_preventDuplicateNamesFail(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit", "test") r := AdministrativeUnitResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ data.RequiresImportErrorStep(r.preventDuplicateNamesFail(data)), }) } diff --git a/internal/services/administrativeunits/administrative_unit_role_member_resource.go b/internal/services/administrativeunits/administrative_unit_role_member_resource.go index 547db22ecf..e65c26e36b 100644 --- a/internal/services/administrativeunits/administrative_unit_role_member_resource.go +++ b/internal/services/administrativeunits/administrative_unit_role_member_resource.go @@ -11,62 +11,62 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/services/administrativeunits/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func administrativeUnitRoleMemberResource() *schema.Resource { - return &schema.Resource{ +func administrativeUnitRoleMemberResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: administrativeUnitRoleMemberResourceCreate, ReadContext: administrativeUnitRoleMemberResourceRead, DeleteContext: administrativeUnitRoleMemberResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.AdministrativeUnitRoleMemberID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "administrative_unit_object_id": { Description: "The object ID of the administrative unit", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "role_object_id": { Description: "The object ID of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "member_object_id": { Description: "The object ID of the member", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, } } -func administrativeUnitRoleMemberResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitRoleMemberResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient memberID := utils.String(d.Get("member_object_id").(string)) @@ -92,7 +92,7 @@ func administrativeUnitRoleMemberResourceCreate(ctx context.Context, d *schema.R return administrativeUnitRoleMemberResourceRead(ctx, d, meta) } -func administrativeUnitRoleMemberResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitRoleMemberResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient id, err := parse.AdministrativeUnitRoleMemberID(d.Id()) @@ -115,7 +115,7 @@ func administrativeUnitRoleMemberResourceRead(ctx context.Context, d *schema.Res return nil } -func administrativeUnitRoleMemberResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func administrativeUnitRoleMemberResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AdministrativeUnits.AdministrativeUnitsClient id, err := parse.AdministrativeUnitRoleMemberID(d.Id()) diff --git a/internal/services/administrativeunits/administrative_unit_role_member_resource_test.go b/internal/services/administrativeunits/administrative_unit_role_member_resource_test.go index 40d079f508..15c06b184b 100644 --- a/internal/services/administrativeunits/administrative_unit_role_member_resource_test.go +++ b/internal/services/administrativeunits/administrative_unit_role_member_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -25,10 +24,10 @@ func TestAccAdministrativeUnitRoleMember_user(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit_role_member", "test") r := AdministrativeUnitRoleMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -44,10 +43,10 @@ func TestAccAdministrativeUnitRoleMember_multipleUser(t *testing.T) { dataC := acceptance.BuildTestData(t, "azuread_administrative_unit_role_member", "testC") r := AdministrativeUnitRoleMemberResource{} - dataA.ResourceTest(t, r, []resource.TestStep{ + dataA.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.threeUsers(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -69,10 +68,10 @@ func TestAccAdministrativeUnitRoleMember_group(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit_role_member", "test") r := AdministrativeUnitRoleMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.group(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -86,10 +85,10 @@ func TestAccAdministrativeUnitRoleMember_servicePrincipal(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_administrative_unit_role_member", "test") r := AdministrativeUnitRoleMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), diff --git a/internal/services/administrativeunits/registration.go b/internal/services/administrativeunits/registration.go index 6179606428..7075facbb0 100644 --- a/internal/services/administrativeunits/registration.go +++ b/internal/services/administrativeunits/registration.go @@ -3,9 +3,7 @@ package administrativeunits -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,15 +20,15 @@ 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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_administrative_unit": administrativeUnitDataSource(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_administrative_unit": administrativeUnitResource(), "azuread_administrative_unit_member": administrativeUnitMemberResource(), "azuread_administrative_unit_role_member": administrativeUnitRoleMemberResource(), diff --git a/internal/services/applications/application_certificate_resource.go b/internal/services/applications/application_certificate_resource.go index fa759398cd..63ed04b94c 100644 --- a/internal/services/applications/application_certificate_resource.go +++ b/internal/services/applications/application_certificate_resource.go @@ -14,48 +14,46 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func applicationCertificateResource() *schema.Resource { - return &schema.Resource{ +func applicationCertificateResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: applicationCertificateResourceCreate, ReadContext: applicationCertificateResourceRead, DeleteContext: applicationCertificateResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.CertificateID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "application_object_id": { Description: "The object ID of the application for which this certificate should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "encoding": { Description: "Specifies the encoding used for the supplied certificate data", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, Default: "pem", @@ -68,16 +66,16 @@ func applicationCertificateResource() *schema.Resource { "key_id": { Description: "A UUID used to uniquely identify this certificate. If omitted, a random UUID will be automatically generated", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "start_date": { Description: "The start date from which the certificate is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`). If this isn't specified, the current date and time are use", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -86,7 +84,7 @@ func applicationCertificateResource() *schema.Resource { "end_date": { Description: "The end date until which the certificate is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`). If omitted, the API will decide a suitable expiry date, which is typically around 2 years from the start date", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -96,16 +94,16 @@ func applicationCertificateResource() *schema.Resource { "end_date_relative": { Description: "A relative duration for which the certificate is valid until, for example `240h` (10 days) or `2400h30m`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ConflictsWith: []string{"end_date"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "type": { Description: "The type of key/certificate", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ @@ -116,7 +114,7 @@ func applicationCertificateResource() *schema.Resource { "value": { Description: "The certificate data, which can be PEM encoded, base64 encoded DER or hexadecimal encoded DER. See also the `encoding` argumen", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, Sensitive: true, @@ -125,7 +123,7 @@ func applicationCertificateResource() *schema.Resource { } } -func applicationCertificateResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationCertificateResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient objectId := d.Get("application_object_id").(string) @@ -178,7 +176,7 @@ func applicationCertificateResourceCreate(ctx context.Context, d *schema.Resourc // Wait for the credential to appear in the application manifest, this can take several minutes timeout, _ := ctx.Deadline() - polledForCredential, err := (&resource.StateChangeConf{ //nolint:staticcheck + polledForCredential, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -213,7 +211,7 @@ func applicationCertificateResourceCreate(ctx context.Context, d *schema.Resourc return applicationCertificateResourceRead(ctx, d, meta) } -func applicationCertificateResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationCertificateResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.CertificateID(d.Id()) @@ -257,7 +255,7 @@ func applicationCertificateResourceRead(ctx context.Context, d *schema.ResourceD return nil } -func applicationCertificateResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationCertificateResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.CertificateID(d.Id()) diff --git a/internal/services/applications/application_certificate_resource_test.go b/internal/services/applications/application_certificate_resource_test.go index d3d5b9552e..d6716cc555 100644 --- a/internal/services/applications/application_certificate_resource_test.go +++ b/internal/services/applications/application_certificate_resource_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -73,10 +72,10 @@ func TestAccApplicationCertificate_basic(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ApplicationCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -91,10 +90,10 @@ func TestAccApplicationCertificate_complete(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ApplicationCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data, startDate, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -108,10 +107,10 @@ func TestAccApplicationCertificate_base64Cert(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ApplicationCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.base64Cert(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -125,10 +124,10 @@ func TestAccApplicationCertificate_hexCert(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ApplicationCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.hexCert(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -141,10 +140,10 @@ func TestAccApplicationCertificate_relativeEndDate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_certificate", "test") r := ApplicationCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.relativeEndDate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), check.That(data.ResourceName).Key("end_date").Exists(), @@ -159,10 +158,10 @@ func TestAccApplicationCertificate_requiresImport(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ApplicationCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), diff --git a/internal/services/applications/application_data_source.go b/internal/services/applications/application_data_source.go index 866af0b626..810bb5b7b5 100644 --- a/internal/services/applications/application_data_source.go +++ b/internal/services/applications/application_data_source.go @@ -12,127 +12,127 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func applicationDataSource() *schema.Resource { - return &schema.Resource{ +func applicationDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: applicationDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_id": { Description: "The application's object ID", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"application_id", "display_name", "object_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "application_id": { Description: "The Application ID (also called Client ID)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"application_id", "display_name", "object_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "disabled_by_microsoft": { Description: "Whether Microsoft has disabled the registered application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "display_name": { Description: "The display name for the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"application_id", "display_name", "object_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "api": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "known_client_applications": { Description: "Used for bundling consent if you have a solution that contains two parts: a client app and a custom web API app", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "mapped_claims_enabled": { Description: "Allows an application to use claims mapping without specifying a custom signing key", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "oauth2_permission_scopes": { Description: "List of OAuth2 permission scopes published by the application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier of the delegated permission. Must be a valid UUID", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "admin_consent_description": { Description: "Delegated permission description that appears in all tenant-wide admin consent experiences, intended to be read by an administrator granting the permission on behalf of all users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "admin_consent_display_name": { Description: "Display name for the delegated permission, intended to be read by an administrator granting the permission on behalf of all users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "enabled": { Description: "Determines if the permission scope is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "type": { Description: "Whether this delegated permission should be considered safe for non-admin users to consent to on behalf of themselves, or whether an administrator should be required for consent to the permissions. Possible values are `User` or `Admin`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_consent_description": { Description: "Delegated permission description that appears in the end user consent experience, intended to be read by a user consenting on their own behalf", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_consent_display_name": { Description: "Display name for the delegated permission that appears in the end user consent experience", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "value": { Description: "The value that is used for the `scp` claim in OAuth 2.0 access tokens", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -141,7 +141,7 @@ func applicationDataSource() *schema.Resource { "requested_access_token_version": { Description: "Specifies the access token version expected by this resource", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Computed: true, }, }, @@ -150,46 +150,46 @@ func applicationDataSource() *schema.Resource { "app_roles": { Description: "List of app roles published by the application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier of the app role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "allowed_member_types": { Description: "Specifies whether this app role definition can be assigned to users and groups, or to other applications (that are accessing this application in a standalone scenario). Possible values are `User` or `Application`, or both", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "description": { Description: "Description of the app role that appears when the role is being assigned and, if the role functions as an application permissions, during the consent experiences", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "display_name": { Description: "Display name for the app role that appears during app role assignment and in consent experiences", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "enabled": { Description: "The unique identifier of the app role", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "value": { Description: "The value that is used for the `roles` claim in ID tokens and OAuth 2.0 access tokens that are authenticating an assigned service or user principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -198,58 +198,58 @@ func applicationDataSource() *schema.Resource { "app_role_ids": { Description: "Mapping of app role names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "description": { Description: "Description of the application as shown to end users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "device_only_auth_enabled": { Description: "Specifies whether this application supports device authentication without a user.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "fallback_public_client_enabled": { Description: "The fallback application type as public client, such as an installed application running on a mobile device", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "feature_tags": { Description: "Block of features configured for this application using tags", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "custom_single_sign_on": { Description: "Whether this application principal represents a custom SAML application for linked service principals", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "enterprise": { Description: "Whether this application represents an Enterprise Application for linked service principals", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "gallery": { Description: "Whether this application represents a gallery application for linked service principals", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "hide": { Description: "Whether this app is invisible to users in My Apps and Office 365 Launcher", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, @@ -259,60 +259,60 @@ func applicationDataSource() *schema.Resource { "group_membership_claims": { Description: "The `groups` claim issued in a user or OAuth 2.0 access token that the app expects", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "identifier_uris": { Description: "A list of user-defined URI(s) that uniquely identify a Web application within it's Azure AD tenant, or within a verified custom domain if the application is multi-tenant", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "logo_url": { Description: "CDN URL to the application's logo", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "notes": { Description: "User-specified notes relevant for the management of the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "marketing_url": { Description: "URL of the application's marketing page", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "oauth2_permission_scope_ids": { Description: "Mapping of OAuth2.0 permission scope names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "oauth2_post_response_required": { Description: "Specifies whether, as part of OAuth 2.0 token requests, Azure AD allows POST requests, as opposed to GET requests.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "optional_claims": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "access_token": schemaOptionalClaims(), "id_token": schemaOptionalClaims(), "saml2_token": schemaOptionalClaims(), @@ -322,30 +322,30 @@ func applicationDataSource() *schema.Resource { "owners": { Description: "A list of object IDs of principals that are assigned ownership of the application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "privacy_statement_url": { Description: "URL of the application's privacy statement", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "public_client": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, }, @@ -354,36 +354,36 @@ func applicationDataSource() *schema.Resource { "publisher_domain": { Description: "The verified publisher domain for the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "required_resource_access": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "resource_app_id": { Description: "The unique identifier for the resource that the application requires access to. This is the Application ID of the target application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "resource_access": { Description: "A collection of `resource_access` blocks describing OAuth2.0 permission scopes and app roles that the application requires from the specified resource", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier for an app role or OAuth2 permission scope published by the resource application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "type": { Description: "Specifies whether the `id` property references an app role or an OAuth2 permission scope. Possible values are `Role` or `Scope`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -395,27 +395,27 @@ func applicationDataSource() *schema.Resource { "service_management_reference": { Description: "References application or service contact information from a Service or Asset Management database", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "sign_in_audience": { Description: "The Microsoft account types that are supported for the current application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "single_page_application": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, }, @@ -424,65 +424,65 @@ func applicationDataSource() *schema.Resource { "support_url": { Description: "URL of the application's support page", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "tags": { Description: "A set of tags applied to the application", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "terms_of_service_url": { Description: "URL of the application's terms of service statement", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "web": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "homepage_url": { Description: "Home page or landing page of the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "logout_url": { Description: "The URL that will be used by Microsoft's authorization service to sign out a user using front-channel, back-channel or SAML logout protocols", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "redirect_uris": { Description: "A list of URLs where user tokens are sent for sign-in, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "implicit_grant": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "access_token_issuance_enabled": { Description: "Whether this web application can request an access token using OAuth 2.0 implicit flow", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "id_token_issuance_enabled": { Description: "Whether this web application can request an ID token using OAuth 2.0 implicit flow", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, @@ -495,7 +495,7 @@ func applicationDataSource() *schema.Resource { } } -func applicationDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/applications/application_data_source_test.go b/internal/services/applications/application_data_source_test.go index 5f5baf0b2e..dcdcd93682 100644 --- a/internal/services/applications/application_data_source_test.go +++ b/internal/services/applications/application_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -18,7 +17,7 @@ func TestAccApplicationDataSource_byObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_application", "test") r := ApplicationDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.objectId(data), Check: r.testCheck(data), @@ -30,7 +29,7 @@ func TestAccApplicationDataSource_byApplicationId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_application", "test") r := ApplicationDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.applicationId(data), Check: r.testCheck(data), @@ -42,7 +41,7 @@ func TestAccApplicationDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_application", "test") r := ApplicationDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.displayName(data), Check: r.testCheck(data), @@ -50,8 +49,8 @@ func TestAccApplicationDataSource_byDisplayName(t *testing.T) { }) } -func (ApplicationDataSource) testCheck(data acceptance.TestData) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( +func (ApplicationDataSource) testCheck(data acceptance.TestData) acceptance.TestCheckFunc { + return acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("application_id").IsUuid(), check.That(data.ResourceName).Key("object_id").IsUuid(), check.That(data.ResourceName).Key("api.0.oauth2_permission_scopes.#").HasValue("2"), diff --git a/internal/services/applications/application_federated_identity_credential_resource.go b/internal/services/applications/application_federated_identity_credential_resource.go index 5743667959..51c16a1674 100644 --- a/internal/services/applications/application_federated_identity_credential_resource.go +++ b/internal/services/applications/application_federated_identity_credential_resource.go @@ -6,6 +6,7 @@ package applications import ( "context" "errors" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "strings" @@ -13,94 +14,92 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func applicationFederatedIdentityCredentialResource() *schema.Resource { - return &schema.Resource{ +func applicationFederatedIdentityCredentialResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: applicationFederatedIdentityCredentialResourceCreate, UpdateContext: applicationFederatedIdentityCredentialResourceUpdate, ReadContext: applicationFederatedIdentityCredentialResourceRead, DeleteContext: applicationFederatedIdentityCredentialResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(15 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(15 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.FederatedIdentityCredentialID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "application_object_id": { Description: "The object ID of the application for which this federated identity credential should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "audiences": { Description: "List of audiences that can appear in the external token. This specifies what should be accepted in the `aud` claim of incoming tokens.", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, MaxItems: 1, // TODO: consider making this a scalar value instead of a list in v3.0 (the API now only accepts a single value) - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.ValidateDiag(validation.StringIsNotEmpty), + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.ValidateDiag(validation.StringIsNotEmpty), }, }, "display_name": { Description: "A unique display name for the federated identity credential", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.ValidateDiag(validation.StringLenBetween(1, 120)), + ValidateDiagFunc: validation2.ValidateDiag(validation.StringLenBetween(1, 120)), }, "issuer": { Description: "The URL of the external identity provider, which must match the issuer claim of the external token being exchanged. The combination of the values of issuer and subject must be unique on the app.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "subject": { Description: "The identifier of the external software workload within the external identity provider. The combination of issuer and subject must be unique on the app.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "description": { Description: "A description for the federated identity credential", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "credential_id": { Description: "A UUID used to uniquely identify this federated identity credential", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func applicationFederatedIdentityCredentialResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationFederatedIdentityCredentialResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient objectId := d.Get("application_object_id").(string) @@ -141,7 +140,7 @@ func applicationFederatedIdentityCredentialResourceCreate(ctx context.Context, d // Wait for the credential to replicate timeout, _ := ctx.Deadline() - polledForCredential, err := (&resource.StateChangeConf{ //nolint:staticcheck + polledForCredential, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -176,7 +175,7 @@ func applicationFederatedIdentityCredentialResourceCreate(ctx context.Context, d return applicationFederatedIdentityCredentialResourceRead(ctx, d, meta) } -func applicationFederatedIdentityCredentialResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationFederatedIdentityCredentialResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.FederatedIdentityCredentialID(d.Id()) @@ -203,7 +202,7 @@ func applicationFederatedIdentityCredentialResourceUpdate(ctx context.Context, d return applicationFederatedIdentityCredentialResourceRead(ctx, d, meta) } -func applicationFederatedIdentityCredentialResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationFederatedIdentityCredentialResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.FederatedIdentityCredentialID(d.Id()) @@ -233,7 +232,7 @@ func applicationFederatedIdentityCredentialResourceRead(ctx context.Context, d * return nil } -func applicationFederatedIdentityCredentialResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationFederatedIdentityCredentialResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.FederatedIdentityCredentialID(d.Id()) diff --git a/internal/services/applications/application_federated_identity_credential_resource_test.go b/internal/services/applications/application_federated_identity_credential_resource_test.go index 8d0792d2bd..090fc3f5e9 100644 --- a/internal/services/applications/application_federated_identity_credential_resource_test.go +++ b/internal/services/applications/application_federated_identity_credential_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -25,10 +24,10 @@ func TestAccApplicationFederatedIdentityCredential_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_federated_identity_credential", "test") r := ApplicationFederatedIdentityCredentialResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("credential_id").Exists(), ), @@ -41,10 +40,10 @@ func TestAccApplicationFederatedIdentityCredential_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_federated_identity_credential", "test") r := ApplicationFederatedIdentityCredentialResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("credential_id").Exists(), ), @@ -57,10 +56,10 @@ func TestAccApplicationFederatedIdentityCredential_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_federated_identity_credential", "test") r := ApplicationFederatedIdentityCredentialResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("credential_id").Exists(), ), @@ -68,7 +67,7 @@ func TestAccApplicationFederatedIdentityCredential_update(t *testing.T) { data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("credential_id").Exists(), ), @@ -76,7 +75,7 @@ func TestAccApplicationFederatedIdentityCredential_update(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("credential_id").Exists(), ), diff --git a/internal/services/applications/application_password_resource.go b/internal/services/applications/application_password_resource.go index 7edfa67793..beb304270a 100644 --- a/internal/services/applications/application_password_resource.go +++ b/internal/services/applications/application_password_resource.go @@ -14,33 +14,31 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/migrations" "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" ) -func applicationPasswordResource() *schema.Resource { - return &schema.Resource{ +func applicationPasswordResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: applicationPasswordResourceCreate, ReadContext: applicationPasswordResourceRead, DeleteContext: applicationPasswordResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(15 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(15 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, SchemaVersion: 1, - StateUpgraders: []schema.StateUpgrader{ + StateUpgraders: []pluginsdk.StateUpgrader{ { Type: migrations.ResourceApplicationPasswordInstanceResourceV0().CoreConfigSchema().ImpliedType(), Upgrade: migrations.ResourceApplicationPasswordInstanceStateUpgradeV0, @@ -48,18 +46,18 @@ func applicationPasswordResource() *schema.Resource { }, }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "application_object_id": { Description: "The object ID of the application for which this password should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "A display name for the password", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -67,7 +65,7 @@ func applicationPasswordResource() *schema.Resource { "start_date": { Description: "The start date from which the password is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`). If this isn't specified, the current date is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -76,7 +74,7 @@ func applicationPasswordResource() *schema.Resource { "end_date": { Description: "The end date until which the password is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -86,32 +84,32 @@ func applicationPasswordResource() *schema.Resource { "end_date_relative": { Description: "A relative duration for which the password is valid until, for example `240h` (10 days) or `2400h30m`. Changing this field forces a new resource to be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ConflictsWith: []string{"end_date"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "rotate_when_changed": { Description: "Arbitrary map of values that, when changed, will trigger rotation of the password", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Optional: true, ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "key_id": { Description: "A UUID used to uniquely identify this password credential", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "value": { Description: "The password for this application, which is generated by Azure Active Directory", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, Sensitive: true, }, @@ -119,7 +117,7 @@ func applicationPasswordResource() *schema.Resource { } } -func applicationPasswordResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationPasswordResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient objectId := d.Get("application_object_id").(string) @@ -167,7 +165,7 @@ func applicationPasswordResourceCreate(ctx context.Context, d *schema.ResourceDa // Wait for the credential to appear in the application manifest, this can take several minutes timeout, _ := ctx.Deadline() - polledForCredential, err := (&resource.StateChangeConf{ //nolint:staticcheck + polledForCredential, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -203,7 +201,7 @@ func applicationPasswordResourceCreate(ctx context.Context, d *schema.ResourceDa return applicationPasswordResourceRead(ctx, d, meta) } -func applicationPasswordResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationPasswordResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.PasswordID(d.Id()) @@ -257,7 +255,7 @@ func applicationPasswordResourceRead(ctx context.Context, d *schema.ResourceData return nil } -func applicationPasswordResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint +func applicationPasswordResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { //nolint client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.PasswordID(d.Id()) diff --git a/internal/services/applications/application_password_resource_test.go b/internal/services/applications/application_password_resource_test.go index 52ac6e30b8..288bd59ed6 100644 --- a/internal/services/applications/application_password_resource_test.go +++ b/internal/services/applications/application_password_resource_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -26,10 +25,10 @@ func TestAccApplicationPassword_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_password", "test") r := ApplicationPasswordResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("end_date").Exists(), check.That(data.ResourceName).Key("key_id").Exists(), @@ -46,10 +45,10 @@ func TestAccApplicationPassword_complete(t *testing.T) { endDate := time.Now().AddDate(0, 5, 27).UTC().Format(time.RFC3339) r := ApplicationPasswordResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data, startDate, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("end_date").Exists(), check.That(data.ResourceName).Key("key_id").Exists(), @@ -64,10 +63,10 @@ func TestAccApplicationPassword_relativeEndDate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_password", "test") r := ApplicationPasswordResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.relativeEndDate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("end_date").Exists(), check.That(data.ResourceName).Key("end_date_relative").HasValue("8760h"), diff --git a/internal/services/applications/application_pre_authorized_resource.go b/internal/services/applications/application_pre_authorized_resource.go index 0a9106995f..fedd3b5894 100644 --- a/internal/services/applications/application_pre_authorized_resource.go +++ b/internal/services/applications/application_pre_authorized_resource.go @@ -14,65 +14,65 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/services/applications/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func applicationPreAuthorizedResource() *schema.Resource { - return &schema.Resource{ +func applicationPreAuthorizedResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: applicationPreAuthorizedResourceCreate, ReadContext: applicationPreAuthorizedResourceRead, UpdateContext: applicationPreAuthorizedResourceUpdate, DeleteContext: applicationPreAuthorizedResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.ApplicationPreAuthorizedID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "application_object_id": { Description: "The object ID of the application to which this pre-authorized application should be added", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "authorized_app_id": { Description: "The application ID of the pre-authorized application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "permission_ids": { Description: "The IDs of the permission scopes required by the pre-authorized application", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, }, } } -func applicationPreAuthorizedResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationPreAuthorizedResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient id := parse.NewApplicationPreAuthorizedID(d.Get("application_object_id").(string), d.Get("authorized_app_id").(string)) @@ -102,7 +102,7 @@ func applicationPreAuthorizedResourceCreate(ctx context.Context, d *schema.Resou newPreAuthorizedApps = append(newPreAuthorizedApps, msgraph.ApiPreAuthorizedApplication{ AppId: utils.String(id.AppId), - PermissionIds: tf.ExpandStringSlicePtr(d.Get("permission_ids").(*schema.Set).List()), + PermissionIds: tf.ExpandStringSlicePtr(d.Get("permission_ids").(*pluginsdk.Set).List()), }) properties := msgraph.Application{ @@ -123,7 +123,7 @@ func applicationPreAuthorizedResourceCreate(ctx context.Context, d *schema.Resou return applicationPreAuthorizedResourceRead(ctx, d, meta) } -func applicationPreAuthorizedResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationPreAuthorizedResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.ApplicationPreAuthorizedID(d.Id()) if err != nil { @@ -152,7 +152,7 @@ func applicationPreAuthorizedResourceUpdate(ctx context.Context, d *schema.Resou for i, a := range newPreAuthorizedApps { if a.AppId != nil && strings.EqualFold(*a.AppId, id.AppId) { found = true - newPreAuthorizedApps[i].PermissionIds = tf.ExpandStringSlicePtr(d.Get("permission_ids").(*schema.Set).List()) + newPreAuthorizedApps[i].PermissionIds = tf.ExpandStringSlicePtr(d.Get("permission_ids").(*pluginsdk.Set).List()) break } } @@ -176,7 +176,7 @@ func applicationPreAuthorizedResourceUpdate(ctx context.Context, d *schema.Resou return applicationPreAuthorizedResourceRead(ctx, d, meta) } -func applicationPreAuthorizedResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationPreAuthorizedResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.ApplicationPreAuthorizedID(d.Id()) if err != nil { @@ -219,7 +219,7 @@ func applicationPreAuthorizedResourceRead(ctx context.Context, d *schema.Resourc return nil } -func applicationPreAuthorizedResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationPreAuthorizedResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient id, err := parse.ApplicationPreAuthorizedID(d.Id()) if err != nil { diff --git a/internal/services/applications/application_pre_authorized_resource_test.go b/internal/services/applications/application_pre_authorized_resource_test.go index bb46c7e980..8ed54f229d 100644 --- a/internal/services/applications/application_pre_authorized_resource_test.go +++ b/internal/services/applications/application_pre_authorized_resource_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -26,10 +25,10 @@ func TestAccApplicationPreAuthorized_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_pre_authorized", "test") r := ApplicationPreAuthorizedResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("authorized_app_id").Exists(), check.That(data.ResourceName).Key("permission_ids.#").HasValue("2"), @@ -43,10 +42,10 @@ func TestAccApplicationPreAuthorized_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application_pre_authorized", "test") r := ApplicationPreAuthorizedResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/applications/application_published_app_ids_data_source.go b/internal/services/applications/application_published_app_ids_data_source.go index 9827e16566..122376ec8b 100644 --- a/internal/services/applications/application_published_app_ids_data_source.go +++ b/internal/services/applications/application_published_app_ids_data_source.go @@ -9,29 +9,29 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/environments" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) -func applicationPublishedAppIdsDataSource() *schema.Resource { - return &schema.Resource{ - ReadContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics { +func applicationPublishedAppIdsDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ + ReadContext: func(_ context.Context, d *pluginsdk.ResourceData, _ interface{}) diag.Diagnostics { tf.Set(d, "result", environments.PublishedApis) d.SetId("appIds") return nil }, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "result": { Description: "A mapping of application names and application IDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, }, diff --git a/internal/services/applications/application_published_app_ids_data_source_test.go b/internal/services/applications/application_published_app_ids_data_source_test.go index 290f21037e..642217110a 100644 --- a/internal/services/applications/application_published_app_ids_data_source_test.go +++ b/internal/services/applications/application_published_app_ids_data_source_test.go @@ -6,7 +6,6 @@ package applications_test import ( "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,10 +16,10 @@ func TestAccApplicationPublishedAppIdsDataSource_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_application_published_app_ids", "test") r := ApplicationPublishedAppIdsDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("result.%").Exists(), ), }, diff --git a/internal/services/applications/application_resource.go b/internal/services/applications/application_resource.go index 72da062d41..aaeb620686 100644 --- a/internal/services/applications/application_resource.go +++ b/internal/services/applications/application_resource.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "net/url" @@ -17,22 +18,21 @@ import ( "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/migrations" applicationsValidate "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/validate" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const applicationResourceName = "azuread_application" -func applicationResource() *schema.Resource { - return &schema.Resource{ +func applicationResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: applicationResourceCreate, ReadContext: applicationResourceRead, UpdateContext: applicationResourceUpdate, @@ -40,14 +40,14 @@ func applicationResource() *schema.Resource { CustomizeDiff: applicationResourceCustomizeDiff, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(10 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(10 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } @@ -55,7 +55,7 @@ func applicationResource() *schema.Resource { }), SchemaVersion: 1, - StateUpgraders: []schema.StateUpgrader{ + StateUpgraders: []pluginsdk.StateUpgrader{ { Type: migrations.ResourceApplicationInstanceResourceV0().CoreConfigSchema().ImpliedType(), Upgrade: migrations.ResourceApplicationInstanceStateUpgradeV0, @@ -63,74 +63,74 @@ func applicationResource() *schema.Resource { }, }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name for the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "api": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: applicationDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "known_client_applications": { Description: "Used for bundling consent if you have a solution that contains two parts: a client app and a custom web API app", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "mapped_claims_enabled": { Description: "Allows an application to use claims mapping without specifying a custom signing key", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "oauth2_permission_scope": { Description: "One or more `oauth2_permission_scope` blocks to describe delegated permissions exposed by the web API represented by this application", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier of the delegated permission", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "admin_consent_description": { Description: "Delegated permission description that appears in all tenant-wide admin consent experiences, intended to be read by an administrator granting the permission on behalf of all users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "admin_consent_display_name": { Description: "Display name for the delegated permission, intended to be read by an administrator granting the permission on behalf of all users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "enabled": { Description: "Determines if the permission scope is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "type": { Description: "Whether this delegated permission should be considered safe for non-admin users to consent to on behalf of themselves, or whether an administrator should be required for consent to the permissions", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Default: msgraph.PermissionScopeTypeUser, ValidateFunc: validation.StringInSlice([]string{ @@ -141,21 +141,21 @@ func applicationResource() *schema.Resource { "user_consent_description": { Description: "Delegated permission description that appears in the end user consent experience, intended to be read by a user consenting on their own behalf", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "user_consent_display_name": { Description: "Display name for the delegated permission that appears in the end user consent experience", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "value": { Description: "The value that is used for the `scp` claim in OAuth 2.0 access tokens", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateDiagFunc: applicationsValidate.RoleScopeClaimValue, }, @@ -165,7 +165,7 @@ func applicationResource() *schema.Resource { "requested_access_token_version": { Description: "The access token version expected by this resource", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Optional: true, Default: 1, ValidateDiagFunc: func(i interface{}, path cty.Path) (ret diag.Diagnostics) { @@ -193,24 +193,24 @@ func applicationResource() *schema.Resource { }, "app_role": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier of the app role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "allowed_member_types": { Description: "Specifies whether this app role definition can be assigned to users and groups by setting to `User`, or to other applications (that are accessing this application in a standalone scenario) by setting to `Application`, or to both", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Required: true, MinItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice( []string{ msgraph.AppRoleAllowedMemberTypeApplication, @@ -222,28 +222,28 @@ func applicationResource() *schema.Resource { "description": { Description: "Description of the app role that appears when the role is being assigned and, if the role functions as an application permissions, during the consent experiences", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "display_name": { Description: "Display name for the app role that appears during app role assignment and in consent experiences", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "enabled": { Description: "Determines if the app role is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "value": { Description: "The value that is used for the `roles` claim in ID tokens and OAuth 2.0 access tokens that are authenticating an assigned service or user principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateDiagFunc: applicationsValidate.RoleScopeClaimValue, }, @@ -253,61 +253,61 @@ func applicationResource() *schema.Resource { "app_role_ids": { Description: "Mapping of app role names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "description": { Description: "Description of the application as shown to end users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.ValidateDiag(validation.StringLenBetween(0, 1024)), + ValidateDiagFunc: validation2.ValidateDiag(validation.StringLenBetween(0, 1024)), }, "device_only_auth_enabled": { Description: "Specifies whether this application supports device authentication without a user.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "fallback_public_client_enabled": { Description: "Specifies whether the application is a public client. Appropriate for apps using token grant flows that don't use a redirect URI", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "feature_tags": { Description: "Block of features to configure for this application using tags", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ConflictsWith: []string{"tags"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "custom_single_sign_on": { Description: "Whether this application represents a custom SAML application for linked service principals", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "enterprise": { Description: "Whether this application represents an Enterprise Application for linked service principals", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "gallery": { Description: "Whether this application represents a gallery application for linked service principals", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "hide": { Description: "Whether this application is invisible to users in My Apps and Office 365 Launcher", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, }, @@ -316,10 +316,10 @@ func applicationResource() *schema.Resource { "group_membership_claims": { Description: "Configures the `groups` claim issued in a user or OAuth 2.0 access token that the app expects", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.GroupMembershipClaimAll, msgraph.GroupMembershipClaimNone, @@ -332,57 +332,57 @@ func applicationResource() *schema.Resource { "identifier_uris": { Description: "The user-defined URI(s) that uniquely identify an application within its Azure AD tenant, or within a verified custom domain if the application is multi-tenant", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.IsAppUri, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.IsAppUri, }, }, "logo_image": { Description: "Base64 encoded logo image in gif, png or jpeg format", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringIsBase64, }, "marketing_url": { Description: "URL of the application's marketing page", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "notes": { Description: "User-specified notes relevant for the management of the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, // This is a top level attribute because d.SetNewComputed() doesn't work inside a block "oauth2_permission_scope_ids": { Description: "Mapping of OAuth2.0 permission scope names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "oauth2_post_response_required": { Description: "Specifies whether, as part of OAuth 2.0 token requests, Azure AD allows POST requests, as opposed to GET requests.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "optional_claims": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: applicationDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "access_token": schemaOptionalClaims(), "id_token": schemaOptionalClaims(), "saml2_token": schemaOptionalClaims(), @@ -392,37 +392,37 @@ func applicationResource() *schema.Resource { "owners": { Description: "A list of object IDs of principals that will be granted ownership of the application", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Set: schema.HashString, + Set: pluginsdk.HashString, MaxItems: 100, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "privacy_statement_url": { Description: "URL of the application's privacy statement", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "public_client": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: applicationDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, MaxItems: 256, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.IsRedirectUriFunc(true, true), + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.IsRedirectUriFunc(true, true), }, }, }, @@ -430,32 +430,32 @@ func applicationResource() *schema.Resource { }, "required_resource_access": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "resource_app_id": { Description: "", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "resource_access": { Description: "", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "type": { Description: "", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice( []string{ @@ -474,13 +474,13 @@ func applicationResource() *schema.Resource { "service_management_reference": { Description: "References application or service contact information from a Service or Asset Management database", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "sign_in_audience": { Description: "The Microsoft account types that are supported for the current application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Default: msgraph.SignInAudienceAzureADMyOrg, ValidateFunc: validation.StringInSlice([]string{ @@ -492,20 +492,20 @@ func applicationResource() *schema.Resource { }, "single_page_application": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: applicationDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, MaxItems: 256, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.IsRedirectUriFunc(false, false), + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.IsRedirectUriFunc(false, false), }, }, }, @@ -514,85 +514,85 @@ func applicationResource() *schema.Resource { "support_url": { Description: "URL of the application's support page", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "tags": { Description: "A set of tags to apply to the application", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, - Set: schema.HashString, + Set: pluginsdk.HashString, ConflictsWith: []string{"feature_tags"}, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "template_id": { Description: "Unique ID of the application template from which this application is created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "terms_of_service_url": { Description: "URL of the application's terms of service statement", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "web": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: applicationDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "homepage_url": { Description: "Home page or landing page of the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, }, "logout_url": { Description: "The URL that will be used by Microsoft's authorization service to sign out a user using front-channel, back-channel or SAML logout protocols", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.IsLogoutUrl, + ValidateDiagFunc: validation2.IsLogoutUrl, }, "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, MaxItems: 256, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.IsRedirectUriFunc(true, false), + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.IsRedirectUriFunc(true, false), }, }, "implicit_grant": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: applicationDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "access_token_issuance_enabled": { Description: "Whether this web application can request an access token using OAuth 2.0 implicit flow", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "id_token_issuance_enabled": { Description: "Whether this web application can request an ID token using OAuth 2.0 implicit flow", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, }, @@ -604,49 +604,49 @@ func applicationResource() *schema.Resource { "application_id": { Description: "The Application ID (also called Client ID)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The application's object ID", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "logo_url": { Description: "CDN URL to the application's logo", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "prevent_duplicate_names": { Description: "If `true`, will return an error if an existing application is found with the same name", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "publisher_domain": { Description: "The verified publisher domain for the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "disabled_by_microsoft": { Description: "Whether Microsoft has disabled the registered application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func applicationResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func applicationResourceCustomizeDiff(ctx context.Context, diff *pluginsdk.ResourceDiff, meta interface{}) error { client := meta.(*clients.Client).Applications.ApplicationsClient oldDisplayName, newDisplayName := diff.GetChange("display_name") - if diff.Get("prevent_duplicate_names").(bool) && tf.ValueIsNotEmptyOrUnknown(newDisplayName) && + if diff.Get("prevent_duplicate_names").(bool) && pluginsdk.ValueIsNotEmptyOrUnknown(newDisplayName) && (oldDisplayName.(string) == "" || oldDisplayName.(string) != newDisplayName.(string)) { result, err := applicationFindByName(ctx, client, newDisplayName.(string)) if err != nil { @@ -665,7 +665,7 @@ func applicationResourceCustomizeDiff(ctx context.Context, diff *schema.Resource } // Validate roles and scopes to check for duplicate IDs or values - if err := applicationValidateRolesScopes(diff.Get("app_role").(*schema.Set).List(), diff.Get("api.0.oauth2_permission_scope").(*schema.Set).List()); err != nil { + if err := applicationValidateRolesScopes(diff.Get("app_role").(*pluginsdk.Set).List(), diff.Get("api.0.oauth2_permission_scope").(*pluginsdk.Set).List()); err != nil { return fmt.Errorf("checking for duplicate app roles / OAuth2.0 permission scopes: %v", err) } @@ -686,11 +686,11 @@ func applicationResourceCustomizeDiff(ctx context.Context, diff *schema.Resource // These apply only when personal account sign-ins are enabled for an application, and are enforced at plan time to avoid breaking existing // applications that change from AAD (corporate) account sign-ins to personal account sign-ins if s := diff.Get("sign_in_audience").(string); s == msgraph.SignInAudienceAzureADandPersonalMicrosoftAccount || s == msgraph.SignInAudiencePersonalMicrosoftAccount { - oauth2PermissionScopes := diff.Get("api.0.oauth2_permission_scope").(*schema.Set).List() - identifierUris := diff.Get("identifier_uris").(*schema.Set).List() - pubRedirectUris := diff.Get("public_client.0.redirect_uris").(*schema.Set).List() - spaRedirectUris := diff.Get("single_page_application.0.redirect_uris").(*schema.Set).List() - webRedirectUris := diff.Get("web.0.redirect_uris").(*schema.Set).List() + oauth2PermissionScopes := diff.Get("api.0.oauth2_permission_scope").(*pluginsdk.Set).List() + identifierUris := diff.Get("identifier_uris").(*pluginsdk.Set).List() + pubRedirectUris := diff.Get("public_client.0.redirect_uris").(*pluginsdk.Set).List() + spaRedirectUris := diff.Get("single_page_application.0.redirect_uris").(*pluginsdk.Set).List() + webRedirectUris := diff.Get("web.0.redirect_uris").(*pluginsdk.Set).List() allRedirectUris := append(pubRedirectUris, append(spaRedirectUris, webRedirectUris...)...) // applications must use v2 access tokens with personal account sign-ins @@ -734,7 +734,7 @@ func applicationResourceCustomizeDiff(ctx context.Context, diff *schema.Resource } // urn scheme not supported with personal account sign-ins for _, v := range identifierUris { - if diags := validate.IsUriFunc([]string{"http", "https", "api", "ms-appx"}, false, false, false)(v, cty.Path{}); diags.HasError() { + if diags := validation2.IsUriFunc([]string{"http", "https", "api", "ms-appx"}, false, false, false)(v, cty.Path{}); diags.HasError() { return fmt.Errorf("`identifier_uris` is invalid. The URN scheme is not supported when `sign_in_audience` is %q or %q", msgraph.SignInAudienceAzureADandPersonalMicrosoftAccount, msgraph.SignInAudiencePersonalMicrosoftAccount) } @@ -767,7 +767,7 @@ func applicationResourceCustomizeDiff(ctx context.Context, diff *schema.Resource // 50 resources per application // 30 permissions per resource // 200 permissions per application - requiredResourceAccess := diff.Get("required_resource_access").(*schema.Set).List() + requiredResourceAccess := diff.Get("required_resource_access").(*pluginsdk.Set).List() if len(requiredResourceAccess) > 50 { return fmt.Errorf("maximum of 50 `required_resource_access` blocks are supported when `sign_in_audience` is %q or %q", msgraph.SignInAudienceAzureADandPersonalMicrosoftAccount, msgraph.SignInAudiencePersonalMicrosoftAccount) @@ -800,7 +800,7 @@ func applicationResourceCustomizeDiff(ctx context.Context, diff *schema.Resource return nil } -func applicationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { +func applicationDiffSuppress(k, old, new string, d *pluginsdk.ResourceData) bool { suppress := false switch { @@ -809,13 +809,13 @@ func applicationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { if len(apiRaw) == 1 { suppress = true api := apiRaw[0].(map[string]interface{}) - if v, ok := api["known_client_applications"]; ok && len(v.(*schema.Set).List()) > 0 { + if v, ok := api["known_client_applications"]; ok && len(v.(*pluginsdk.Set).List()) > 0 { suppress = false } if v, ok := api["mapped_claims_enabled"]; ok && v.(bool) { suppress = false } - if v, ok := api["oauth2_permission_scope"]; ok && len(v.(*schema.Set).List()) > 0 { + if v, ok := api["oauth2_permission_scope"]; ok && len(v.(*pluginsdk.Set).List()) > 0 { suppress = false } if v, ok := api["requested_access_token_version"]; ok && v.(int) > 1 { @@ -844,7 +844,7 @@ func applicationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { if len(publicClientRaw) == 1 { suppress = true publicClient := publicClientRaw[0].(map[string]interface{}) - if v, ok := publicClient["redirect_uris"]; ok && len(v.(*schema.Set).List()) > 0 { + if v, ok := publicClient["redirect_uris"]; ok && len(v.(*pluginsdk.Set).List()) > 0 { suppress = false } } @@ -854,7 +854,7 @@ func applicationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { if len(spaRaw) == 1 { suppress = true spa := spaRaw[0].(map[string]interface{}) - if v, ok := spa["redirect_uris"]; ok && len(v.(*schema.Set).List()) > 0 { + if v, ok := spa["redirect_uris"]; ok && len(v.(*pluginsdk.Set).List()) > 0 { suppress = false } } @@ -864,7 +864,7 @@ func applicationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { if len(webRaw) == 1 { suppress = true web := webRaw[0].(map[string]interface{}) - if v, ok := web["redirect_uris"]; ok && len(v.(*schema.Set).List()) > 0 { + if v, ok := web["redirect_uris"]; ok && len(v.(*pluginsdk.Set).List()) > 0 { suppress = false } if b, ok := web["implicit_grant"]; ok { @@ -897,7 +897,7 @@ func applicationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { return suppress } -func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient appTemplatesClient := meta.(*clients.Client).Applications.ApplicationTemplatesClient directoryObjectsClient := meta.(*clients.Client).Applications.DirectoryObjectsClient @@ -935,7 +935,7 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk("feature_tags"); ok { tags = helpers.ApplicationExpandFeatures(v.([]interface{})) } else { - tags = tf.ExpandStringSlice(d.Get("tags").(*schema.Set).List()) + tags = tf.ExpandStringSlice(d.Get("tags").(*pluginsdk.Set).List()) } if templateId != "" { @@ -976,11 +976,11 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta // Create a new application properties := msgraph.Application{ Api: api, - AppRoles: expandApplicationAppRoles(d.Get("app_role").(*schema.Set).List()), + AppRoles: expandApplicationAppRoles(d.Get("app_role").(*pluginsdk.Set).List()), Description: utils.NullableString(d.Get("description").(string)), DisplayName: utils.String(displayName), - GroupMembershipClaims: expandApplicationGroupMembershipClaims(d.Get("group_membership_claims").(*schema.Set).List()), - IdentifierUris: tf.ExpandStringSlicePtr(d.Get("identifier_uris").(*schema.Set).List()), + GroupMembershipClaims: expandApplicationGroupMembershipClaims(d.Get("group_membership_claims").(*pluginsdk.Set).List()), + IdentifierUris: tf.ExpandStringSlicePtr(d.Get("identifier_uris").(*pluginsdk.Set).List()), Info: &msgraph.InformationalUrl{ MarketingUrl: utils.String(d.Get("marketing_url").(string)), PrivacyStatementUrl: utils.String(d.Get("privacy_statement_url").(string)), @@ -993,7 +993,7 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta Oauth2RequirePostResponse: utils.Bool(d.Get("oauth2_post_response_required").(bool)), OptionalClaims: expandApplicationOptionalClaims(d.Get("optional_claims").([]interface{})), PublicClient: expandApplicationPublicClient(d.Get("public_client").([]interface{})), - RequiredResourceAccess: expandApplicationRequiredResourceAccess(d.Get("required_resource_access").(*schema.Set).List()), + RequiredResourceAccess: expandApplicationRequiredResourceAccess(d.Get("required_resource_access").(*pluginsdk.Set).List()), ServiceManagementReference: utils.NullableString(d.Get("service_management_reference").(string)), SignInAudience: utils.String(d.Get("sign_in_audience").(string)), Spa: expandApplicationSpa(d.Get("single_page_application").([]interface{})), @@ -1024,7 +1024,7 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta // Retrieve and set the initial owners, which can be up to 20 in total when creating the application if v, ok := d.GetOk("owners"); ok { ownerCount := 0 - for _, ownerIdRaw := range v.(*schema.Set).List() { + for _, ownerIdRaw := range v.(*pluginsdk.Set).List() { ownerId := ownerIdRaw.(string) // If the calling principal was found in the specified owners, we won't remove them later @@ -1124,7 +1124,7 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta return applicationResourceRead(ctx, d, meta) } -func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient tenantId := meta.(*clients.Client).TenantID applicationId := d.Id() @@ -1163,7 +1163,7 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk("feature_tags"); ok && len(v.([]interface{})) > 0 && d.HasChange("feature_tags") { tags = helpers.ApplicationExpandFeatures(v.([]interface{})) } else { - tags = tf.ExpandStringSlice(d.Get("tags").(*schema.Set).List()) + tags = tf.ExpandStringSlice(d.Get("tags").(*pluginsdk.Set).List()) } properties := msgraph.Application{ @@ -1171,11 +1171,11 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta Id: utils.String(applicationId), }, Api: expandApplicationApi(d.Get("api").([]interface{})), - AppRoles: expandApplicationAppRoles(d.Get("app_role").(*schema.Set).List()), + AppRoles: expandApplicationAppRoles(d.Get("app_role").(*pluginsdk.Set).List()), Description: utils.NullableString(d.Get("description").(string)), DisplayName: utils.String(displayName), - GroupMembershipClaims: expandApplicationGroupMembershipClaims(d.Get("group_membership_claims").(*schema.Set).List()), - IdentifierUris: tf.ExpandStringSlicePtr(d.Get("identifier_uris").(*schema.Set).List()), + GroupMembershipClaims: expandApplicationGroupMembershipClaims(d.Get("group_membership_claims").(*pluginsdk.Set).List()), + IdentifierUris: tf.ExpandStringSlicePtr(d.Get("identifier_uris").(*pluginsdk.Set).List()), Info: &msgraph.InformationalUrl{ MarketingUrl: utils.String(d.Get("marketing_url").(string)), PrivacyStatementUrl: utils.String(d.Get("privacy_statement_url").(string)), @@ -1188,7 +1188,7 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta Oauth2RequirePostResponse: utils.Bool(d.Get("oauth2_post_response_required").(bool)), OptionalClaims: expandApplicationOptionalClaims(d.Get("optional_claims").([]interface{})), PublicClient: expandApplicationPublicClient(d.Get("public_client").([]interface{})), - RequiredResourceAccess: expandApplicationRequiredResourceAccess(d.Get("required_resource_access").(*schema.Set).List()), + RequiredResourceAccess: expandApplicationRequiredResourceAccess(d.Get("required_resource_access").(*pluginsdk.Set).List()), ServiceManagementReference: utils.NullableString(d.Get("service_management_reference").(string)), SignInAudience: utils.String(d.Get("sign_in_audience").(string)), Spa: expandApplicationSpa(d.Get("single_page_application").([]interface{})), @@ -1196,11 +1196,11 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta Web: expandApplicationWeb(d.Get("web").([]interface{})), } - if err := applicationDisableAppRoles(ctx, client, &properties, expandApplicationAppRoles(d.Get("app_role").(*schema.Set).List())); err != nil { + if err := applicationDisableAppRoles(ctx, client, &properties, expandApplicationAppRoles(d.Get("app_role").(*pluginsdk.Set).List())); err != nil { return tf.ErrorDiagPathF(err, "app_role", "Could not disable App Roles for application with object ID %q", d.Id()) } - if err := applicationDisableOauth2PermissionScopes(ctx, client, &properties, expandApplicationOAuth2PermissionScope(d.Get("api.0.oauth2_permission_scope").(*schema.Set).List())); err != nil { + if err := applicationDisableOauth2PermissionScopes(ctx, client, &properties, expandApplicationOAuth2PermissionScope(d.Get("api.0.oauth2_permission_scope").(*pluginsdk.Set).List())); err != nil { return tf.ErrorDiagPathF(err, "api.0.oauth2_permission_scope", "Could not disable OAuth2 Permission Scopes for application with object ID %q", d.Id()) } @@ -1214,7 +1214,7 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta return tf.ErrorDiagF(err, "Could not retrieve owners for application with object ID: %q", d.Id()) } - desiredOwners := *tf.ExpandStringSlicePtr(d.Get("owners").(*schema.Set).List()) + desiredOwners := *tf.ExpandStringSlicePtr(d.Get("owners").(*pluginsdk.Set).List()) existingOwners := *owners ownersForRemoval := utils.Difference(existingOwners, desiredOwners) ownersToAdd := utils.Difference(desiredOwners, existingOwners) @@ -1253,7 +1253,7 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta return applicationResourceRead(ctx, d, meta) } -func applicationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient app, status, err := client.Get(ctx, d.Id(), odata.Query{}) @@ -1326,7 +1326,7 @@ func applicationResourceRead(ctx context.Context, d *schema.ResourceData, meta i return nil } -func applicationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationsClient appId := d.Id() diff --git a/internal/services/applications/application_resource_test.go b/internal/services/applications/application_resource_test.go index 4c3aa33db4..40a15a8aa3 100644 --- a/internal/services/applications/application_resource_test.go +++ b/internal/services/applications/application_resource_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -25,10 +24,10 @@ func TestAccApplication_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -43,10 +42,10 @@ func TestAccApplication_basicFromTemplate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicFromTemplate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -62,10 +61,10 @@ func TestAccApplication_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -79,10 +78,10 @@ func TestAccApplication_completeFromTemplate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.completeFromTemplate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -99,10 +98,10 @@ func TestAccApplication_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -111,7 +110,7 @@ func TestAccApplication_update(t *testing.T) { data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -120,7 +119,7 @@ func TestAccApplication_update(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("application_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), @@ -138,10 +137,10 @@ func TestAccApplication_appRoles(t *testing.T) { data.UUID(), } - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_role.#").HasValue("0"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("0"), @@ -150,7 +149,7 @@ func TestAccApplication_appRoles(t *testing.T) { data.ImportStep(), { Config: r.appRoleNoValue(data, roleIDs), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_role.#").HasValue("1"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("0"), @@ -159,7 +158,7 @@ func TestAccApplication_appRoles(t *testing.T) { data.ImportStep(), { Config: r.appRole(data, roleIDs), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_role.#").HasValue("1"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("1"), @@ -168,7 +167,7 @@ func TestAccApplication_appRoles(t *testing.T) { data.ImportStep(), { Config: r.appRolesUpdate(data, roleIDs), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_role.#").HasValue("2"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("2"), @@ -177,7 +176,7 @@ func TestAccApplication_appRoles(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_role.#").HasValue("0"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("0"), @@ -191,10 +190,10 @@ func TestAccApplication_duplicateAppRolesOauth2PermissionsIdsUnknown(t *testing. data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.duplicateAppRolesOauth2PermissionsIdsUnknown(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("app_role.#").HasValue("1"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("1"), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("1"), @@ -208,7 +207,7 @@ func TestAccApplication_duplicateAppRolesOauth2PermissionsValues(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.duplicateAppRolesOauth2PermissionsValues(data), ExpectError: regexp.MustCompile("validation failed: duplicate value found:"), @@ -220,10 +219,10 @@ func TestAccApplication_duplicateAppRolesOauth2PermissionsMatchingIdAndValueWith data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.duplicateAppRolesOauth2PermissionsMatchingIdAndValueWithCommonMetadata(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("app_role.#").HasValue("1"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("1"), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("1"), @@ -237,7 +236,7 @@ func TestAccApplication_duplicateAppRolesOauth2PermissionsMatchingIdAndValueWith data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.duplicateAppRolesOauth2PermissionsMatchingIdAndValueWithMismatchingMetadata(data), ExpectError: regexp.MustCompile("validation failed: The following values must match for the"), @@ -249,24 +248,24 @@ func TestAccApplication_groupMembershipClaimsUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.withGroupMembershipClaims(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -283,10 +282,10 @@ func TestAccApplication_oauth2PermissionScopes(t *testing.T) { data.UUID(), } - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("0"), check.That(data.ResourceName).Key("oauth2_permission_scope_ids.%").HasValue("0"), @@ -295,7 +294,7 @@ func TestAccApplication_oauth2PermissionScopes(t *testing.T) { data.ImportStep(), { Config: r.oauth2PermissionScopes(data, scopeIDs), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("2"), check.That(data.ResourceName).Key("oauth2_permission_scope_ids.%").HasValue("2"), @@ -304,7 +303,7 @@ func TestAccApplication_oauth2PermissionScopes(t *testing.T) { data.ImportStep(), { Config: r.oauth2PermissionScopesUpdate(data, scopeIDs), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("3"), check.That(data.ResourceName).Key("oauth2_permission_scope_ids.%").HasValue("3"), @@ -313,7 +312,7 @@ func TestAccApplication_oauth2PermissionScopes(t *testing.T) { data.ImportStep(), { Config: r.oauth2PermissionScopes(data, scopeIDs), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("2"), check.That(data.ResourceName).Key("oauth2_permission_scope_ids.%").HasValue("2"), @@ -322,7 +321,7 @@ func TestAccApplication_oauth2PermissionScopes(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("api.0.oauth2_permission_scope.#").HasValue("0"), check.That(data.ResourceName).Key("oauth2_permission_scope_ids.%").HasValue("0"), @@ -336,10 +335,10 @@ func TestAccApplication_owners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -347,7 +346,7 @@ func TestAccApplication_owners(t *testing.T) { data.ImportStep(), { Config: r.singleOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -355,7 +354,7 @@ func TestAccApplication_owners(t *testing.T) { data.ImportStep(), { Config: r.noOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -363,7 +362,7 @@ func TestAccApplication_owners(t *testing.T) { data.ImportStep(), { Config: r.singleOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -371,7 +370,7 @@ func TestAccApplication_owners(t *testing.T) { data.ImportStep(), { Config: r.threeOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("3"), ), @@ -379,7 +378,7 @@ func TestAccApplication_owners(t *testing.T) { data.ImportStep(), { Config: r.noOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -392,10 +391,10 @@ func TestAccApplication_createWithNoOwners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.noOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -408,10 +407,10 @@ func TestAccApplication_manyOwners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.manyOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("45"), ), @@ -424,10 +423,10 @@ func TestAccApplication_preventDuplicateNamesPass(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.preventDuplicateNamesPass(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -439,7 +438,7 @@ func TestAccApplication_preventDuplicateNamesFail(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ data.RequiresImportErrorStep(r.preventDuplicateNamesFail(data)), }) } @@ -454,17 +453,17 @@ func TestAccApplication_related(t *testing.T) { data.UUID(), } - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.related(data, uuids), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.relatedUpdate(data, uuids), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -476,10 +475,10 @@ func TestAccApplication_featureTags(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -491,66 +490,66 @@ func TestAccApplication_featureTagsUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.noFeatureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.tags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.noFeatureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -562,24 +561,24 @@ func TestAccApplication_logo(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_application", "test") r := ApplicationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.logo(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("logo"), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.logo(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/applications/application_template_data_source.go b/internal/services/applications/application_template_data_source.go index 4bc0b009c0..2987782f40 100644 --- a/internal/services/applications/application_template_data_source.go +++ b/internal/services/applications/application_template_data_source.go @@ -12,89 +12,89 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func applicationTemplateDataSource() *schema.Resource { - return &schema.Resource{ +func applicationTemplateDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: applicationTemplateDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "template_id": { Description: "The application template's ID", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "template_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "The display name for the application template", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "template_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "categories": { Description: "List of categories for this templated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "homepage_url": { Description: "Home page URL of the templated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "logo_url": { Description: "URL to retrieve the logo for this templated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "publisher": { Description: "Name of the publisher for this templated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "supported_provisioning_types": { Description: "The provisioning modes supported by this templated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "supported_single_sign_on_modes": { Description: "The single sign on modes supported by this templated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, }, } } -func applicationTemplateDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func applicationTemplateDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Applications.ApplicationTemplatesClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/applications/application_template_data_source_test.go b/internal/services/applications/application_template_data_source_test.go index 98fb33169b..ad132b2b1a 100644 --- a/internal/services/applications/application_template_data_source_test.go +++ b/internal/services/applications/application_template_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -24,7 +23,7 @@ func TestAccApplicationTemplateDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_application_template", "test") r := ApplicationTemplateDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayName(data), Check: r.testCheck(data), @@ -36,7 +35,7 @@ func TestAccApplicationTemplateDataSource_byTemplateId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_application_template", "test") r := ApplicationTemplateDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byTemplateId(data), Check: r.testCheck(data), @@ -44,8 +43,8 @@ func TestAccApplicationTemplateDataSource_byTemplateId(t *testing.T) { }) } -func (ApplicationTemplateDataSource) testCheck(data acceptance.TestData) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( +func (ApplicationTemplateDataSource) testCheck(data acceptance.TestData) acceptance.TestCheckFunc { + return acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("template_id").HasValue(testApplicationTemplateId), check.That(data.ResourceName).Key("display_name").HasValue(testApplicationTemplateDisplayName), check.That(data.ResourceName).Key("categories.#").Exists(), diff --git a/internal/services/applications/applications.go b/internal/services/applications/applications.go index 160c50a6bf..db2de9d989 100644 --- a/internal/services/applications/applications.go +++ b/internal/services/applications/applications.go @@ -13,10 +13,9 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) @@ -124,7 +123,7 @@ func applicationDisableAppRoles(ctx context.Context, client *msgraph.Application return fmt.Errorf("context has no deadline") } timeout := time.Until(deadline) - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Disabled"}, Timeout: timeout, @@ -241,7 +240,7 @@ func applicationDisableOauth2PermissionScopes(ctx context.Context, client *msgra return fmt.Errorf("context has no deadline") } timeout := time.Until(deadline) - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Disabled"}, Timeout: timeout, @@ -333,7 +332,7 @@ func applicationValidateRolesScopes(appRoles, oauth2Permissions []interface{}) e enabled: role["enabled"].(bool), value: role["value"].(string), } - if tf.ValueIsNotEmptyOrUnknown(permission.id) && tf.ValueIsNotEmptyOrUnknown(permission.value) { + if pluginsdk.ValueIsNotEmptyOrUnknown(permission.id) && pluginsdk.ValueIsNotEmptyOrUnknown(permission.value) { appPermissions = append(appPermissions, permission) } } @@ -350,7 +349,7 @@ func applicationValidateRolesScopes(appRoles, oauth2Permissions []interface{}) e enabled: scope["enabled"].(bool), value: scope["value"].(string), } - if tf.ValueIsNotEmptyOrUnknown(permission.id) && tf.ValueIsNotEmptyOrUnknown(permission.value) { + if pluginsdk.ValueIsNotEmptyOrUnknown(permission.id) && pluginsdk.ValueIsNotEmptyOrUnknown(permission.value) { appPermissions = append(appPermissions, permission) } } @@ -394,9 +393,9 @@ func expandApplicationApi(input []interface{}) (result *msgraph.ApplicationApi) result.AcceptMappedClaims = utils.Bool(v.(bool)) } if v, ok := in["known_client_applications"]; ok { - result.KnownClientApplications = tf.ExpandStringSlicePtr(v.(*schema.Set).List()) + result.KnownClientApplications = tf.ExpandStringSlicePtr(v.(*pluginsdk.Set).List()) } - result.OAuth2PermissionScopes = expandApplicationOAuth2PermissionScope(in["oauth2_permission_scope"].(*schema.Set).List()) + result.OAuth2PermissionScopes = expandApplicationOAuth2PermissionScope(in["oauth2_permission_scope"].(*pluginsdk.Set).List()) if v, ok := in["requested_access_token_version"]; ok { result.RequestedAccessTokenVersion = utils.Int32(int32(v.(int))) } @@ -418,7 +417,7 @@ func expandApplicationAppRoles(input []interface{}) *[]msgraph.AppRole { appRole := appRoleRaw.(map[string]interface{}) var allowedMemberTypes []msgraph.AppRoleAllowedMemberType - for _, allowedMemberType := range appRole["allowed_member_types"].(*schema.Set).List() { + for _, allowedMemberType := range appRole["allowed_member_types"].(*pluginsdk.Set).List() { allowedMemberTypes = append(allowedMemberTypes, allowedMemberType.(string)) } @@ -550,7 +549,7 @@ func expandApplicationPublicClient(input []interface{}) (result *msgraph.PublicC } in := input[0].(map[string]interface{}) - result.RedirectUris = tf.ExpandStringSlicePtr(in["redirect_uris"].(*schema.Set).List()) + result.RedirectUris = tf.ExpandStringSlicePtr(in["redirect_uris"].(*pluginsdk.Set).List()) return } @@ -603,7 +602,7 @@ func expandApplicationSpa(input []interface{}) (result *msgraph.ApplicationSpa) } in := input[0].(map[string]interface{}) - result.RedirectUris = tf.ExpandStringSlicePtr(in["redirect_uris"].(*schema.Set).List()) + result.RedirectUris = tf.ExpandStringSlicePtr(in["redirect_uris"].(*pluginsdk.Set).List()) return } @@ -624,7 +623,7 @@ func expandApplicationWeb(input []interface{}) (result *msgraph.ApplicationWeb) result.HomePageUrl = utils.NullableString(in["homepage_url"].(string)) result.LogoutUrl = utils.NullableString(in["logout_url"].(string)) result.ImplicitGrantSettings = expandApplicationImplicitGrantSettings(in["implicit_grant"].([]interface{})) - result.RedirectUris = tf.ExpandStringSlicePtr(in["redirect_uris"].(*schema.Set).List()) + result.RedirectUris = tf.ExpandStringSlicePtr(in["redirect_uris"].(*pluginsdk.Set).List()) return } diff --git a/internal/services/applications/migrations/application_password_resource.go b/internal/services/applications/migrations/application_password_resource.go index 06a791c980..1b436df436 100644 --- a/internal/services/applications/migrations/application_password_resource.go +++ b/internal/services/applications/migrations/application_password_resource.go @@ -8,39 +8,38 @@ import ( "fmt" "log" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/parse" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" ) -func ResourceApplicationPasswordInstanceResourceV0() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ +func ResourceApplicationPasswordInstanceResourceV0() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "application_object_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "key_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, }, "value": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, Sensitive: true, @@ -48,7 +47,7 @@ func ResourceApplicationPasswordInstanceResourceV0() *schema.Resource { }, "start_date": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -56,7 +55,7 @@ func ResourceApplicationPasswordInstanceResourceV0() *schema.Resource { }, "end_date": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -65,11 +64,11 @@ func ResourceApplicationPasswordInstanceResourceV0() *schema.Resource { }, "end_date_relative": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ExactlyOneOf: []string{"end_date"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, } diff --git a/internal/services/applications/migrations/application_resource.go b/internal/services/applications/migrations/application_resource.go index e2a45836f2..f3141a19d1 100644 --- a/internal/services/applications/migrations/application_resource.go +++ b/internal/services/applications/migrations/application_resource.go @@ -5,71 +5,71 @@ package migrations import ( "context" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" applicationsValidate "github.com/hashicorp/terraform-provider-azuread/internal/services/applications/validate" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func ResourceApplicationInstanceResourceV0() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ +func ResourceApplicationInstanceResourceV0() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "name"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, Deprecated: "This property has been renamed to `display_name` and will be removed in version 2.0 of the AzureAD provider", ExactlyOneOf: []string{"display_name", "name"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "api": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "oauth2_permission_scope": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "admin_consent_description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "admin_consent_display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "type": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Default: msgraph.PermissionScopeTypeUser, ValidateFunc: validation.StringInSlice([]string{ @@ -79,19 +79,19 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "user_consent_description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "user_consent_display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "value": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateDiagFunc: applicationsValidate.RoleScopeClaimValue, }, @@ -103,23 +103,23 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "app_role": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, - ConfigMode: schema.SchemaConfigModeAttr, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + ConfigMode: pluginsdk.SchemaConfigModeAttr, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "allowed_member_types": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Required: true, MinItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice( []string{ msgraph.AppRoleAllowedMemberTypeApplication, @@ -130,32 +130,32 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "is_enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, Deprecated: "[NOTE] This attribute has been renamed to `enabled` and will be removed in version 2.0 of the AzureAD provider", }, "value": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateDiagFunc: applicationsValidate.RoleScopeClaimValue, @@ -165,7 +165,7 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "available_to_other_tenants": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, ConflictsWith: []string{"sign_in_audience"}, @@ -173,14 +173,14 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "fallback_public_client_enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, ConflictsWith: []string{"public_client"}, }, "group_membership_claims": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Deprecated: "[NOTE] This attribute will become a list in version 2.0 of the AzureAD provider", ValidateFunc: validation.StringInSlice([]string{ @@ -193,35 +193,35 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "homepage": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, ConflictsWith: []string{"web.0.homepage_url"}, Deprecated: "[NOTE] This attribute will be replaced by a new attribute `homepage_url` in the `web` block in version 2.0 of the AzureAD provider", }, "identifier_uris": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.IsAppUri, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.IsAppUri, }, }, "logout_url": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, Computed: true, ConflictsWith: []string{"web.0.logout_url"}, Deprecated: "[NOTE] This attribute will be moved into the `web` block in version 2.0 of the AzureAD provider", }, "oauth2_allow_implicit_flow": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, ConflictsWith: []string{"web.0.implicit_grant.0.access_token_issuance_enabled"}, @@ -229,85 +229,85 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "oauth2_permissions": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, - ConfigMode: schema.SchemaConfigModeAttr, + ConfigMode: pluginsdk.SchemaConfigModeAttr, Deprecated: "[NOTE] The `oauth2_permissions` block has been renamed to `oauth2_permission_scope` and moved to the `api` block. `oauth2_permissions` will be removed in version 2.0 of the AzureAD provider.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "admin_consent_description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "admin_consent_display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "is_enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, }, "type": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.StringInSlice([]string{"Admin", "User"}, false), }, "user_consent_description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, }, "user_consent_display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, }, "value": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, }, "optional_claims": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "access_token": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "source": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice( []string{"user"}, @@ -315,15 +315,15 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { ), }, "essential": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "additional_properties": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice( []string{ "dns_domain_and_sam_account_name", @@ -343,17 +343,17 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "id_token": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "source": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice( []string{"user"}, @@ -361,15 +361,15 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { ), }, "essential": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "additional_properties": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice( []string{ "dns_domain_and_sam_account_name", @@ -392,17 +392,17 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "owners": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "public_client": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, ConflictsWith: []string{"fallback_public_client_enabled"}, @@ -410,40 +410,40 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "reply_urls": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, ConflictsWith: []string{"web.0.redirect_uris"}, Deprecated: "[NOTE] This attribute will be replaced by a new attribute `redirect_uris` in the `web` block in version 2.0 of the AzureAD provider", - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "required_resource_access": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "resource_app_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "resource_access": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "type": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice( []string{ @@ -461,7 +461,7 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "sign_in_audience": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ConflictsWith: []string{"available_to_other_tenants"}, @@ -472,7 +472,7 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "type": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Deprecated: "[NOTE] This legacy property is deprecated and will be removed in version 2.0 of the AzureAD provider", ValidateFunc: validation.StringInSlice([]string{"webapp/api", "native"}, false), @@ -480,44 +480,44 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "web": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "homepage_url": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ConflictsWith: []string{"homepage"}, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, }, "logout_url": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ConflictsWith: []string{"logout_url"}, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, }, "redirect_uris": { - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, ConflictsWith: []string{"reply_urls"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "implicit_grant": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "access_token_issuance_enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ConflictsWith: []string{"oauth2_allow_implicit_flow"}, }, @@ -529,17 +529,17 @@ func ResourceApplicationInstanceResourceV0() *schema.Resource { }, "application_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "prevent_duplicate_names": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, diff --git a/internal/services/applications/registration.go b/internal/services/applications/registration.go index 970d495dc0..4fde548c94 100644 --- a/internal/services/applications/registration.go +++ b/internal/services/applications/registration.go @@ -3,9 +3,7 @@ package applications -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,8 +20,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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_application": applicationDataSource(), "azuread_application_published_app_ids": applicationPublishedAppIdsDataSource(), "azuread_application_template": applicationTemplateDataSource(), @@ -31,8 +29,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_application": applicationResource(), "azuread_application_certificate": applicationCertificateResource(), "azuread_application_federated_identity_credential": applicationFederatedIdentityCredentialResource(), diff --git a/internal/services/applications/schema.go b/internal/services/applications/schema.go index 2b98711f7c..5de9a5558e 100644 --- a/internal/services/applications/schema.go +++ b/internal/services/applications/schema.go @@ -4,25 +4,25 @@ package applications import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" ) -func schemaOptionalClaims() *schema.Schema { - return &schema.Schema{ - Type: schema.TypeList, +func schemaOptionalClaims() *pluginsdk.Schema { + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "name": { Description: "The name of the optional claim", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "source": { Description: "The source of the claim. If `source` is absent, the claim is a predefined optional claim. If `source` is `user`, the value of `name` is the extension property from the user object", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice( []string{"user"}, @@ -32,17 +32,17 @@ func schemaOptionalClaims() *schema.Schema { "essential": { Description: "Whether the claim specified by the client is necessary to ensure a smooth authorization experience", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "additional_properties": { Description: "List of additional properties of the claim. If a property exists in this list, it modifies the behaviour of the optional claim", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice( []string{ "cloud_displayname", diff --git a/internal/services/approleassignments/app_role_assignment_resource.go b/internal/services/approleassignments/app_role_assignment_resource.go index bcda271190..9c39c707c0 100644 --- a/internal/services/approleassignments/app_role_assignment_resource.go +++ b/internal/services/approleassignments/app_role_assignment_resource.go @@ -13,79 +13,79 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/services/approleassignments/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func appRoleAssignmentResource() *schema.Resource { - return &schema.Resource{ +func appRoleAssignmentResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: appRoleAssignmentResourceCreate, ReadContext: appRoleAssignmentResourceRead, DeleteContext: appRoleAssignmentResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.AppRoleAssignmentID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "app_role_id": { Description: "The ID of the app role to be assigned", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "principal_object_id": { Description: "The object ID of the user, group or service principal to be assigned this app role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "resource_object_id": { Description: "The object ID of the service principal representing the resource", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "principal_display_name": { Description: "The display name of the principal to which the app role is assigned", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "principal_type": { Description: "The object type of the principal to which the app role is assigned", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "resource_display_name": { Description: "The display name of the application representing the resource", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func appRoleAssignmentResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func appRoleAssignmentResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AppRoleAssignments.AppRoleAssignedToClient servicePrincipalsClient := meta.(*clients.Client).AppRoleAssignments.ServicePrincipalsClient @@ -123,7 +123,7 @@ func appRoleAssignmentResourceCreate(ctx context.Context, d *schema.ResourceData return appRoleAssignmentResourceRead(ctx, d, meta) } -func appRoleAssignmentResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func appRoleAssignmentResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AppRoleAssignments.AppRoleAssignedToClient id, err := parse.AppRoleAssignmentID(d.Id()) @@ -168,7 +168,7 @@ func appRoleAssignmentResourceRead(ctx context.Context, d *schema.ResourceData, return nil } -func appRoleAssignmentResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func appRoleAssignmentResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).AppRoleAssignments.AppRoleAssignedToClient id, err := parse.AppRoleAssignmentID(d.Id()) diff --git a/internal/services/approleassignments/app_role_assignment_resource_test.go b/internal/services/approleassignments/app_role_assignment_resource_test.go index 5803a20d64..50ec3d0a8c 100644 --- a/internal/services/approleassignments/app_role_assignment_resource_test.go +++ b/internal/services/approleassignments/app_role_assignment_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -25,10 +24,10 @@ func TestAccAppRoleAssignment_servicePrincipalForMsGraph(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_app_role_assignment", "test") r := AppRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipalForMsGraph(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -40,10 +39,10 @@ func TestAccAppRoleAssignment_servicePrincipalForTenantApp(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_app_role_assignment", "test_admin") r := AppRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipalForTenantApp(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That("azuread_app_role_assignment.test_query").ExistsInAzure(r), ), @@ -56,10 +55,10 @@ func TestAccAppRoleAssignment_groupForTenantApp(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_app_role_assignment", "test") r := AppRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.groupForTenantApp(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -71,10 +70,10 @@ func TestAccAppRoleAssignment_groupForTenantAppWithoutRole(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_app_role_assignment", "test") r := AppRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.groupForTenantAppWithoutRole(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -86,10 +85,10 @@ func TestAccAppRoleAssignment_userForTenantApp(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_app_role_assignment", "test") r := AppRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.userForTenantApp(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/approleassignments/registration.go b/internal/services/approleassignments/registration.go index d3ea5a4217..13275c750d 100644 --- a/internal/services/approleassignments/registration.go +++ b/internal/services/approleassignments/registration.go @@ -3,9 +3,7 @@ package approleassignments -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,13 +20,13 @@ 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{} +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_app_role_assignment": appRoleAssignmentResource(), } } diff --git a/internal/services/conditionalaccess/conditional_access_policy_resource.go b/internal/services/conditionalaccess/conditional_access_policy_resource.go index d38029e97b..47a132047e 100644 --- a/internal/services/conditionalaccess/conditional_access_policy_resource.go +++ b/internal/services/conditionalaccess/conditional_access_policy_resource.go @@ -14,19 +14,17 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func conditionalAccessPolicyResource() *schema.Resource { - return &schema.Resource{ +func conditionalAccessPolicyResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: conditionalAccessPolicyResourceCreate, ReadContext: conditionalAccessPolicyResourceRead, UpdateContext: conditionalAccessPolicyResourceUpdate, @@ -34,29 +32,29 @@ func conditionalAccessPolicyResource() *schema.Resource { CustomizeDiff: conditionalAccessPolicyCustomizeDiff, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(15 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(15 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "state": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessPolicyStateDisabled, @@ -66,43 +64,43 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "conditions": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "applications": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "included_applications": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, ExactlyOneOf: []string{"conditions.0.applications.0.included_applications", "conditions.0.applications.0.included_user_actions"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "excluded_applications": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "included_user_actions": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, ExactlyOneOf: []string{"conditions.0.applications.0.included_applications", "conditions.0.applications.0.included_user_actions"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -110,26 +108,26 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "client_applications": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "included_service_principals": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "excluded_service_principals": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -137,65 +135,65 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "users": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "included_users": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, AtLeastOneOf: []string{"conditions.0.users.0.included_groups", "conditions.0.users.0.included_roles", "conditions.0.users.0.included_users"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "excluded_users": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "included_groups": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, AtLeastOneOf: []string{"conditions.0.users.0.included_groups", "conditions.0.users.0.included_roles", "conditions.0.users.0.included_users"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "excluded_groups": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "included_roles": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, AtLeastOneOf: []string{"conditions.0.users.0.included_groups", "conditions.0.users.0.included_roles", "conditions.0.users.0.included_users"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "excluded_roles": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -203,10 +201,10 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "client_app_types": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessClientAppTypeAll, msgraph.ConditionalAccessClientAppTypeBrowser, @@ -219,19 +217,19 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "devices": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "filter": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "mode": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessFilterModeExclude, @@ -240,9 +238,9 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "rule": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -252,26 +250,26 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "locations": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "included_locations": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "excluded_locations": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -279,16 +277,16 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "platforms": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "included_platforms": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessDevicePlatformAll, msgraph.ConditionalAccessDevicePlatformAndroid, @@ -303,10 +301,10 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "excluded_platforms": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessDevicePlatformAll, msgraph.ConditionalAccessDevicePlatformAndroid, @@ -324,10 +322,10 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "service_principal_risk_levels": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessRiskLevelHigh, msgraph.ConditionalAccessRiskLevelLow, @@ -339,10 +337,10 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "sign_in_risk_levels": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessRiskLevelHidden, msgraph.ConditionalAccessRiskLevelHigh, @@ -355,10 +353,10 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "user_risk_levels": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessRiskLevelHidden, msgraph.ConditionalAccessRiskLevelHigh, @@ -374,23 +372,23 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "grant_controls": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, AtLeastOneOf: []string{"grant_controls", "session_controls"}, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "operator": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{"AND", "OR"}, false), }, "built_in_controls": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessGrantControlApprovedApplication, msgraph.ConditionalAccessGrantControlBlock, @@ -405,20 +403,20 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "custom_authentication_factors": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "terms_of_use": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -426,20 +424,20 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "session_controls": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, AtLeastOneOf: []string{"grant_controls", "session_controls"}, MaxItems: 1, DiffSuppressFunc: conditionalAccessPolicyDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "application_enforced_restrictions_enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "cloud_app_security_policy": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.ConditionalAccessCloudAppSecuritySessionControlTypeBlockDownloads, @@ -450,12 +448,12 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "disable_resilience_defaults": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "persistent_browser_mode": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.PersistentBrowserSessionModeAlways, @@ -464,14 +462,14 @@ func conditionalAccessPolicyResource() *schema.Resource { }, "sign_in_frequency": { - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Optional: true, RequiredWith: []string{"session_controls.0.sign_in_frequency_period"}, ValidateFunc: validation.IntAtLeast(0), }, "sign_in_frequency_period": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, RequiredWith: []string{"session_controls.0.sign_in_frequency"}, ValidateFunc: validation.StringInSlice([]string{"days", "hours"}, false), @@ -483,7 +481,7 @@ func conditionalAccessPolicyResource() *schema.Resource { } } -func conditionalAccessPolicyCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func conditionalAccessPolicyCustomizeDiff(ctx context.Context, diff *pluginsdk.ResourceDiff, meta interface{}) error { // See https://github.com/microsoftgraph/msgraph-metadata/issues/93 if old, new := diff.GetChange("session_controls.0.sign_in_frequency"); old.(int) > 0 && new.(int) == 0 { diff.ForceNew("session_controls.0.sign_in_frequency") @@ -502,7 +500,7 @@ func conditionalAccessPolicyCustomizeDiff(ctx context.Context, diff *schema.Reso return nil } -func conditionalAccessPolicyDiffSuppress(k, old, new string, d *schema.ResourceData) bool { +func conditionalAccessPolicyDiffSuppress(k, old, new string, d *pluginsdk.ResourceData) bool { suppress := false switch { @@ -537,7 +535,7 @@ func conditionalAccessPolicyDiffSuppress(k, old, new string, d *schema.ResourceD return suppress } -func conditionalAccessPolicyResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func conditionalAccessPolicyResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.PoliciesClient properties := msgraph.ConditionalAccessPolicy{ @@ -568,7 +566,7 @@ func conditionalAccessPolicyResourceCreate(ctx context.Context, d *schema.Resour return conditionalAccessPolicyResourceRead(ctx, d, meta) } -func conditionalAccessPolicyResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func conditionalAccessPolicyResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.PoliciesClient properties := msgraph.ConditionalAccessPolicy{ @@ -594,7 +592,7 @@ func conditionalAccessPolicyResourceUpdate(ctx context.Context, d *schema.Resour // in a timeout loop, instead we're hoping that this allows enough time/activity for the update to be reflected. log.Printf("[DEBUG] Waiting for conditional access policy %q to be updated", d.Id()) timeout, _ := ctx.Deadline() - stateConf := &resource.StateChangeConf{ //nolint:staticcheck + stateConf := &pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Pending"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -627,7 +625,7 @@ func conditionalAccessPolicyResourceUpdate(ctx context.Context, d *schema.Resour return nil } -func conditionalAccessPolicyResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func conditionalAccessPolicyResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.PoliciesClient policy, status, err := client.Get(ctx, d.Id(), odata.Query{}) @@ -650,7 +648,7 @@ func conditionalAccessPolicyResourceRead(ctx context.Context, d *schema.Resource return nil } -func conditionalAccessPolicyResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func conditionalAccessPolicyResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.PoliciesClient policyId := d.Id() diff --git a/internal/services/conditionalaccess/conditional_access_policy_resource_test.go b/internal/services/conditionalaccess/conditional_access_policy_resource_test.go index 12b1486932..19bda5f9dd 100644 --- a/internal/services/conditionalaccess/conditional_access_policy_resource_test.go +++ b/internal/services/conditionalaccess/conditional_access_policy_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccConditionalAccessPolicy_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -42,10 +41,10 @@ func TestAccConditionalAccessPolicy_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -60,24 +59,24 @@ func TestAccConditionalAccessPolicy_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -93,10 +92,10 @@ func TestAccConditionalAccessPolicy_deviceFilter(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.deviceFilter(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -106,14 +105,14 @@ func TestAccConditionalAccessPolicy_deviceFilter(t *testing.T) { data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.deviceFilter(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -123,7 +122,7 @@ func TestAccConditionalAccessPolicy_deviceFilter(t *testing.T) { data.ImportStep(), { Config: r.deviceFilterUpdate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -138,24 +137,24 @@ func TestAccConditionalAccessPolicy_includedUserActions(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.includedUserActions(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.includedUserActions(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -167,10 +166,10 @@ func TestAccConditionalAccessPolicy_sessionControls(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.sessionControls(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -180,14 +179,14 @@ func TestAccConditionalAccessPolicy_sessionControls(t *testing.T) { data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.sessionControls(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -197,14 +196,14 @@ func TestAccConditionalAccessPolicy_sessionControls(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.sessionControls(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -221,10 +220,10 @@ func TestAccConditionalAccessPolicy_sessionControlsDisabled(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.sessionControlsDisabled(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -234,14 +233,14 @@ func TestAccConditionalAccessPolicy_sessionControlsDisabled(t *testing.T) { data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.sessionControlsDisabled(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -264,10 +263,10 @@ func TestAccConditionalAccessPolicy_clientApplications(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test") r := ConditionalAccessPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.clientApplicationsIncluded(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -277,7 +276,7 @@ func TestAccConditionalAccessPolicy_clientApplications(t *testing.T) { data.ImportStep(), { Config: r.clientApplicationsExcluded(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), @@ -287,7 +286,7 @@ func TestAccConditionalAccessPolicy_clientApplications(t *testing.T) { data.ImportStep(), { Config: r.clientApplicationsIncluded(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("id").Exists(), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)), diff --git a/internal/services/conditionalaccess/named_location_data_source.go b/internal/services/conditionalaccess/named_location_data_source.go index 8ecef50dde..2e7e161429 100644 --- a/internal/services/conditionalaccess/named_location_data_source.go +++ b/internal/services/conditionalaccess/named_location_data_source.go @@ -12,43 +12,43 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func namedLocationDataSource() *schema.Resource { - return &schema.Resource{ +func namedLocationDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: namedLocationDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "ip": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "ip_ranges": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "trusted": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, @@ -56,20 +56,20 @@ func namedLocationDataSource() *schema.Resource { }, "country": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "countries_and_regions": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "include_unknown_countries_and_regions": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, @@ -79,7 +79,7 @@ func namedLocationDataSource() *schema.Resource { } } -func namedLocationDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func namedLocationDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.NamedLocationsClient displayName := d.Get("display_name").(string) diff --git a/internal/services/conditionalaccess/named_location_data_source_test.go b/internal/services/conditionalaccess/named_location_data_source_test.go index 7e81d30e04..42b42238df 100644 --- a/internal/services/conditionalaccess/named_location_data_source_test.go +++ b/internal/services/conditionalaccess/named_location_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,10 +16,10 @@ type NamedLocationDataSource struct{} func TestAccNamedLocationDataSource_country(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_named_location", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: NamedLocationDataSource{}.country(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("country.#").HasValue("1"), check.That(data.ResourceName).Key("country.0.countries_and_regions.#").HasValue("3"), check.That(data.ResourceName).Key("country.0.include_unknown_countries_and_regions").HasValue("true"), @@ -32,10 +31,10 @@ func TestAccNamedLocationDataSource_country(t *testing.T) { func TestAccNamedLocationDataSource_ip(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_named_location", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: NamedLocationDataSource{}.ip(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("ip.#").HasValue("1"), check.That(data.ResourceName).Key("ip.0.ip_ranges.#").HasValue("4"), check.That(data.ResourceName).Key("ip.0.trusted").HasValue("true"), diff --git a/internal/services/conditionalaccess/named_location_resource.go b/internal/services/conditionalaccess/named_location_resource.go index bd319a40d2..46ff8ef772 100644 --- a/internal/services/conditionalaccess/named_location_resource.go +++ b/internal/services/conditionalaccess/named_location_resource.go @@ -15,63 +15,62 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func namedLocationResource() *schema.Resource { - return &schema.Resource{ +func namedLocationResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: namedLocationResourceCreate, ReadContext: namedLocationResourceRead, UpdateContext: namedLocationResourceUpdate, DeleteContext: namedLocationResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "ip": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, ForceNew: true, MaxItems: 1, ExactlyOneOf: []string{"ip", "country"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "ip_ranges": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "trusted": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, }, @@ -79,23 +78,23 @@ func namedLocationResource() *schema.Resource { }, "country": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, ForceNew: true, MaxItems: 1, ExactlyOneOf: []string{"ip", "country"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "countries_and_regions": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "include_unknown_countries_and_regions": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, }, @@ -105,7 +104,7 @@ func namedLocationResource() *schema.Resource { } } -func namedLocationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func namedLocationResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.NamedLocationsClient displayName := d.Get("display_name").(string) @@ -147,7 +146,7 @@ func namedLocationResourceCreate(ctx context.Context, d *schema.ResourceData, me return namedLocationResourceRead(ctx, d, meta) } -func namedLocationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func namedLocationResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.NamedLocationsClient base := msgraph.BaseNamedLocation{ @@ -159,7 +158,7 @@ func namedLocationResourceUpdate(ctx context.Context, d *schema.ResourceData, me base.DisplayName = &displayName } - var updateRefreshFunc resource.StateRefreshFunc //nolint:staticcheck + var updateRefreshFunc pluginsdk.StateRefreshFunc //nolint:staticcheck if v, ok := d.GetOk("ip"); ok { properties := expandIPNamedLocation(v.([]interface{})) @@ -221,7 +220,7 @@ func namedLocationResourceUpdate(ctx context.Context, d *schema.ResourceData, me log.Printf("[DEBUG] Waiting for named location %q to be updated", d.Id()) timeout, _ := ctx.Deadline() - stateConf := &resource.StateChangeConf{ //nolint:staticcheck + stateConf := &pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Pending"}, Target: []string{"Updated"}, Timeout: time.Until(timeout), @@ -236,7 +235,7 @@ func namedLocationResourceUpdate(ctx context.Context, d *schema.ResourceData, me return namedLocationResourceRead(ctx, d, meta) } -func namedLocationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func namedLocationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.NamedLocationsClient result, status, err := client.Get(ctx, d.Id(), odata.Query{}) @@ -274,7 +273,7 @@ func namedLocationResourceRead(ctx context.Context, d *schema.ResourceData, meta return nil } -func namedLocationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func namedLocationResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ConditionalAccess.NamedLocationsClient namedLocationId := d.Id() diff --git a/internal/services/conditionalaccess/named_location_resource_test.go b/internal/services/conditionalaccess/named_location_resource_test.go index 73354bfd7d..844f11ab44 100644 --- a/internal/services/conditionalaccess/named_location_resource_test.go +++ b/internal/services/conditionalaccess/named_location_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -25,10 +24,10 @@ func TestAccNamedLocation_basicIP(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_named_location", "test") r := NamedLocationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicIP(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -40,10 +39,10 @@ func TestAccNamedLocation_completeIP(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_named_location", "test") r := NamedLocationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.completeIP(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -55,24 +54,24 @@ func TestAccNamedLocation_updateIP(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_named_location", "test") r := NamedLocationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicIP(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.completeIP(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basicIP(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -84,10 +83,10 @@ func TestAccNamedLocation_basicCountry(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_named_location", "test") r := NamedLocationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicCountry(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -99,10 +98,10 @@ func TestAccNamedLocation_completeCountry(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_named_location", "test") r := NamedLocationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.completeCountry(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -114,24 +113,24 @@ func TestAccNamedLocation_updateCountry(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_named_location", "test") r := NamedLocationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicCountry(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.completeCountry(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basicCountry(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/conditionalaccess/registration.go b/internal/services/conditionalaccess/registration.go index 6b35e66e6e..1e2ceac58c 100644 --- a/internal/services/conditionalaccess/registration.go +++ b/internal/services/conditionalaccess/registration.go @@ -3,9 +3,7 @@ package conditionalaccess -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,15 +20,15 @@ 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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_named_location": namedLocationDataSource(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_named_location": namedLocationResource(), "azuread_conditional_access_policy": conditionalAccessPolicyResource(), } diff --git a/internal/services/directoryobjects/directory_object_data_source.go b/internal/services/directoryobjects/directory_object_data_source.go index 007553da4a..9eb1c77e65 100644 --- a/internal/services/directoryobjects/directory_object_data_source.go +++ b/internal/services/directoryobjects/directory_object_data_source.go @@ -10,38 +10,38 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func directoryObjectDataSource() *schema.Resource { - return &schema.Resource{ +func directoryObjectDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: directoryObjectDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_id": { Description: "The object ID of the principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "type": { Description: "The OData type of the principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func directoryObjectDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryObjectDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.DirectoryObjectsClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/directoryobjects/directory_object_data_source_test.go b/internal/services/directoryobjects/directory_object_data_source_test.go index cf24a0b447..5a933cf6ca 100644 --- a/internal/services/directoryobjects/directory_object_data_source_test.go +++ b/internal/services/directoryobjects/directory_object_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,10 +16,10 @@ type PrincipalTypeDataSource struct{} func TestAccPrincipalTypeDataSource_groupByObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_directory_object", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: PrincipalTypeDataSource{}.objectTypeFromGroup(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("type").HasValue("Group"), ), }, @@ -30,10 +29,10 @@ func TestAccPrincipalTypeDataSource_groupByObjectId(t *testing.T) { func TestAccPrincipalTypeDataSource_userByObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_directory_object", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: PrincipalTypeDataSource{}.objectTypeFromUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("type").HasValue("User"), ), }, @@ -43,10 +42,10 @@ func TestAccPrincipalTypeDataSource_userByObjectId(t *testing.T) { func TestAccPrincipalTypeDataSource_servicePrincipalByObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_directory_object", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: PrincipalTypeDataSource{}.objectTypeFromServicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("type").HasValue("ServicePrincipal"), ), }, diff --git a/internal/services/directoryobjects/registration.go b/internal/services/directoryobjects/registration.go index 08361cef6f..043da7df57 100644 --- a/internal/services/directoryobjects/registration.go +++ b/internal/services/directoryobjects/registration.go @@ -3,7 +3,7 @@ package directoryobjects -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -20,13 +20,13 @@ 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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_directory_object": directoryObjectDataSource(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} } diff --git a/internal/services/directoryroles/custom_directory_role_resource.go b/internal/services/directoryroles/custom_directory_role_resource.go index 54602b7358..de29256eb4 100644 --- a/internal/services/directoryroles/custom_directory_role_resource.go +++ b/internal/services/directoryroles/custom_directory_role_resource.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "time" @@ -14,63 +15,62 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func customDirectoryRoleResource() *schema.Resource { - return &schema.Resource{ +func customDirectoryRoleResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: customDirectoryRoleResourceCreate, UpdateContext: customDirectoryRoleResourceUpdate, ReadContext: customDirectoryRoleResourceRead, DeleteContext: customDirectoryRoleResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the custom directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "enabled": { Description: "Indicates whether the role is enabled for assignment", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Required: true, }, "permissions": { Description: "List of permissions that are included in the custom directory role", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "allowed_resource_actions": { Description: "Set of tasks that can be performed on a resource", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -79,23 +79,23 @@ func customDirectoryRoleResource() *schema.Resource { "version": { Description: "The version of the role definition.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.ValidateDiag(validation.StringLenBetween(1, 128)), + ValidateDiagFunc: validation2.ValidateDiag(validation.StringLenBetween(1, 128)), }, "description": { Description: "The description of the custom directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "template_id": { Description: "Custom template identifier that is typically used if one needs an identifier to be the same across different directories.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), // The template ID _can_ technically be changed but doing so mutates the role ID - essentially // causing the equivalent of a ForceNew by the API :/ @@ -104,14 +104,14 @@ func customDirectoryRoleResource() *schema.Resource { "object_id": { Description: "The object ID of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func customDirectoryRoleResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func customDirectoryRoleResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleDefinitionsClient displayName := d.Get("display_name").(string) @@ -120,7 +120,7 @@ func customDirectoryRoleResourceCreate(ctx context.Context, d *schema.ResourceDa Description: utils.NullableString(d.Get("description").(string)), DisplayName: utils.String(displayName), IsEnabled: utils.Bool(d.Get("enabled").(bool)), - RolePermissions: expandCustomRolePermissions(d.Get("permissions").(*schema.Set).List()), + RolePermissions: expandCustomRolePermissions(d.Get("permissions").(*pluginsdk.Set).List()), TemplateId: utils.String(d.Get("template_id").(string)), Version: utils.String(d.Get("version").(string)), } @@ -139,7 +139,7 @@ func customDirectoryRoleResourceCreate(ctx context.Context, d *schema.ResourceDa return customDirectoryRoleResourceRead(ctx, d, meta) } -func customDirectoryRoleResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func customDirectoryRoleResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleDefinitionsClient roleId := d.Id() @@ -152,7 +152,7 @@ func customDirectoryRoleResourceUpdate(ctx context.Context, d *schema.ResourceDa Description: utils.NullableString(d.Get("description").(string)), DisplayName: utils.String(displayName), IsEnabled: utils.Bool(d.Get("enabled").(bool)), - RolePermissions: expandCustomRolePermissions(d.Get("permissions").(*schema.Set).List()), + RolePermissions: expandCustomRolePermissions(d.Get("permissions").(*pluginsdk.Set).List()), TemplateId: utils.String(d.Get("template_id").(string)), Version: utils.String(d.Get("version").(string)), } @@ -165,7 +165,7 @@ func customDirectoryRoleResourceUpdate(ctx context.Context, d *schema.ResourceDa return customDirectoryRoleResourceRead(ctx, d, meta) } -func customDirectoryRoleResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func customDirectoryRoleResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleDefinitionsClient roleId := d.Id() @@ -193,7 +193,7 @@ func customDirectoryRoleResourceRead(ctx context.Context, d *schema.ResourceData return nil } -func customDirectoryRoleResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func customDirectoryRoleResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleDefinitionsClient roleId := d.Id() diff --git a/internal/services/directoryroles/custom_directory_role_resource_test.go b/internal/services/directoryroles/custom_directory_role_resource_test.go index 84250490d2..92f13df411 100644 --- a/internal/services/directoryroles/custom_directory_role_resource_test.go +++ b/internal/services/directoryroles/custom_directory_role_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccCustomDirectoryRole_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_custom_directory_role", "test") r := CustomDirectoryRoleResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").Exists(), ), @@ -40,10 +39,10 @@ func TestAccCustomDirectoryRole_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_custom_directory_role", "test") r := CustomDirectoryRoleResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").Exists(), ), @@ -56,24 +55,24 @@ func TestAccCustomDirectoryRole_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_custom_directory_role", "test") r := CustomDirectoryRoleResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -85,10 +84,10 @@ func TestAccCustomDirectoryRole_disable(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_custom_directory_role", "test") r := CustomDirectoryRoleResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").Exists(), ), @@ -96,7 +95,7 @@ func TestAccCustomDirectoryRole_disable(t *testing.T) { data.ImportStep(), { Config: r.disabled(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").Exists(), ), @@ -104,7 +103,7 @@ func TestAccCustomDirectoryRole_disable(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").Exists(), ), @@ -117,10 +116,10 @@ func TestAccCustomDirectoryRole_templateId(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_custom_directory_role", "test") r := CustomDirectoryRoleResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.templateId(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("object_id").Exists(), ), diff --git a/internal/services/directoryroles/directory_role_assignment_resource.go b/internal/services/directoryroles/directory_role_assignment_resource.go index 8473cbe14a..c3adc54572 100644 --- a/internal/services/directoryroles/directory_role_assignment_resource.go +++ b/internal/services/directoryroles/directory_role_assignment_resource.go @@ -13,97 +13,96 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func directoryRoleAssignmentResource() *schema.Resource { - return &schema.Resource{ +func directoryRoleAssignmentResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: directoryRoleAssignmentResourceCreate, ReadContext: directoryRoleAssignmentResourceRead, DeleteContext: directoryRoleAssignmentResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if id == "" { return errors.New("id was empty") } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "role_id": { Description: "The object ID of the directory role for this assignment", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "principal_object_id": { Description: "The object ID of the member principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "app_scope_id": { Description: "Identifier of the app-specific scope when the assignment scope is app-specific", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, ConflictsWith: []string{"app_scope_object_id", "directory_scope_id", "directory_scope_object_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "app_scope_object_id": { Deprecated: "`app_scope_object_id` has been renamed to `app_scope_id` and will be removed in version 3.0 or the AzureAD Provider", Description: "Identifier of the app-specific scope when the assignment scope is app-specific", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, ConflictsWith: []string{"app_scope_id", "directory_scope_id", "directory_scope_object_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "directory_scope_id": { Description: "Identifier of the directory object representing the scope of the assignment", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, ConflictsWith: []string{"app_scope_id", "app_scope_object_id", "directory_scope_object_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "directory_scope_object_id": { Description: "Identifier of the directory object representing the scope of the assignment", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, ConflictsWith: []string{"app_scope_id", "app_scope_object_id", "directory_scope_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, } } -func directoryRoleAssignmentResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleAssignmentResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleAssignmentsClient roleId := d.Get("role_id").(string) @@ -152,7 +151,7 @@ func directoryRoleAssignmentResourceCreate(ctx context.Context, d *schema.Resour return tf.ErrorDiagF(errors.New("context has no deadline"), "Waiting for directory role %q assignment to principal %q to take effect", roleId, principalId) } timeout := time.Until(deadline) - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: timeout, @@ -176,7 +175,7 @@ func directoryRoleAssignmentResourceCreate(ctx context.Context, d *schema.Resour return directoryRoleAssignmentResourceRead(ctx, d, meta) } -func directoryRoleAssignmentResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleAssignmentResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleAssignmentsClient id := d.Id() @@ -200,7 +199,7 @@ func directoryRoleAssignmentResourceRead(ctx context.Context, d *schema.Resource return nil } -func directoryRoleAssignmentResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleAssignmentResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.RoleAssignmentsClient if _, err := client.Delete(ctx, d.Id()); err != nil { diff --git a/internal/services/directoryroles/directory_role_assignment_resource_test.go b/internal/services/directoryroles/directory_role_assignment_resource_test.go index ded3686e65..8fa400deb3 100644 --- a/internal/services/directoryroles/directory_role_assignment_resource_test.go +++ b/internal/services/directoryroles/directory_role_assignment_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccDirectoryRoleAssignment_servicePrincipal(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role_assignment", "test") r := DirectoryRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -41,10 +40,10 @@ func TestAccDirectoryRoleAssignment_servicePrincipalWithCustomRole(t *testing.T) data := acceptance.BuildTestData(t, "azuread_directory_role_assignment", "test") r := DirectoryRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipalCustomRole(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -58,10 +57,10 @@ func TestAccDirectoryRoleAssignment_servicePrincipalScopedApplication(t *testing data := acceptance.BuildTestData(t, "azuread_directory_role_assignment", "test") r := DirectoryRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipalScopedApplication(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -75,10 +74,10 @@ func TestAccDirectoryRoleAssignment_user(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role_assignment", "testA") r := DirectoryRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -92,10 +91,10 @@ func TestAccDirectoryRoleAssignment_userWithCustomRole(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role_assignment", "testA") r := DirectoryRoleAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUserCustomRole(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -110,10 +109,10 @@ func TestAccDirectoryRoleAssignment_multipleUser(t *testing.T) { dataB := acceptance.BuildTestData(t, "azuread_directory_role_assignment", "testB") r := DirectoryRoleAssignmentResource{} - dataA.ResourceTest(t, r, []resource.TestStep{ + dataA.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_id").IsUuid(), check.That(dataA.ResourceName).Key("principal_object_id").IsUuid(), @@ -122,7 +121,7 @@ func TestAccDirectoryRoleAssignment_multipleUser(t *testing.T) { dataA.ImportStep(), { Config: r.twoUsers(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_id").IsUuid(), check.That(dataA.ResourceName).Key("principal_object_id").IsUuid(), @@ -135,7 +134,7 @@ func TestAccDirectoryRoleAssignment_multipleUser(t *testing.T) { dataB.ImportStep(), { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_id").IsUuid(), check.That(dataA.ResourceName).Key("principal_object_id").IsUuid(), diff --git a/internal/services/directoryroles/directory_role_member_resource.go b/internal/services/directoryroles/directory_role_member_resource.go index 6e7c711dd6..662d8e68c6 100644 --- a/internal/services/directoryroles/directory_role_member_resource.go +++ b/internal/services/directoryroles/directory_role_member_resource.go @@ -13,60 +13,59 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/directoryroles/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const directoryRoleMemberResourceName = "azuread_directory_role_member" -func directoryRoleMemberResource() *schema.Resource { - return &schema.Resource{ +func directoryRoleMemberResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: directoryRoleMemberResourceCreate, ReadContext: directoryRoleMemberResourceRead, DeleteContext: directoryRoleMemberResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.DirectoryRoleMemberID(id) return err }), DeprecationMessage: "This resource is deprecated and will be removed in version 3.0 of the AzureAD provider. Please use the `azuread_directory_role_assignment` resource instead.", - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "role_object_id": { Description: "The object ID of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "member_object_id": { Description: "The object ID of the member", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, } } -func directoryRoleMemberResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleMemberResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRolesClient directoryObjectsClient := meta.(*clients.Client).DirectoryRoles.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -116,7 +115,7 @@ func directoryRoleMemberResourceCreate(ctx context.Context, d *schema.ResourceDa return tf.ErrorDiagF(errors.New("context has no deadline"), "Waiting for role member %q to reflect for directory role %q", id.MemberId, id.DirectoryRoleId) } timeout := time.Until(deadline) - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: timeout, @@ -142,7 +141,7 @@ func directoryRoleMemberResourceCreate(ctx context.Context, d *schema.ResourceDa return directoryRoleMemberResourceRead(ctx, d, meta) } -func directoryRoleMemberResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleMemberResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRolesClient id, err := parse.DirectoryRoleMemberID(d.Id()) @@ -165,7 +164,7 @@ func directoryRoleMemberResourceRead(ctx context.Context, d *schema.ResourceData return nil } -func directoryRoleMemberResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleMemberResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRolesClient id, err := parse.DirectoryRoleMemberID(d.Id()) diff --git a/internal/services/directoryroles/directory_role_member_resource_test.go b/internal/services/directoryroles/directory_role_member_resource_test.go index 552167a767..ee7e88e699 100644 --- a/internal/services/directoryroles/directory_role_member_resource_test.go +++ b/internal/services/directoryroles/directory_role_member_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccDirectoryRoleMember_servicePrincipal(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role_member", "test") r := DirectoryRoleMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -41,10 +40,10 @@ func TestAccDirectoryRoleMember_user(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role_member", "testA") r := DirectoryRoleMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("role_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -59,10 +58,10 @@ func TestAccDirectoryRoleMember_multipleUser(t *testing.T) { dataB := acceptance.BuildTestData(t, "azuread_directory_role_member", "testB") r := DirectoryRoleMemberResource{} - dataA.ResourceTest(t, r, []resource.TestStep{ + dataA.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -71,7 +70,7 @@ func TestAccDirectoryRoleMember_multipleUser(t *testing.T) { dataA.ImportStep(), { Config: r.twoUsers(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -84,7 +83,7 @@ func TestAccDirectoryRoleMember_multipleUser(t *testing.T) { dataB.ImportStep(), { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("role_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -98,10 +97,10 @@ func TestAccDirectoryRoleMember_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role_member", "test") r := DirectoryRoleMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/directoryroles/directory_role_resource.go b/internal/services/directoryroles/directory_role_resource.go index 5695b7cd00..ba1235f9aa 100644 --- a/internal/services/directoryroles/directory_role_resource.go +++ b/internal/services/directoryroles/directory_role_resource.go @@ -6,71 +6,71 @@ package directoryroles import ( "context" "errors" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "strings" "time" "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/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azuread/internal/tf/suppress" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func directoryRoleResource() *schema.Resource { - return &schema.Resource{ +func directoryRoleResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: directoryRoleResourceCreate, ReadContext: directoryRoleResourceRead, DeleteContext: directoryRoleResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, ExactlyOneOf: []string{"display_name", "template_id"}, DiffSuppressFunc: suppress.CaseDifference, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "template_id": { Description: "The object ID of the template associated with the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, ExactlyOneOf: []string{"display_name", "template_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "description": { Description: "The description of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func directoryRoleResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRolesClient directoryRoleTemplatesClient := meta.(*clients.Client).DirectoryRoles.DirectoryRoleTemplatesClient displayName := d.Get("display_name").(string) @@ -149,7 +149,7 @@ func directoryRoleResourceCreate(ctx context.Context, d *schema.ResourceData, me return directoryRoleResourceRead(ctx, d, meta) } -func directoryRoleResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRolesClient directoryRole, status, err := client.Get(ctx, d.Id()) @@ -173,7 +173,7 @@ func directoryRoleResourceRead(ctx context.Context, d *schema.ResourceData, meta return nil } -func directoryRoleResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { // Directory roles cannot be deactivated or deleted, so this is a no-op return nil } diff --git a/internal/services/directoryroles/directory_role_resource_test.go b/internal/services/directoryroles/directory_role_resource_test.go index 1dd10c3f04..a23bc2e9cb 100644 --- a/internal/services/directoryroles/directory_role_resource_test.go +++ b/internal/services/directoryroles/directory_role_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -23,10 +22,10 @@ func TestAccDirectoryRole_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role", "test") r := DirectoryRoleResource{} - data.ResourceTestIgnoreDangling(t, r, []resource.TestStep{ + data.ResourceTestIgnoreDangling(t, r, []acceptance.TestStep{ { Config: r.byDisplayName(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("description").Exists(), check.That(data.ResourceName).Key("object_id").IsUuid(), @@ -40,10 +39,10 @@ func TestAccDirectoryRole_byTemplateId(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_directory_role", "test") r := DirectoryRoleResource{} - data.ResourceTestIgnoreDangling(t, r, []resource.TestStep{ + data.ResourceTestIgnoreDangling(t, r, []acceptance.TestStep{ { Config: r.byTemplateId(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("display_name").HasValue("Printer Administrator"), check.That(data.ResourceName).Key("description").Exists(), diff --git a/internal/services/directoryroles/directory_role_templates_data_source.go b/internal/services/directoryroles/directory_role_templates_data_source.go index f0f678a450..e142660a70 100644 --- a/internal/services/directoryroles/directory_role_templates_data_source.go +++ b/internal/services/directoryroles/directory_role_templates_data_source.go @@ -12,50 +12,50 @@ import ( "time" "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/tf/pluginsdk" ) -func directoryRoleTemplatesDataSource() *schema.Resource { - return &schema.Resource{ +func directoryRoleTemplatesDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: directoryRoleTemplatesDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_ids": { Description: "The object IDs of the role templates", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "role_templates": { Description: "A list of role templates", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the directory role template", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "description": { Description: "The description of the directory role template", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the directory role template", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -65,7 +65,7 @@ func directoryRoleTemplatesDataSource() *schema.Resource { } } -func directoryRoleTemplatesDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRoleTemplatesDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRoleTemplatesClient directoryRoleTemplates, _, err := client.List(ctx) diff --git a/internal/services/directoryroles/directory_role_templates_data_source_test.go b/internal/services/directoryroles/directory_role_templates_data_source_test.go index 70a716f008..ded3905b22 100644 --- a/internal/services/directoryroles/directory_role_templates_data_source_test.go +++ b/internal/services/directoryroles/directory_role_templates_data_source_test.go @@ -6,7 +6,6 @@ package directoryroles_test import ( "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,7 +16,7 @@ func TestAccDirectoryRoleTemplatesDataSource_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_directory_role_templates", "test") r := DirectoryRoleTemplatesDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.basic(), Check: r.testCheckFunc(data), @@ -25,15 +24,15 @@ func TestAccDirectoryRoleTemplatesDataSource_basic(t *testing.T) { }) } -func (DirectoryRoleTemplatesDataSource) testCheckFunc(data acceptance.TestData, additionalChecks ...resource.TestCheckFunc) resource.TestCheckFunc { - checks := []resource.TestCheckFunc{ +func (DirectoryRoleTemplatesDataSource) testCheckFunc(data acceptance.TestData, additionalChecks ...acceptance.TestCheckFunc) acceptance.TestCheckFunc { + checks := []acceptance.TestCheckFunc{ check.That(data.ResourceName).Key("role_templates.0.description").Exists(), check.That(data.ResourceName).Key("role_templates.0.display_name").Exists(), check.That(data.ResourceName).Key("role_templates.0.object_id").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), } checks = append(checks, additionalChecks...) - return resource.ComposeTestCheckFunc(checks...) + return acceptance.ComposeTestCheckFunc(checks...) } func (DirectoryRoleTemplatesDataSource) basic() string { diff --git a/internal/services/directoryroles/directory_roles_data_source.go b/internal/services/directoryroles/directory_roles_data_source.go index 67fe4e89a6..f27768882e 100644 --- a/internal/services/directoryroles/directory_roles_data_source.go +++ b/internal/services/directoryroles/directory_roles_data_source.go @@ -12,65 +12,65 @@ import ( "time" "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/tf/pluginsdk" ) -func directoryRolesDataSource() *schema.Resource { - return &schema.Resource{ +func directoryRolesDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: directoryRolesDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_ids": { Description: "The object IDs of the roles", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "template_ids": { Description: "The template IDs of the roles", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "roles": { Description: "A list of roles", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "template_id": { Description: "The object ID of the template associated with the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "description": { Description: "The description of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the directory role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -80,7 +80,7 @@ func directoryRolesDataSource() *schema.Resource { } } -func directoryRolesDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func directoryRolesDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).DirectoryRoles.DirectoryRolesClient directoryRoles, _, err := client.List(ctx) diff --git a/internal/services/directoryroles/directory_roles_data_source_test.go b/internal/services/directoryroles/directory_roles_data_source_test.go index d904e2633b..86a3ccf949 100644 --- a/internal/services/directoryroles/directory_roles_data_source_test.go +++ b/internal/services/directoryroles/directory_roles_data_source_test.go @@ -6,7 +6,6 @@ package directoryroles_test import ( "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,7 +16,7 @@ func TestAccDirectoryRolesDataSource_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_directory_roles", "test") r := DirectoryRolesDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.basic(), Check: r.testCheckFunc(data), @@ -25,8 +24,8 @@ func TestAccDirectoryRolesDataSource_basic(t *testing.T) { }) } -func (DirectoryRolesDataSource) testCheckFunc(data acceptance.TestData, additionalChecks ...resource.TestCheckFunc) resource.TestCheckFunc { - checks := []resource.TestCheckFunc{ +func (DirectoryRolesDataSource) testCheckFunc(data acceptance.TestData, additionalChecks ...acceptance.TestCheckFunc) acceptance.TestCheckFunc { + checks := []acceptance.TestCheckFunc{ check.That(data.ResourceName).Key("roles.0.description").Exists(), check.That(data.ResourceName).Key("roles.0.display_name").Exists(), check.That(data.ResourceName).Key("roles.0.object_id").Exists(), @@ -35,7 +34,7 @@ func (DirectoryRolesDataSource) testCheckFunc(data acceptance.TestData, addition check.That(data.ResourceName).Key("template_ids.#").Exists(), } checks = append(checks, additionalChecks...) - return resource.ComposeTestCheckFunc(checks...) + return acceptance.ComposeTestCheckFunc(checks...) } func (DirectoryRolesDataSource) basic() string { diff --git a/internal/services/directoryroles/directoryroles.go b/internal/services/directoryroles/directoryroles.go index a1154b3347..1fd429ac77 100644 --- a/internal/services/directoryroles/directoryroles.go +++ b/internal/services/directoryroles/directoryroles.go @@ -4,8 +4,8 @@ package directoryroles import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "github.com/manicminer/hamilton/msgraph" ) @@ -20,7 +20,7 @@ func expandCustomRolePermissions(in []interface{}) *[]msgraph.UnifiedRolePermiss var allowedResourceActions *[]string if v, ok := perm["allowed_resource_actions"]; ok { - allowedResourceActions = tf.ExpandStringSlicePtr(v.(*schema.Set).List()) + allowedResourceActions = tf.ExpandStringSlicePtr(v.(*pluginsdk.Set).List()) } result = append(result, msgraph.UnifiedRolePermission{ diff --git a/internal/services/directoryroles/registration.go b/internal/services/directoryroles/registration.go index 5e27f18b62..f1a97f4af8 100644 --- a/internal/services/directoryroles/registration.go +++ b/internal/services/directoryroles/registration.go @@ -3,9 +3,7 @@ package directoryroles -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,16 +20,16 @@ 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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_directory_roles": directoryRolesDataSource(), "azuread_directory_role_templates": directoryRoleTemplatesDataSource(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_custom_directory_role": customDirectoryRoleResource(), "azuread_directory_role": directoryRoleResource(), "azuread_directory_role_assignment": directoryRoleAssignmentResource(), diff --git a/internal/services/domains/domains_data_source.go b/internal/services/domains/domains_data_source.go index d33bc54a4d..fce33f8bbf 100644 --- a/internal/services/domains/domains_data_source.go +++ b/internal/services/domains/domains_data_source.go @@ -8,13 +8,12 @@ import ( "crypto/sha1" "encoding/base64" "fmt" - "github.com/hashicorp/terraform-provider-azuread/internal/sdk" - "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "strings" "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azuread/internal/sdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) type DomainsId string @@ -64,44 +63,44 @@ func (r DomainsDataSource) Arguments() map[string]*pluginsdk.Schema { return map[string]*pluginsdk.Schema{ "admin_managed": { Description: "Set to `true` to only return domains whose DNS is managed by Microsoft 365", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "include_unverified": { Description: "Set to `true` if unverified Azure AD domains should be included", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ConflictsWith: []string{"only_default", "only_initial"}, // default or initial domains have to be verified }, "only_default": { Description: "Set to `true` to only return the default domain", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ConflictsWith: []string{"only_initial", "only_root"}, }, "only_initial": { Description: "Set to `true` to only return the initial domain, which is your primary Azure Active Directory tenant domain", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ConflictsWith: []string{"only_default", "only_root"}, }, "only_root": { Description: "Set to `true` to only return verified root domains. Excludes subdomains and unverified domains", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ConflictsWith: []string{"only_default", "only_initial"}, }, "supports_services": { Description: "A list of supported services that must be supported by a domain", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, } @@ -111,58 +110,58 @@ func (r DomainsDataSource) Attributes() map[string]*pluginsdk.Schema { return map[string]*pluginsdk.Schema{ "domains": { Description: "A list of tenant domains", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "admin_managed": { Description: "Whether the DNS for the domain is managed by Microsoft 365", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "authentication_type": { Description: "The authentication type of the domain. Possible values include `Managed` or `Federated`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "default": { Description: "Whether this is the default domain that is used for user creation", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "domain_name": { Description: "The name of the domain", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "initial": { Description: "Whether this is the initial domain created by Azure Active Directory", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "root": { Description: "Whether the domain is a verified root domain (not a subdomain)", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "supported_services": { Description: "A list of capabilities / services supported by the domain. Possible values include `Email`, `Sharepoint`, `EmailInternalRelayOnly`, `OfficeCommunicationsOnline`, `SharePointDefaultDomain`, `FullRedelegation`, `SharePointPublic`, `OrgIdAuthentication`, `Yammer` and `Intune`", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "verified": { Description: "Whether the domain has completed domain ownership verification", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, @@ -196,7 +195,6 @@ func (r DomainsDataSource) Read() sdk.ResourceFunc { return fmt.Errorf("retrieving domains: result was nil") } - var domains []Domain var domainNames []string for _, v := range *result { @@ -243,7 +241,7 @@ func (r DomainsDataSource) Read() sdk.ResourceFunc { supportedServices = *v.SupportedServices } - domains = append(domains, Domain{ + state.Domains = append(state.Domains, Domain{ AdminManaged: v.IsAdminManaged != nil && *v.IsAdminManaged, AuthenticationType: authenticationType, Default: v.IsDefault != nil && *v.IsDefault, @@ -256,7 +254,7 @@ func (r DomainsDataSource) Read() sdk.ResourceFunc { } } - if len(domains) == 0 { + if len(state.Domains) == 0 { return fmt.Errorf("no domains found for the provided filters") } @@ -268,7 +266,7 @@ func (r DomainsDataSource) Read() sdk.ResourceFunc { metadata.SetID(DomainsId(fmt.Sprintf("domains#%s#%s", tenantId, base64.URLEncoding.EncodeToString(h.Sum(nil))))) - return nil + return metadata.Encode(&state) }, } } diff --git a/internal/services/domains/registration.go b/internal/services/domains/registration.go index 4b3119cbb4..f155030101 100644 --- a/internal/services/domains/registration.go +++ b/internal/services/domains/registration.go @@ -4,8 +4,8 @@ package domains import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azuread/internal/sdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) type Registration struct{} @@ -23,13 +23,13 @@ func (r Registration) WebsiteCategories() []string { } // SupportedDataSources returns the untyped Data Sources supported by this Service -func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} } // SupportedResources returns the untyped Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} } // DataSources returns the typed DataSources supported by this service diff --git a/internal/services/groups/group_data_source.go b/internal/services/groups/group_data_source.go index 1114abca99..53b8d48805 100644 --- a/internal/services/groups/group_data_source.go +++ b/internal/services/groups/group_data_source.go @@ -12,96 +12,96 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func groupDataSource() *schema.Resource { - return &schema.Resource{ +func groupDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: groupDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name for the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "object_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "object_id": { Description: "The object ID of the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "object_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "mail_enabled": { Description: "Whether the group is mail-enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, Optional: true, }, "security_enabled": { Description: "Whether the group is a security group", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, }, "assignable_to_role": { Description: "Indicates whether this group can be assigned to an Azure Active Directory role", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "auto_subscribe_new_members": { Description: "Indicates whether new members added to the group will be auto-subscribed to receive email notifications.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "behaviors": { Description: "The group behaviors for a Microsoft 365 group", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "description": { Description: "The optional description of the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "dynamic_membership": { Description: "An optional block to configure dynamic membership for the group. Cannot be used with `members`", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "rule": { Description: "Rule to determine members for a dynamic group. Required when `group_types` contains 'DynamicMembership'", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -110,143 +110,143 @@ func groupDataSource() *schema.Resource { "external_senders_allowed": { Description: "Indicates whether people external to the organization can send messages to the group.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "hide_from_address_lists": { Description: "Indicates whether the group is displayed in certain parts of the Outlook user interface: in the Address Book, in address lists for selecting message recipients, and in the Browse Groups dialog for searching groups.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "hide_from_outlook_clients": { Description: "Indicates whether the group is displayed in Outlook clients, such as Outlook for Windows and Outlook on the web.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "mail": { Description: "The SMTP address for the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "mail_nickname": { Description: "The mail alias for the group, unique in the organisation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "members": { Description: "The object IDs of the group members", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "onpremises_domain_name": { Description: "The on-premises FQDN, also called dnsDomainName, synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_group_type": { Description: "Indicates the target on-premise group type the group will be written back as", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_netbios_name": { Description: "The on-premises NetBIOS name, synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sam_account_name": { Description: "The on-premises SAM account name, synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_security_identifier": { Description: "The on-premises security identifier (SID), synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sync_enabled": { Description: "Whether this group is synchronized from an on-premises directory (true), no longer synchronized (false), or has never been synchronized (null)", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "owners": { Description: "The object IDs of the group owners", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "preferred_language": { Description: "The preferred language for a Microsoft 365 group, in ISO 639-1 notation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "provisioning_options": { Description: "The group provisioning options for a Microsoft 365 group", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "proxy_addresses": { Description: "Email addresses for the group that direct to the same group mailbox", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "theme": { Description: "The colour theme for a Microsoft 365 group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "types": { Description: "A list of group types configured for the group. The only supported type is `Unified`, which specifies a Microsoft 365 group", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "visibility": { Description: "Specifies the group join policy and group content visibility", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "writeback_enabled": { Description: "Whether this group is synced from Azure AD to the on-premises directory when Azure AD Connect is used", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, } } -func groupDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/groups/group_data_source_test.go b/internal/services/groups/group_data_source_test.go index 721ef85c32..f3902e85a9 100644 --- a/internal/services/groups/group_data_source_test.go +++ b/internal/services/groups/group_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,10 +16,10 @@ type GroupDataSource struct{} func TestAccGroupDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.displayName(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -29,10 +28,10 @@ func TestAccGroupDataSource_byDisplayName(t *testing.T) { func TestAccGroupDataSource_byDisplayNameWithSecurity(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.displayNameSecurity(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -42,10 +41,10 @@ func TestAccGroupDataSource_byDisplayNameWithSecurity(t *testing.T) { func TestAccGroupDataSource_byDisplayNameWithSecurityNotMail(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.displayNameSecurityNotMail(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -55,10 +54,10 @@ func TestAccGroupDataSource_byDisplayNameWithSecurityNotMail(t *testing.T) { func TestAccGroupDataSource_byCaseInsensitiveDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.caseInsensitiveDisplayName(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -68,10 +67,10 @@ func TestAccGroupDataSource_byCaseInsensitiveDisplayName(t *testing.T) { func TestAccGroupDataSource_byObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.objectId(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -81,10 +80,10 @@ func TestAccGroupDataSource_byObjectId(t *testing.T) { func TestAccGroupDataSource_byObjectIdWithSecurity(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.objectIdSecurity(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -94,10 +93,10 @@ func TestAccGroupDataSource_byObjectIdWithSecurity(t *testing.T) { func TestAccGroupDataSource_dynamicMembership(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.dynamicMembership(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), check.That(data.ResourceName).Key("dynamic_membership.#").HasValue("1"), check.That(data.ResourceName).Key("dynamic_membership.0.enabled").HasValue("true"), @@ -110,10 +109,10 @@ func TestAccGroupDataSource_dynamicMembership(t *testing.T) { func TestAccGroupDataSource_members(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.members(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), check.That(data.ResourceName).Key("members.#").HasValue("3"), ), @@ -124,10 +123,10 @@ func TestAccGroupDataSource_members(t *testing.T) { func TestAccGroupDataSource_owners(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.owners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), check.That(data.ResourceName).Key("owners.#").HasValue("3"), ), @@ -138,10 +137,10 @@ func TestAccGroupDataSource_owners(t *testing.T) { func TestAccGroupDataSource_unifiedExtraSettings(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.unifiedWithExtraSettings(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), check.That(data.ResourceName).Key("auto_subscribe_new_members").HasValue("true"), check.That(data.ResourceName).Key("external_senders_allowed").HasValue("true"), @@ -155,10 +154,10 @@ func TestAccGroupDataSource_unifiedExtraSettings(t *testing.T) { func TestAccGroupDataSource_writeback(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_group", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupDataSource{}.writeback(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), check.That(data.ResourceName).Key("writeback_enabled").HasValue("true"), check.That(data.ResourceName).Key("onpremises_group_type").HasValue("UniversalSecurityGroup"), diff --git a/internal/services/groups/group_member_resource.go b/internal/services/groups/group_member_resource.go index 5ec1c10dce..7c423439f1 100644 --- a/internal/services/groups/group_member_resource.go +++ b/internal/services/groups/group_member_resource.go @@ -14,55 +14,55 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/groups/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func groupMemberResource() *schema.Resource { - return &schema.Resource{ +func groupMemberResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: groupMemberResourceCreate, ReadContext: groupMemberResourceRead, DeleteContext: groupMemberResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.GroupMemberID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "group_object_id": { Description: "The object ID of the group you want to add the member to", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "member_object_id": { Description: "The object ID of the principal you want to add as a member to the group. Supported object types are Users, Groups or Service Principals", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, } } -func groupMemberResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupMemberResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient directoryObjectsClient := meta.(*clients.Client).Groups.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -118,7 +118,7 @@ func groupMemberResourceCreate(ctx context.Context, d *schema.ResourceData, meta return groupMemberResourceRead(ctx, d, meta) } -func groupMemberResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupMemberResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient id, err := parse.GroupMemberID(d.Id()) @@ -153,7 +153,7 @@ func groupMemberResourceRead(ctx context.Context, d *schema.ResourceData, meta i return nil } -func groupMemberResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupMemberResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient id, err := parse.GroupMemberID(d.Id()) diff --git a/internal/services/groups/group_member_resource_test.go b/internal/services/groups/group_member_resource_test.go index 14a542bfdc..55b784c9d1 100644 --- a/internal/services/groups/group_member_resource_test.go +++ b/internal/services/groups/group_member_resource_test.go @@ -9,7 +9,6 @@ import ( "strings" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccGroupMember_group(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group_member", "test") r := GroupMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.group(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("group_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -41,10 +40,10 @@ func TestAccGroupMember_servicePrincipal(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group_member", "test") r := GroupMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.servicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("group_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -58,10 +57,10 @@ func TestAccGroupMember_user(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group_member", "testA") r := GroupMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("group_object_id").IsUuid(), check.That(data.ResourceName).Key("member_object_id").IsUuid(), @@ -76,10 +75,10 @@ func TestAccGroupMember_multipleUser(t *testing.T) { dataB := acceptance.BuildTestData(t, "azuread_group_member", "testB") r := GroupMemberResource{} - dataA.ResourceTest(t, r, []resource.TestStep{ + dataA.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("group_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -88,7 +87,7 @@ func TestAccGroupMember_multipleUser(t *testing.T) { dataA.ImportStep(), { Config: r.twoUsers(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("group_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -100,14 +99,14 @@ func TestAccGroupMember_multipleUser(t *testing.T) { // we rerun the config so the group resource updates with the number of members { Config: r.twoUsers(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That("azuread_group.test").Key("members.#").HasValue("2"), ), }, dataA.ImportStep(), { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataA.ResourceName).Key("group_object_id").IsUuid(), check.That(dataA.ResourceName).Key("member_object_id").IsUuid(), @@ -116,7 +115,7 @@ func TestAccGroupMember_multipleUser(t *testing.T) { // we rerun the config so the group resource updates with the number of members { Config: r.oneUser(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That("azuread_group.test").Key("members.#").HasValue("1"), ), }, @@ -127,10 +126,10 @@ func TestAccGroupMember_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group_member", "test") r := GroupMemberResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.group(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/groups/group_resource.go b/internal/services/groups/group_resource.go index 44ae93d357..2141c0fcf1 100644 --- a/internal/services/groups/group_resource.go +++ b/internal/services/groups/group_resource.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "regexp" @@ -16,13 +17,12 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) @@ -31,8 +31,8 @@ const ( groupDuplicateValueError = "Request contains a property with duplicate values" ) -func groupResource() *schema.Resource { - return &schema.Resource{ +func groupResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: groupResourceCreate, ReadContext: groupResourceRead, UpdateContext: groupResourceUpdate, @@ -40,59 +40,59 @@ func groupResource() *schema.Resource { CustomizeDiff: groupResourceCustomizeDiff, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(20 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(20 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(20 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(20 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name for the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "administrative_unit_ids": { Description: "The administrative unit IDs in which the group should be. If empty, the group will be created at the tenant level.", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.IsUUID, }, }, "assignable_to_role": { Description: "Indicates whether this group can be assigned to an Azure Active Directory role. This property can only be `true` for security-enabled groups.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ForceNew: true, }, "auto_subscribe_new_members": { Description: "Indicates whether new members added to the group will be auto-subscribed to receive email notifications.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, }, "behaviors": { Description: "The group behaviours for a Microsoft 365 group", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.GroupResourceBehaviorOptionAllowOnlyMembersToPost, msgraph.GroupResourceBehaviorOptionCalendarMemberReadOnly, @@ -107,28 +107,28 @@ func groupResource() *schema.Resource { "description": { Description: "The description for the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "dynamic_membership": { Description: "An optional block to configure dynamic membership for the group. Cannot be used with `members`", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, ConflictsWith: []string{"members"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "enabled": { - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Required: true, }, "rule": { Description: "Rule to determine members for a dynamic group. Required when `group_types` contains 'DynamicMembership'", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.ValidateDiag(validation.StringLenBetween(0, 3072)), + ValidateDiagFunc: validation2.ValidateDiag(validation.StringLenBetween(0, 3072)), }, }, }, @@ -136,57 +136,57 @@ func groupResource() *schema.Resource { "external_senders_allowed": { Description: "Indicates whether people external to the organization can send messages to the group.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, }, "hide_from_address_lists": { Description: "Indicates whether the group is displayed in certain parts of the Outlook user interface: in the Address Book, in address lists for selecting message recipients, and in the Browse Groups dialog for searching groups.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, }, "hide_from_outlook_clients": { Description: "Indicates whether the group is displayed in Outlook clients, such as Outlook for Windows and Outlook on the web.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, }, "mail_enabled": { Description: "Whether the group is a mail enabled, with a shared group mailbox. At least one of `mail_enabled` or `security_enabled` must be specified. A group can be mail enabled _and_ security enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, AtLeastOneOf: []string{"mail_enabled", "security_enabled"}, }, "mail_nickname": { Description: "The mail alias for the group, unique in the organisation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.MailNickname, + ValidateDiagFunc: validation2.MailNickname, }, "members": { Description: "A set of members who should be present in this group. Supported object types are Users, Groups or Service Principals", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, ConflictsWith: []string{"dynamic_membership"}, - Set: schema.HashString, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Set: pluginsdk.HashString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "onpremises_group_type": { Description: "Indicates the target on-premise group type the group will be written back as", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.StringInSlice([]string{ @@ -198,32 +198,32 @@ func groupResource() *schema.Resource { "owners": { Description: "A set of owners who own this group. Supported object types are Users or Service Principals", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, MinItems: 1, MaxItems: 100, - Set: schema.HashString, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Set: pluginsdk.HashString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "prevent_duplicate_names": { Description: "If `true`, will return an error if an existing group is found with the same name", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "provisioning_options": { Description: "The group provisioning options for a Microsoft 365 group", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ msgraph.GroupResourceProvisioningOptionTeam, }, false), @@ -232,14 +232,14 @@ func groupResource() *schema.Resource { "security_enabled": { Description: "Whether the group is a security group for controlling access to in-app resources. At least one of `security_enabled` or `mail_enabled` must be specified. A group can be security enabled _and_ mail enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, AtLeastOneOf: []string{"mail_enabled", "security_enabled"}, }, "theme": { Description: "The colour theme for a Microsoft 365 group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ string(msgraph.GroupThemeNone), @@ -255,11 +255,11 @@ func groupResource() *schema.Resource { "types": { Description: "A set of group types to configure for the group. `Unified` specifies a Microsoft 365 group. Required when `mail_enabled` is true", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, ValidateFunc: validation.StringInSlice([]string{ "DynamicMembership", msgraph.GroupTypeUnified, @@ -269,7 +269,7 @@ func groupResource() *schema.Resource { "visibility": { Description: "Specifies the group join policy and group content visibility", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.StringInSlice([]string{ @@ -281,77 +281,77 @@ func groupResource() *schema.Resource { "writeback_enabled": { Description: "Whether this group should be synced from Azure AD to the on-premises directory when Azure AD Connect is used", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "mail": { Description: "The SMTP address for the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_domain_name": { Description: "The on-premises FQDN, also called dnsDomainName, synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_netbios_name": { Description: "The on-premises NetBIOS name, synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sam_account_name": { Description: "The on-premises SAM account name, synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_security_identifier": { Description: "The on-premises security identifier (SID), synchronized from the on-premises directory when Azure AD Connect is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sync_enabled": { Description: "Whether this group is synchronized from an on-premises directory (true), no longer synchronized (false), or has never been synchronized (null)", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "preferred_language": { Description: "The preferred language for a Microsoft 365 group, in ISO 639-1 notation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, // API always returns "preferredLanguage should not be set" }, "proxy_addresses": { Description: "Email addresses for the group that direct to the same group mailbox", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, }, } } -func groupResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func groupResourceCustomizeDiff(ctx context.Context, diff *pluginsdk.ResourceDiff, meta interface{}) error { client := meta.(*clients.Client).Groups.GroupsClient // Check for duplicate names oldDisplayName, newDisplayName := diff.GetChange("display_name") - if tf.ValueIsNotEmptyOrUnknown(diff.Id()) && diff.Get("prevent_duplicate_names").(bool) && tf.ValueIsNotEmptyOrUnknown(newDisplayName) && + if pluginsdk.ValueIsNotEmptyOrUnknown(diff.Id()) && diff.Get("prevent_duplicate_names").(bool) && pluginsdk.ValueIsNotEmptyOrUnknown(newDisplayName) && (oldDisplayName.(string) == "" || oldDisplayName.(string) != newDisplayName.(string)) { result, err := groupFindByName(ctx, client, newDisplayName.(string)) if err != nil { @@ -372,7 +372,7 @@ func groupResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, mailEnabled := diff.Get("mail_enabled").(bool) securityEnabled := diff.Get("security_enabled").(bool) groupTypes := make([]msgraph.GroupType, 0) - for _, v := range diff.Get("types").(*schema.Set).List() { + for _, v := range diff.Get("types").(*pluginsdk.Set).List() { groupTypes = append(groupTypes, v.(string)) } @@ -403,7 +403,7 @@ func groupResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, return fmt.Errorf("`auto_subscribe_new_members` is only supported for unified groups") } - if behaviors, ok := diff.GetOk("behaviors"); ok && len(behaviors.(*schema.Set).List()) > 0 { + if behaviors, ok := diff.GetOk("behaviors"); ok && len(behaviors.(*pluginsdk.Set).List()) > 0 { return fmt.Errorf("`behaviors` is only supported for unified groups") } @@ -419,7 +419,7 @@ func groupResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, return fmt.Errorf("`hide_from_outlook_clients` is only supported for unified groups") } - if provisioning, ok := diff.GetOk("provisioning_options"); ok && len(provisioning.(*schema.Set).List()) > 0 { + if provisioning, ok := diff.GetOk("provisioning_options"); ok && len(provisioning.(*pluginsdk.Set).List()) > 0 { return fmt.Errorf("`provisioning_options` is only supported for unified groups") } @@ -440,7 +440,7 @@ func groupResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, return nil } -func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient directoryObjectsClient := meta.(*clients.Client).Groups.DirectoryObjectsClient administrativeUnitsClient := meta.(*clients.Client).Groups.AdministrativeUnitsClient @@ -465,7 +465,7 @@ func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta inter } groupTypes := make([]msgraph.GroupType, 0) - for _, v := range d.Get("types").(*schema.Set).List() { + for _, v := range d.Get("types").(*pluginsdk.Set).List() { groupTypes = append(groupTypes, v.(string)) } @@ -479,12 +479,12 @@ func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta inter } behaviorOptions := make([]msgraph.GroupResourceBehaviorOption, 0) - for _, v := range d.Get("behaviors").(*schema.Set).List() { + for _, v := range d.Get("behaviors").(*pluginsdk.Set).List() { behaviorOptions = append(behaviorOptions, v.(string)) } provisioningOptions := make([]msgraph.GroupResourceProvisioningOption, 0) - for _, v := range d.Get("provisioning_options").(*schema.Set).List() { + for _, v := range d.Get("provisioning_options").(*pluginsdk.Set).List() { provisioningOptions = append(provisioningOptions, v.(string)) } @@ -568,7 +568,7 @@ func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta inter // First look for the calling principal, then prefer users, followed by service principals, to try and avoid // ownership-related API validation errors for Microsoft 365 groups. if v, ok := d.GetOk("owners"); ok { - owners := v.(*schema.Set).List() + owners := v.(*pluginsdk.Set).List() ownerCount := 0 // First look for the calling principal in the specified owners; it should always be included in the initial @@ -625,7 +625,7 @@ func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta inter var err error if v, ok := d.GetOk("administrative_unit_ids"); ok { - administrativeUnitIds := tf.ExpandStringSlice(v.(*schema.Set).List()) + administrativeUnitIds := tf.ExpandStringSlice(v.(*pluginsdk.Set).List()) for i, administrativeUnitId := range administrativeUnitIds { // Create the group in the first administrative unit, as this requires fewer permissions than creating it at tenant level if i == 0 { @@ -905,7 +905,7 @@ func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta inter // Add members after the group is created members := make(msgraph.Members, 0) if v, ok := d.GetOk("members"); ok { - for _, memberId := range v.(*schema.Set).List() { + for _, memberId := range v.(*pluginsdk.Set).List() { memberObject, _, err := directoryObjectsClient.Get(ctx, memberId.(string), odata.Query{}) if err != nil { return tf.ErrorDiagF(err, "Could not retrieve member principal object %q", memberId) @@ -941,7 +941,7 @@ func groupResourceCreate(ctx context.Context, d *schema.ResourceData, meta inter return groupResourceRead(ctx, d, meta) } -func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient directoryObjectsClient := meta.(*clients.Client).Groups.DirectoryObjectsClient administrativeUnitClient := meta.(*clients.Client).Groups.AdministrativeUnitsClient @@ -1016,7 +1016,7 @@ func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta inter } groupTypes := make([]msgraph.GroupType, 0) - for _, v := range d.Get("types").(*schema.Set).List() { + for _, v := range d.Get("types").(*pluginsdk.Set).List() { groupTypes = append(groupTypes, v.(string)) } @@ -1139,7 +1139,7 @@ func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta inter } existingMembers := *members - desiredMembers := *tf.ExpandStringSlicePtr(d.Get("members").(*schema.Set).List()) + desiredMembers := *tf.ExpandStringSlicePtr(d.Get("members").(*pluginsdk.Set).List()) membersForRemoval := utils.Difference(existingMembers, desiredMembers) membersToAdd := utils.Difference(desiredMembers, existingMembers) @@ -1185,7 +1185,7 @@ func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta inter // If all owners are removed, restore the calling principal as the sole owner, in order to meet API // restrictions about removing all owners, and maintain consistency with the Create behaviour. // In theory this path should never be reached, since the property is Computed and has MinItems: 1, but we handle it anyway. - desiredOwners := tf.ExpandStringSlice(v.(*schema.Set).List()) + desiredOwners := tf.ExpandStringSlice(v.(*pluginsdk.Set).List()) if len(desiredOwners) == 0 { desiredOwners = []string{callerId} } @@ -1238,7 +1238,7 @@ func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta inter existingAdministrativeUnits = append(existingAdministrativeUnits, *administrativeUnit.ID) } - desiredAdministrativeUnits := tf.ExpandStringSlice(v.(*schema.Set).List()) + desiredAdministrativeUnits := tf.ExpandStringSlice(v.(*pluginsdk.Set).List()) administrativeUnitsToLeave := utils.Difference(existingAdministrativeUnits, desiredAdministrativeUnits) administrativeUnitsToJoin := utils.Difference(desiredAdministrativeUnits, existingAdministrativeUnits) @@ -1264,7 +1264,7 @@ func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta inter return groupResourceRead(ctx, d, meta) } -func groupResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient group, status, err := client.Get(ctx, d.Id(), odata.Query{}) @@ -1381,7 +1381,7 @@ func groupResourceRead(ctx context.Context, d *schema.ResourceData, meta interfa return nil } -func groupResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient groupId := d.Id() diff --git a/internal/services/groups/group_resource_test.go b/internal/services/groups/group_resource_test.go index 8aa416308f..acd1770597 100644 --- a/internal/services/groups/group_resource_test.go +++ b/internal/services/groups/group_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccGroup_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), @@ -40,10 +39,10 @@ func TestAccGroup_basicUnified(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test_unified") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicUnified(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), @@ -56,10 +55,10 @@ func TestAccGroup_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -71,31 +70,31 @@ func TestAccGroup_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.unified(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.unified(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -107,10 +106,10 @@ func TestAccGroup_assignableToRole(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.assignableToRole(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -122,10 +121,10 @@ func TestAccGroup_behaviors(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.behaviors(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -137,24 +136,24 @@ func TestAccGroup_dynamicMembership(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.dynamicMembership(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.unified(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.dynamicMembership(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -166,10 +165,10 @@ func TestAccGroup_callerOwner(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withCallerAsOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -181,10 +180,10 @@ func TestAccGroup_owners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -192,7 +191,7 @@ func TestAccGroup_owners(t *testing.T) { data.ImportStep(), { Config: r.withOneOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -200,7 +199,7 @@ func TestAccGroup_owners(t *testing.T) { data.ImportStep(), { Config: r.withThreeOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("3"), ), @@ -208,7 +207,7 @@ func TestAccGroup_owners(t *testing.T) { data.ImportStep(), { Config: r.withOneOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -216,7 +215,7 @@ func TestAccGroup_owners(t *testing.T) { data.ImportStep(), { Config: r.withServicePrincipalOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -224,7 +223,7 @@ func TestAccGroup_owners(t *testing.T) { data.ImportStep(), { Config: r.withDiverseOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("2"), ), @@ -232,7 +231,7 @@ func TestAccGroup_owners(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("2"), ), @@ -245,10 +244,10 @@ func TestAccGroup_members(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("0"), ), @@ -256,7 +255,7 @@ func TestAccGroup_members(t *testing.T) { data.ImportStep(), { Config: r.withThreeMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("3"), ), @@ -264,7 +263,7 @@ func TestAccGroup_members(t *testing.T) { data.ImportStep(), { Config: r.withOneMember(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("1"), ), @@ -272,7 +271,7 @@ func TestAccGroup_members(t *testing.T) { data.ImportStep(), { Config: r.withServicePrincipalMember(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("1"), ), @@ -280,7 +279,7 @@ func TestAccGroup_members(t *testing.T) { data.ImportStep(), { Config: r.withDiverseMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("3"), ), @@ -288,7 +287,7 @@ func TestAccGroup_members(t *testing.T) { data.ImportStep(), { Config: r.withNoMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("0"), ), @@ -301,10 +300,10 @@ func TestAccGroup_membersAndOwners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withOwnersAndMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("2"), check.That(data.ResourceName).Key("owners.#").HasValue("1"), @@ -318,10 +317,10 @@ func TestAccGroup_manyMembersAndOwners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withManyOwnersAndMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("66"), check.That(data.ResourceName).Key("owners.#").HasValue("45"), @@ -330,7 +329,7 @@ func TestAccGroup_manyMembersAndOwners(t *testing.T) { data.ImportStep(), { Config: r.withOneOwnerAndNoMembers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("members.#").HasValue("0"), check.That(data.ResourceName).Key("owners.#").HasValue("1"), @@ -344,10 +343,10 @@ func TestAccGroup_preventDuplicateNamesPass(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.preventDuplicateNamesPass(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -359,7 +358,7 @@ func TestAccGroup_preventDuplicateNamesFail(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ data.RequiresImportErrorStep(r.preventDuplicateNamesFail(data)), }) } @@ -368,16 +367,16 @@ func TestAccGroup_preventDuplicateNamesForceNew(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, { Config: r.preventDuplicateNamesForceNew(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)), ), }, @@ -389,10 +388,10 @@ func TestAccGroup_provisioning(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.provisioning(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -404,24 +403,24 @@ func TestAccGroup_unifiedExtraSettings(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.unifiedWithExtraSettings(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.unifiedAsUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.unifiedWithExtraSettings(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -433,17 +432,17 @@ func TestAccGroup_visibility(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.visibility(data, "Private"), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.visibility(data, "Public"), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -455,10 +454,10 @@ func TestAccGroup_administrativeUnit(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.administrativeUnits(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("administrative_unit_ids.#").HasValue("2"), ), @@ -466,7 +465,7 @@ func TestAccGroup_administrativeUnit(t *testing.T) { data.ImportStep("administrative_unit_ids"), { Config: r.administrativeUnitsWithoutAssociation(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("administrative_unit_ids.#").HasValue("0"), ), @@ -474,7 +473,7 @@ func TestAccGroup_administrativeUnit(t *testing.T) { data.ImportStep("administrative_unit_ids"), { Config: r.administrativeUnits(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("administrative_unit_ids.#").HasValue("2"), ), @@ -487,10 +486,10 @@ func TestAccGroup_writeback(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withWriteback(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("onpremises_group_type").HasValue("UniversalSecurityGroup"), ), @@ -503,17 +502,17 @@ func TestAccGroup_writebackUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.withWriteback(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("onpremises_group_type").HasValue("UniversalSecurityGroup"), ), @@ -521,7 +520,7 @@ func TestAccGroup_writebackUpdate(t *testing.T) { data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -533,10 +532,10 @@ func TestAccGroup_writebackUnified(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_group", "test") r := GroupResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.unifiedWithWriteback(data, "UniversalDistributionGroup"), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("onpremises_group_type").HasValue("UniversalDistributionGroup"), ), @@ -544,7 +543,7 @@ func TestAccGroup_writebackUnified(t *testing.T) { data.ImportStep(), { Config: r.unifiedWithWriteback(data, "UniversalMailEnabledSecurityGroup"), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("onpremises_group_type").HasValue("UniversalMailEnabledSecurityGroup"), ), diff --git a/internal/services/groups/groups_data_source.go b/internal/services/groups/groups_data_source.go index 1158cbb26c..d8b582b78b 100644 --- a/internal/services/groups/groups_data_source.go +++ b/internal/services/groups/groups_data_source.go @@ -15,58 +15,58 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func groupsDataSource() *schema.Resource { - return &schema.Resource{ +func groupsDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: groupsDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_ids": { Description: "The object IDs of the groups", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"display_names", "display_name_prefix", "object_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "display_names": { Description: "The display names of the groups", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"display_names", "display_name_prefix", "object_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "display_name_prefix": { Description: "Common display name prefix of the groups", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_names", "display_name_prefix", "object_ids", "return_all"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "ignore_missing": { Description: "Ignore missing groups and return groups that were found. The data source will still fail if no groups are found", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, ConflictsWith: []string{"return_all"}, @@ -74,7 +74,7 @@ func groupsDataSource() *schema.Resource { "return_all": { Description: "Retrieve all groups with no filter", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, ConflictsWith: []string{"ignore_missing"}, ExactlyOneOf: []string{"display_names", "display_name_prefix", "object_ids", "return_all"}, @@ -82,7 +82,7 @@ func groupsDataSource() *schema.Resource { "mail_enabled": { Description: "Whether the groups are mail-enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, ConflictsWith: []string{"object_ids"}, @@ -90,7 +90,7 @@ func groupsDataSource() *schema.Resource { "security_enabled": { Description: "Whether the groups are security-enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Computed: true, ConflictsWith: []string{"object_ids"}, @@ -99,7 +99,7 @@ func groupsDataSource() *schema.Resource { } } -func groupsDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func groupsDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Groups.GroupsClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/groups/groups_data_source_test.go b/internal/services/groups/groups_data_source_test.go index 713e0e1092..ac5fa533f9 100644 --- a/internal/services/groups/groups_data_source_test.go +++ b/internal/services/groups/groups_data_source_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azuread/internal/clients" @@ -22,10 +21,10 @@ func TestAccGroupsDataSource_byDisplayNames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") r := GroupsDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayNames(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), ), @@ -37,10 +36,10 @@ func TestAccGroupsDataSource_byDisplayNamesIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") r := GroupsDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayNamesIgnoreMissing(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), ), @@ -53,10 +52,10 @@ func TestAccGroupsDataSource_byDisplayNamePrefix(t *testing.T) { r := GroupsDataSource{} moreThanZero := regexp.MustCompile("^[1-9][0-9]*$") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayNamePrefix(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").MatchesRegex(moreThanZero), check.That(data.ResourceName).Key("object_ids.#").MatchesRegex(moreThanZero), ), @@ -68,10 +67,10 @@ func TestAccGroupsDataSource_byObjectIds(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") r := GroupsDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byObjectIds(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), ), @@ -82,10 +81,10 @@ func TestAccGroupsDataSource_byObjectIds(t *testing.T) { func TestAccGroupsDataSource_noNames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupsDataSource{}.noNames(), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("0"), check.That(data.ResourceName).Key("object_ids.#").HasValue("0"), ), @@ -96,10 +95,10 @@ func TestAccGroupsDataSource_noNames(t *testing.T) { func TestAccGroupsDataSource_returnAll(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupsDataSource{}.returnAll(), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), ), @@ -110,10 +109,10 @@ func TestAccGroupsDataSource_returnAll(t *testing.T) { func TestAccGroupsDataSource_returnAllMailEnabled(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupsDataSource{}.returnAllMailEnabled(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), check.That(data.ResourceName).Key("object_ids").ValidatesWith(testCheckHasOnlyMailEnabledGroups()), @@ -125,10 +124,10 @@ func TestAccGroupsDataSource_returnAllMailEnabled(t *testing.T) { func TestAccGroupsDataSource_returnAllSecurityEnabled(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupsDataSource{}.returnAllSecurityEnabled(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), check.That(data.ResourceName).Key("object_ids").ValidatesWith(testCheckHasOnlySecurityEnabledGroups()), @@ -140,10 +139,10 @@ func TestAccGroupsDataSource_returnAllSecurityEnabled(t *testing.T) { func TestAccGroupsDataSource_returnAllMailNotSecurityEnabled(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupsDataSource{}.returnAllMailNotSecurityEnabled(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), check.That(data.ResourceName).Key("object_ids").ValidatesWith(testCheckHasOnlyMailEnabledGroupsNotSecurityEnabledGroups()), @@ -155,10 +154,10 @@ func TestAccGroupsDataSource_returnAllMailNotSecurityEnabled(t *testing.T) { func TestAccGroupsDataSource_returnAllSecurityNotMailEnabled(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_groups", "test") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: GroupsDataSource{}.returnAllSecurityNotMailEnabled(data), - Check: resource.ComposeAggregateTestCheckFunc( + Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), check.That(data.ResourceName).Key("object_ids").ValidatesWith(testCheckHasOnlySecurityEnabledGroupsNotMailEnabledGroups()), diff --git a/internal/services/groups/registration.go b/internal/services/groups/registration.go index 0b05b812d3..42871d7170 100644 --- a/internal/services/groups/registration.go +++ b/internal/services/groups/registration.go @@ -3,9 +3,7 @@ package groups -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,16 +20,16 @@ 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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_group": groupDataSource(), "azuread_groups": groupsDataSource(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_group": groupResource(), "azuread_group_member": groupMemberResource(), } diff --git a/internal/services/identitygovernance/access_package_assignment_policy_resource.go b/internal/services/identitygovernance/access_package_assignment_policy_resource.go index d16f660c39..ec90209c6d 100644 --- a/internal/services/identitygovernance/access_package_assignment_policy_resource.go +++ b/internal/services/identitygovernance/access_package_assignment_policy_resource.go @@ -13,20 +13,19 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const accessPackageAssignmentPolicyResourceName = "azuread_access_package_assignment_policy" -func accessPackageAssignmentPolicyResource() *schema.Resource { - return &schema.Resource{ +func accessPackageAssignmentPolicyResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: accessPackageAssignmentPolicyResourceCreate, ReadContext: accessPackageAssignmentPolicyResourceRead, UpdateContext: accessPackageAssignmentPolicyResourceUpdate, @@ -34,45 +33,45 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { CustomizeDiff: assignmentPolicyCustomDiff, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "access_package_id": { Description: "The ID of the access package that will contain the policy", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "The display name of the policy", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "description": { Description: "The description of the policy", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "duration_in_days": { Description: "How many days this assignment is valid for", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Optional: true, ConflictsWith: []string{"expiration_date"}, ValidateFunc: validation.IntBetween(0, 3660), @@ -80,7 +79,7 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "expiration_date": { Description: "The date that this assignment expires, formatted as an RFC3339 date string in UTC (e.g. 2018-01-01T01:02:03Z)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ConflictsWith: []string{"duration_in_days"}, ValidateFunc: validation.IsRFC3339Time, @@ -89,27 +88,27 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "extension_enabled": { Description: "When enabled, users will be able to request extension of their access to this package before their access expires", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "requestor_settings": { Description: "This block configures the users who can request access", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, DiffSuppressFunc: assignmentPolicyDiffSuppress, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "requests_accepted": { Description: "Whether to accept requests now, when disabled, no new requests can be made using this policy", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "scope_type": { Description: "Specify the scopes of the requestors", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.RequestorSettingsScopeTypeAllConfiguredConnectedOrganizationSubjects, @@ -125,7 +124,7 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "requestor": { Description: "The users who are allowed to request on this policy, which can be singleUser, groupMembers, and connectedOrganizationMembers", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Elem: schemaUserSet(), }, @@ -135,70 +134,70 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "approval_settings": { Description: "Settings of whether approvals are required and how they are obtained", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, DiffSuppressFunc: assignmentPolicyDiffSuppress, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "approval_required": { Description: "Whether an approval is required", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "approval_required_for_extension": { Description: "Whether an approval is required to grant extension. Same approval settings used to approve initial access will apply", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "requestor_justification_required": { Description: "Whether requestor are required to provide a justification to request an access package. Justification is visible to other approvers and the requestor", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "approval_stage": { Description: "The process to obtain an approval", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "approval_timeout_in_days": { Description: "Decision must be made in how many days? If a request is not approved within this time period after it is made, it will be automatically rejected", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Required: true, }, "approver_justification_required": { Description: "Whether an approver must provide a justification for their decision. Justification is visible to other approvers and the requestor", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "alternative_approval_enabled": { Description: "If no action taken, forward to alternate approvers?", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "enable_alternative_approval_in_days": { Description: "Forward to alternate approver(s) after how many days?", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Optional: true, }, "primary_approver": { Description: "The users who will be asked to approve requests. A collection of singleUser, groupMembers, requestorManager, internalSponsors and externalSponsors. When creating or updating a policy, include at least one userSet in this collection", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Elem: schemaUserSet(), }, "alternative_approver": { Description: "If escalation is enabled and the primary approvers do not respond before the escalation time, the escalationApprovers are the users who will be asked to approve requests. This can be a collection of singleUser, groupMembers, requestorManager, internalSponsors and externalSponsors. When creating or updating a policy, if there are no escalation approvers, or escalation approvers are not required for the stage, the value of this property should be an empty collection", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Elem: schemaUserSet(), }, @@ -211,21 +210,21 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "assignment_review_settings": { Description: "The settings of whether assignment review is needed and how it's conducted", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, DiffSuppressFunc: assignmentPolicyDiffSuppress, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "enabled": { Description: "Whether to enable assignment review", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "review_frequency": { Description: "This will determine how often the access review campaign runs", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.AccessReviewRecurrenceTypeAnnual, @@ -238,7 +237,7 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "review_type": { Description: "Self review or specific reviewers", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.AccessReviewReviewerTypeManager, @@ -249,39 +248,39 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "starting_on": { Description: "This is the date the access review campaign will start on, formatted as an RFC3339 date string in UTC(e.g. 2018-01-01T01:02:03Z), default is now. Once an access review has been created, you cannot update its start date", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.IsRFC3339Time, }, "duration_in_days": { Description: "How many days each occurrence of the access review series will run", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Optional: true, }, "reviewer": { Description: "If the reviewerType is Reviewers, this collection specifies the users who will be reviewers, either by ID or as members of a group, using a collection of singleUser and groupMembers", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Elem: schemaUserSet(), }, "access_recommendation_enabled": { Description: "Whether to show Show reviewer decision helpers. If enabled, system recommendations based on users' access information will be shown to the reviewers. The reviewer will be recommended to approve the review if the user has signed-in at least once during the last 30 days. The reviewer will be recommended to deny the review if the user has not signed-in during the last 30 days", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "approver_justification_required": { Description: "Whether a reviewer need provide a justification for their decision. Justification is visible to other reviewers and the requestor", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "access_review_timeout_behavior": { Description: "What actions the system takes if reviewers don't respond in time", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ msgraph.AccessReviewTimeoutBehaviorTypeAcceptAccessRecommendation, @@ -295,38 +294,38 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "question": { Description: "One or more questions to the requestor", - Type: schema.TypeList, + Type: pluginsdk.TypeList, DiffSuppressFunc: assignmentPolicyDiffSuppress, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "required": { Description: "Whether this question is required", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "sequence": { Description: "The sequence number of this question", - Type: schema.TypeInt, + Type: pluginsdk.TypeInt, Optional: true, }, "choice": { Description: "Configuration of a choice to the question", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "actual_value": { Description: "The actual value of this choice", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "display_value": { Description: "The display text of this choice", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, MaxItems: 1, Elem: schemaLocalizedContent(), @@ -337,7 +336,7 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { "text": { Description: "The content of this question", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, MaxItems: 1, Elem: schemaLocalizedContent(), @@ -349,7 +348,7 @@ func accessPackageAssignmentPolicyResource() *schema.Resource { } } -func accessPackageAssignmentPolicyResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageAssignmentPolicyResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageAssignmentPolicyClient var properties msgraph.AccessPackageAssignmentPolicy @@ -368,7 +367,7 @@ func accessPackageAssignmentPolicyResourceCreate(ctx context.Context, d *schema. return accessPackageAssignmentPolicyResourceRead(ctx, d, meta) } -func accessPackageAssignmentPolicyResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageAssignmentPolicyResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageAssignmentPolicyClient var properties msgraph.AccessPackageAssignmentPolicy @@ -387,7 +386,7 @@ func accessPackageAssignmentPolicyResourceUpdate(ctx context.Context, d *schema. return accessPackageAssignmentPolicyResourceRead(ctx, d, meta) } -func accessPackageAssignmentPolicyResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageAssignmentPolicyResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageAssignmentPolicyClient objectId := d.Id() @@ -421,7 +420,7 @@ func accessPackageAssignmentPolicyResourceRead(ctx context.Context, d *schema.Re return nil } -func accessPackageAssignmentPolicyResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageAssignmentPolicyResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageAssignmentPolicyClient accessPackageAssignmentPolicyId := d.Id() @@ -457,7 +456,7 @@ func accessPackageAssignmentPolicyResourceDelete(ctx context.Context, d *schema. return nil } -func buildAssignmentPolicyResourceData(ctx context.Context, d *schema.ResourceData, meta interface{}) (msgraph.AccessPackageAssignmentPolicy, error) { +func buildAssignmentPolicyResourceData(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) (msgraph.AccessPackageAssignmentPolicy, error) { accessPackageClient := meta.(*clients.Client).IdentityGovernance.AccessPackageClient accessPackageId := d.Get("access_package_id").(string) @@ -503,7 +502,7 @@ func buildAssignmentPolicyResourceData(ctx context.Context, d *schema.ResourceDa return properties, nil } -func assignmentPolicyDiffSuppress(k, old, new string, d *schema.ResourceData) bool { +func assignmentPolicyDiffSuppress(k, old, new string, d *pluginsdk.ResourceData) bool { if k == "approval_settings.#" && old == "1" && new == "0" { return true } @@ -531,7 +530,7 @@ func assignmentPolicyDiffSuppress(k, old, new string, d *schema.ResourceData) bo return false } -func assignmentPolicyCustomDiff(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func assignmentPolicyCustomDiff(ctx context.Context, diff *pluginsdk.ResourceDiff, meta interface{}) error { if reviewSettings := diff.Get("assignment_review_settings").([]interface{}); len(reviewSettings) > 0 { reviewSetting := reviewSettings[0].(map[string]interface{}) if reviewSetting["enabled"].(bool) && diff --git a/internal/services/identitygovernance/access_package_assignment_policy_resource_test.go b/internal/services/identitygovernance/access_package_assignment_policy_resource_test.go index 49ebbc98bb..22078f3352 100644 --- a/internal/services/identitygovernance/access_package_assignment_policy_resource_test.go +++ b/internal/services/identitygovernance/access_package_assignment_policy_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAccessPackageAssignmentPolicy_simple(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_assignment_policy", "test") r := AccessPackageAssignmentPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.simple(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -39,10 +38,10 @@ func TestAccAccessPackageAssignmentPolicy_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_assignment_policy", "test") r := AccessPackageAssignmentPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -54,10 +53,10 @@ func TestAccAccessPackageAssignmentPolicy_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_assignment_policy", "test") r := AccessPackageAssignmentPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -69,24 +68,24 @@ func TestAccAccessPackageAssignmentPolicy_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_assignment_policy", "test") r := AccessPackageAssignmentPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/identitygovernance/access_package_catalog_data_source.go b/internal/services/identitygovernance/access_package_catalog_data_source.go index f2e3dff212..450a5cc0c5 100644 --- a/internal/services/identitygovernance/access_package_catalog_data_source.go +++ b/internal/services/identitygovernance/access_package_catalog_data_source.go @@ -11,25 +11,25 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func accessPackageCatalogDataSource() *schema.Resource { - return &schema.Resource{ +func accessPackageCatalogDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: accessPackageCatalogDataRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_id": { Description: "The ID of this access package catalog", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.IsUUID, @@ -38,7 +38,7 @@ func accessPackageCatalogDataSource() *schema.Resource { "display_name": { Description: "The display name of the access package catalog", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"object_id", "display_name"}, @@ -46,26 +46,26 @@ func accessPackageCatalogDataSource() *schema.Resource { "description": { Description: "The description of the access package catalog", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "externally_visible": { Description: "Whether the access packages in this catalog can be requested by users outside the tenant", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "published": { Description: "Whether the access packages in this catalog are available for management", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, } } -func accessPackageCatalogDataRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogDataRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient objectId := d.Get("object_id").(string) diff --git a/internal/services/identitygovernance/access_package_catalog_data_source_test.go b/internal/services/identitygovernance/access_package_catalog_data_source_test.go index 55914b9509..9951deca09 100644 --- a/internal/services/identitygovernance/access_package_catalog_data_source_test.go +++ b/internal/services/identitygovernance/access_package_catalog_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -18,7 +17,7 @@ func TestAccAccessPackageCatalogDataSource_byId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_access_package_catalog", "test") r := AccessPackageCatalogDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byId(data), Check: r.testCheckFunc(data), @@ -30,7 +29,7 @@ func TestAccAccessPackageCatalogDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_access_package_catalog", "test") r := AccessPackageCatalogDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayName(data), Check: r.testCheckFunc(data), @@ -38,8 +37,8 @@ func TestAccAccessPackageCatalogDataSource_byDisplayName(t *testing.T) { }) } -func (AccessPackageCatalogDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( +func (AccessPackageCatalogDataSource) testCheckFunc(data acceptance.TestData) acceptance.TestCheckFunc { + return acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("description").HasValue(fmt.Sprintf("Test access package catalog %[1]d", data.RandomInteger)), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("test-access-package-catalog-%[1]d", data.RandomInteger)), check.That(data.ResourceName).Key("externally_visible").HasValue("false"), diff --git a/internal/services/identitygovernance/access_package_catalog_resource.go b/internal/services/identitygovernance/access_package_catalog_resource.go index cc1fa4113b..36362198d4 100644 --- a/internal/services/identitygovernance/access_package_catalog_resource.go +++ b/internal/services/identitygovernance/access_package_catalog_resource.go @@ -14,63 +14,63 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "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/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const accessPackageCatalogResourceName = "azuread_access_package_catalog" -func accessPackageCatalogResource() *schema.Resource { - return &schema.Resource{ +func accessPackageCatalogResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: accessPackageCatalogResourceCreate, ReadContext: accessPackageCatalogResourceRead, UpdateContext: accessPackageCatalogResourceUpdate, DeleteContext: accessPackageCatalogResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the access package catalog", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "description": { Description: "The description of the access package catalog", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "externally_visible": { Description: "Whether the access packages in this catalog can be requested by users outside the tenant", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "published": { Description: "Whether the access packages in this catalog are available for management", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, @@ -78,7 +78,7 @@ func accessPackageCatalogResource() *schema.Resource { } } -func accessPackageCatalogResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient displayName := d.Get("display_name").(string) @@ -105,7 +105,7 @@ func accessPackageCatalogResourceCreate(ctx context.Context, d *schema.ResourceD return accessPackageCatalogResourceRead(ctx, d, meta) } -func accessPackageCatalogResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient objectId := d.Id() @@ -132,7 +132,7 @@ func accessPackageCatalogResourceUpdate(ctx context.Context, d *schema.ResourceD return accessPackageCatalogResourceRead(ctx, d, meta) } -func accessPackageCatalogResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient objectId := d.Id() @@ -160,7 +160,7 @@ func accessPackageCatalogResourceRead(ctx context.Context, d *schema.ResourceDat return nil } -func accessPackageCatalogResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient accessPackageCatalogId := d.Id() diff --git a/internal/services/identitygovernance/access_package_catalog_resource_test.go b/internal/services/identitygovernance/access_package_catalog_resource_test.go index be27d10c41..37772be94b 100644 --- a/internal/services/identitygovernance/access_package_catalog_resource_test.go +++ b/internal/services/identitygovernance/access_package_catalog_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAccessPackageCatalog_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_catalog", "test") r := AccessPackageCatalogResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -39,10 +38,10 @@ func TestAccAccessPackageCatalog_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_catalog", "test") r := AccessPackageCatalogResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -54,24 +53,24 @@ func TestAccAccessPackageCatalog_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_catalog", "test") r := AccessPackageCatalogResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/identitygovernance/access_package_catalog_role_assignment_resource.go b/internal/services/identitygovernance/access_package_catalog_role_assignment_resource.go index 4f45554a8f..98557c8007 100644 --- a/internal/services/identitygovernance/access_package_catalog_role_assignment_resource.go +++ b/internal/services/identitygovernance/access_package_catalog_role_assignment_resource.go @@ -15,63 +15,63 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func accessPackageCatalogRoleAssignmentResource() *schema.Resource { - return &schema.Resource{ +func accessPackageCatalogRoleAssignmentResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: accessPackageCatalogRoleAssignmentResourceCreate, ReadContext: accessPackageCatalogRoleAssignmentResourceRead, DeleteContext: accessPackageCatalogRoleAssignmentResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "role_id": { Description: "The object ID of the catalog role for this assignment", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "principal_object_id": { Description: "The object ID of the member principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "catalog_id": { Description: "The unique ID of the access package catalog.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, } } -func accessPackageCatalogRoleAssignmentResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogRoleAssignmentResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogRoleAssignmentsClient catalogId := d.Get("catalog_id").(string) @@ -97,7 +97,7 @@ func accessPackageCatalogRoleAssignmentResourceCreate(ctx context.Context, d *sc return accessPackageCatalogRoleAssignmentResourceRead(ctx, d, meta) } -func accessPackageCatalogRoleAssignmentResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogRoleAssignmentResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogRoleAssignmentsClient id := d.Id() @@ -120,7 +120,7 @@ func accessPackageCatalogRoleAssignmentResourceRead(ctx context.Context, d *sche return nil } -func accessPackageCatalogRoleAssignmentResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogRoleAssignmentResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogRoleAssignmentsClient if _, err := client.Delete(ctx, d.Id()); err != nil { diff --git a/internal/services/identitygovernance/access_package_catalog_role_assignment_resource_test.go b/internal/services/identitygovernance/access_package_catalog_role_assignment_resource_test.go index 09a3fa65d6..bcbdb0bd8b 100644 --- a/internal/services/identitygovernance/access_package_catalog_role_assignment_resource_test.go +++ b/internal/services/identitygovernance/access_package_catalog_role_assignment_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAccessPackageCatalogRoleAssignmentResource_group(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_catalog_role_assignment", "test") r := AccessPackageCatalogRoleAssignmentResource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.group(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("catalog_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -42,10 +41,10 @@ func TestAccAccessPackageCatalogRoleAssignmentResource_servicePrincipal(t *testi data := acceptance.BuildTestData(t, "azuread_access_package_catalog_role_assignment", "test") r := AccessPackageCatalogRoleAssignmentResource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.servicePrincipal(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("catalog_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), @@ -60,10 +59,10 @@ func TestAccAccessPackageCatalogRoleAssignmentResource_user(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_catalog_role_assignment", "test") r := AccessPackageCatalogRoleAssignmentResource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.user(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("catalog_id").IsUuid(), check.That(data.ResourceName).Key("principal_object_id").IsUuid(), diff --git a/internal/services/identitygovernance/access_package_catalog_role_data_source.go b/internal/services/identitygovernance/access_package_catalog_role_data_source.go index e32957a5af..e980244203 100644 --- a/internal/services/identitygovernance/access_package_catalog_role_data_source.go +++ b/internal/services/identitygovernance/access_package_catalog_role_data_source.go @@ -12,24 +12,24 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/tf/pluginsdk" "github.com/manicminer/hamilton/msgraph" ) -func accessPackageCatalogRoleDataSource() *schema.Resource { - return &schema.Resource{ +func accessPackageCatalogRoleDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: accessPackageCatalogRoleDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the catalog role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "object_id"}, @@ -37,7 +37,7 @@ func accessPackageCatalogRoleDataSource() *schema.Resource { "object_id": { Description: "The object ID of the catalog role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"display_name", "object_id"}, @@ -45,20 +45,20 @@ func accessPackageCatalogRoleDataSource() *schema.Resource { "description": { Description: "The description of the catalog role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "template_id": { Description: "The object ID of the template associated with the catalog role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func accessPackageCatalogRoleDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageCatalogRoleDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogRoleClient var role msgraph.UnifiedRoleDefinition diff --git a/internal/services/identitygovernance/access_package_catalog_role_data_source_test.go b/internal/services/identitygovernance/access_package_catalog_role_data_source_test.go index f50503758d..cb129b44c5 100644 --- a/internal/services/identitygovernance/access_package_catalog_role_data_source_test.go +++ b/internal/services/identitygovernance/access_package_catalog_role_data_source_test.go @@ -6,7 +6,6 @@ package identitygovernance_test import ( "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,10 +16,10 @@ func TestAccAccessPackageCatalogRoleDataSource_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_access_package_catalog_role", "test") r := AccessPackageCatalogRoleDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_name").Exists(), check.That(data.ResourceName).Key("template_id").Exists(), check.That(data.ResourceName).Key("object_id").Exists(), diff --git a/internal/services/identitygovernance/access_package_data_source.go b/internal/services/identitygovernance/access_package_data_source.go index 52dfe0162b..97626845d2 100644 --- a/internal/services/identitygovernance/access_package_data_source.go +++ b/internal/services/identitygovernance/access_package_data_source.go @@ -10,25 +10,25 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func accessPackageDataSource() *schema.Resource { - return &schema.Resource{ +func accessPackageDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: accessPackageDataRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_id": { Description: "The ID of this access package", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ValidateFunc: validation.IsUUID, @@ -37,7 +37,7 @@ func accessPackageDataSource() *schema.Resource { "display_name": { Description: "The display name of the access package", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, AtLeastOneOf: []string{"object_id", "display_name", "catalog_id"}, @@ -47,7 +47,7 @@ func accessPackageDataSource() *schema.Resource { "catalog_id": { Description: "The ID of the Catalog this access package is in", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, AtLeastOneOf: []string{"object_id", "display_name", "catalog_id"}, ConflictsWith: []string{"object_id"}, @@ -56,20 +56,20 @@ func accessPackageDataSource() *schema.Resource { "description": { Description: "The description of the access package", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "hidden": { Description: "Whether the access package is hidden from the requestor", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, } } -func accessPackageDataRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageDataRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageClient var err error diff --git a/internal/services/identitygovernance/access_package_data_source_test.go b/internal/services/identitygovernance/access_package_data_source_test.go index 537a2686a5..5bb60ad1c7 100644 --- a/internal/services/identitygovernance/access_package_data_source_test.go +++ b/internal/services/identitygovernance/access_package_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -18,7 +17,7 @@ func TestAccAccessPackageDataSource_byId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_access_package", "test") r := AccessPackageDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byId(data), Check: r.testCheckFunc(data), @@ -30,7 +29,7 @@ func TestAccAccessPackageDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_access_package", "test") r := AccessPackageDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayName(data), Check: r.testCheckFunc(data), @@ -38,8 +37,8 @@ func TestAccAccessPackageDataSource_byDisplayName(t *testing.T) { }) } -func (AccessPackageDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( +func (AccessPackageDataSource) testCheckFunc(data acceptance.TestData) acceptance.TestCheckFunc { + return acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("description").HasValue(fmt.Sprintf("Access Package %[1]d", data.RandomInteger)), check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("access-package-%[1]d", data.RandomInteger)), check.That(data.ResourceName).Key("hidden").HasValue("true"), diff --git a/internal/services/identitygovernance/access_package_resource.go b/internal/services/identitygovernance/access_package_resource.go index 6a131989e5..018ad1a061 100644 --- a/internal/services/identitygovernance/access_package_resource.go +++ b/internal/services/identitygovernance/access_package_resource.go @@ -13,64 +13,64 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "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/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const accessPackageResourceName = "azuread_access_package" -func accessPackageResource() *schema.Resource { - return &schema.Resource{ +func accessPackageResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: accessPackageResourceCreate, ReadContext: accessPackageResourceRead, UpdateContext: accessPackageResourceUpdate, DeleteContext: accessPackageResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "catalog_id": { Description: "The ID of the Catalog this access package will be created in", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "The display name of the access package", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "description": { Description: "The description of the access package", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "hidden": { Description: "Whether the access package is hidden from the requestor", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, @@ -78,7 +78,7 @@ func accessPackageResource() *schema.Resource { } } -func accessPackageResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageClient accessPackageCatalogClient := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient @@ -108,7 +108,7 @@ func accessPackageResourceCreate(ctx context.Context, d *schema.ResourceData, me return accessPackageResourceRead(ctx, d, meta) } -func accessPackageResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageClient accessPackageCatalogClient := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient @@ -139,7 +139,7 @@ func accessPackageResourceUpdate(ctx context.Context, d *schema.ResourceData, me return accessPackageResourceRead(ctx, d, meta) } -func accessPackageResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageClient objectId := d.Id() @@ -163,7 +163,7 @@ func accessPackageResourceRead(ctx context.Context, d *schema.ResourceData, meta return nil } -func accessPackageResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageClient accessPackageId := d.Id() diff --git a/internal/services/identitygovernance/access_package_resource_catalog_association_resource.go b/internal/services/identitygovernance/access_package_resource_catalog_association_resource.go index bd031e2b88..d0775aeb4b 100644 --- a/internal/services/identitygovernance/access_package_resource_catalog_association_resource.go +++ b/internal/services/identitygovernance/access_package_resource_catalog_association_resource.go @@ -11,47 +11,47 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/services/identitygovernance/parse" "github.com/hashicorp/terraform-provider-azuread/internal/services/identitygovernance/validate" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) -func accessPackageResourceCatalogAssociationResource() *schema.Resource { - return &schema.Resource{ +func accessPackageResourceCatalogAssociationResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: accessPackageResourceCatalogAssociationResourceCreate, ReadContext: accessPackageResourceCatalogAssociationResourceRead, DeleteContext: accessPackageResourceCatalogAssociationResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(validate.AccessPackageResourceCatalogAssociationID), + Importer: pluginsdk.ImporterValidatingResourceId(validate.AccessPackageResourceCatalogAssociationID), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "resource_origin_id": { Description: "The unique identifier of the resource in the origin system. In the case of an Azure AD group, this is the identifier of the group", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, }, "resource_origin_system": { Description: "The type of the resource in the origin system, such as SharePointOnline, AadApplication or AadGroup", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, }, "catalog_id": { Description: "The unique ID of the access package catalog", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, }, @@ -59,7 +59,7 @@ func accessPackageResourceCatalogAssociationResource() *schema.Resource { } } -func accessPackageResourceCatalogAssociationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceCatalogAssociationResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceRequestClient accessPackageCatalogClient := meta.(*clients.Client).IdentityGovernance.AccessPackageCatalogClient resourceClient := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceClient @@ -103,7 +103,7 @@ func accessPackageResourceCatalogAssociationResourceCreate(ctx context.Context, return accessPackageResourceCatalogAssociationResourceRead(ctx, d, meta) } -func accessPackageResourceCatalogAssociationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceCatalogAssociationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { resourceClient := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceClient id, err := parse.AccessPackageResourceCatalogAssociationID(d.Id()) @@ -129,7 +129,7 @@ func accessPackageResourceCatalogAssociationResourceRead(ctx context.Context, d return nil } -func accessPackageResourceCatalogAssociationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourceCatalogAssociationResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceRequestClient resourceClient := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceClient diff --git a/internal/services/identitygovernance/access_package_resource_catalog_association_resource_test.go b/internal/services/identitygovernance/access_package_resource_catalog_association_resource_test.go index 70d102b400..763b0f11d8 100644 --- a/internal/services/identitygovernance/access_package_resource_catalog_association_resource_test.go +++ b/internal/services/identitygovernance/access_package_resource_catalog_association_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAccessPackageResourceCatalogAssociation_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_resource_catalog_association", "test") r := AccessPackageResourceCatalogAssociationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -39,10 +38,10 @@ func TestAccAccessPackageResourceCatalogAssociation_requiresImport(t *testing.T) data := acceptance.BuildTestData(t, "azuread_access_package_resource_catalog_association", "test") r := AccessPackageResourceCatalogAssociationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/identitygovernance/access_package_resource_package_association_resource.go b/internal/services/identitygovernance/access_package_resource_package_association_resource.go index 7fded7bc7c..5e6bc236c8 100644 --- a/internal/services/identitygovernance/access_package_resource_package_association_resource.go +++ b/internal/services/identitygovernance/access_package_resource_package_association_resource.go @@ -12,34 +12,34 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/services/identitygovernance/parse" "github.com/hashicorp/terraform-provider-azuread/internal/services/identitygovernance/validate" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) -func accessPackageResourcePackageAssociationResource() *schema.Resource { - return &schema.Resource{ +func accessPackageResourcePackageAssociationResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: accessPackageResourcePackageAssociationResourceCreate, ReadContext: accessPackageResourcePackageAssociationResourceRead, DeleteContext: accessPackageResourcePackageAssociationResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(validate.AccessPackageResourcePackageAssociationID), + Importer: pluginsdk.ImporterValidatingResourceId(validate.AccessPackageResourcePackageAssociationID), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "access_package_id": { Description: "The ID of access package this resource association is configured to", - Type: schema.TypeString, + Type: pluginsdk.TypeString, ValidateFunc: validation.IsUUID, Required: true, ForceNew: true, @@ -47,14 +47,14 @@ func accessPackageResourcePackageAssociationResource() *schema.Resource { "catalog_resource_association_id": { Description: "The ID of the access package catalog association", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, }, "access_type": { Description: "The role of access type to the specified resource, valid values are `Member` and `Owner`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, Default: "Member", @@ -67,7 +67,7 @@ func accessPackageResourcePackageAssociationResource() *schema.Resource { } } -func accessPackageResourcePackageAssociationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourcePackageAssociationResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceRoleScopeClient resourceClient := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceClient @@ -113,7 +113,7 @@ func accessPackageResourcePackageAssociationResourceCreate(ctx context.Context, return accessPackageResourcePackageAssociationResourceRead(ctx, d, meta) } -func accessPackageResourcePackageAssociationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourcePackageAssociationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceRoleScopeClient accessPackageClient := meta.(*clients.Client).IdentityGovernance.AccessPackageClient @@ -146,7 +146,7 @@ func accessPackageResourcePackageAssociationResourceRead(ctx context.Context, d return nil } -func accessPackageResourcePackageAssociationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func accessPackageResourcePackageAssociationResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).IdentityGovernance.AccessPackageResourceRoleScopeClient id, err := parse.AccessPackageResourcePackageAssociationID(d.Id()) diff --git a/internal/services/identitygovernance/access_package_resource_package_association_resource_test.go b/internal/services/identitygovernance/access_package_resource_package_association_resource_test.go index b2bcdaf410..89fd1b4cc2 100644 --- a/internal/services/identitygovernance/access_package_resource_package_association_resource_test.go +++ b/internal/services/identitygovernance/access_package_resource_package_association_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,11 +23,11 @@ func TestAccAccessPackageResourcePackageAssociation_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package_resource_package_association", "test") r := AccessPackageResourcePackageAssociationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), Destroy: false, - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/identitygovernance/access_package_resource_test.go b/internal/services/identitygovernance/access_package_resource_test.go index e098492267..339f2678dd 100644 --- a/internal/services/identitygovernance/access_package_resource_test.go +++ b/internal/services/identitygovernance/access_package_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccAccessPackage_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package", "test") r := AccessPackageResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -39,10 +38,10 @@ func TestAccAccessPackage_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package", "test") r := AccessPackageResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -54,24 +53,24 @@ func TestAccAccessPackage_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_access_package", "test") r := AccessPackageResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/identitygovernance/registration.go b/internal/services/identitygovernance/registration.go index bc74b41611..27d4147eff 100644 --- a/internal/services/identitygovernance/registration.go +++ b/internal/services/identitygovernance/registration.go @@ -3,9 +3,7 @@ package identitygovernance -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,8 +20,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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_access_package": accessPackageDataSource(), "azuread_access_package_catalog": accessPackageCatalogDataSource(), "azuread_access_package_catalog_role": accessPackageCatalogRoleDataSource(), @@ -31,8 +29,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_access_package": accessPackageResource(), "azuread_access_package_assignment_policy": accessPackageAssignmentPolicyResource(), "azuread_access_package_catalog": accessPackageCatalogResource(), diff --git a/internal/services/identitygovernance/schema.go b/internal/services/identitygovernance/schema.go index bee2677f62..f7e31706a4 100644 --- a/internal/services/identitygovernance/schema.go +++ b/internal/services/identitygovernance/schema.go @@ -5,36 +5,36 @@ package identitygovernance import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" ) -func schemaLocalizedContent() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ +func schemaLocalizedContent() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "default_text": { Description: "The default text of this question", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "localized_text": { Description: "The localized text of this question", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "language_code": { Description: "The language code of this question content", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.ISO639Language, + ValidateDiagFunc: validation2.ISO639Language, }, "content": { Description: "The localized content of this question", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, }, @@ -44,12 +44,12 @@ func schemaLocalizedContent() *schema.Resource { } } -func schemaUserSet() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ +func schemaUserSet() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "subject_type": { Description: "Type of users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ odata.ShortTypeConnectedOrganizationMembers, @@ -63,13 +63,13 @@ func schemaUserSet() *schema.Resource { "backup": { Description: "For a user in an approval stage, this property indicates whether the user is a backup fallback approver", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "object_id": { Description: "The object ID of the subject", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, }, diff --git a/internal/services/invitations/invitation_resource.go b/internal/services/invitations/invitation_resource.go index ed3a0c7b0a..e878a6cdee 100644 --- a/internal/services/invitations/invitation_resource.go +++ b/internal/services/invitations/invitation_resource.go @@ -7,93 +7,93 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func invitationResource() *schema.Resource { - return &schema.Resource{ +func invitationResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: invitationResourceCreate, ReadContext: invitationResourceRead, DeleteContext: invitationResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "redirect_url": { Description: "The URL that the user should be redirected to once the invitation is redeemed", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, }, "user_email_address": { Description: "The email address of the user being invited", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.StringIsEmailAddress, + ValidateDiagFunc: validation2.StringIsEmailAddress, }, "user_display_name": { Description: "The display name of the user being invited", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "message": { Description: "Customize the message sent to the invited user", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, ForceNew: true, MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "additional_recipients": { Description: "Email addresses of additional recipients the invitation message should be sent to", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.StringIsEmailAddress, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation2.StringIsEmailAddress, }, }, "body": { Description: "Customized message body you want to send if you don't want to send the default message", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ConflictsWith: []string{"message.0.language"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "language": { Description: "The language you want to send the default message in", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ConflictsWith: []string{"message.0.body"}, - ValidateDiagFunc: validate.ISO639Language, + ValidateDiagFunc: validation2.ISO639Language, }, }, }, @@ -101,7 +101,7 @@ func invitationResource() *schema.Resource { "user_type": { Description: "The user type of the user being invited", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, Default: "Guest", @@ -113,20 +113,20 @@ func invitationResource() *schema.Resource { "redeem_url": { Description: "The URL the user can use to redeem their invitation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_id": { Description: "Object ID of the invited user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func invitationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func invitationResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Invitations.InvitationsClient usersClient := meta.(*clients.Client).Invitations.UsersClient @@ -195,7 +195,7 @@ func invitationResourceCreate(ctx context.Context, d *schema.ResourceData, meta return invitationResourceRead(ctx, d, meta) } -func invitationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func invitationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Invitations.UsersClient userID := d.Get("user_id").(string) @@ -216,7 +216,7 @@ func invitationResourceRead(ctx context.Context, d *schema.ResourceData, meta in return nil } -func invitationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func invitationResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Invitations.UsersClient userID := d.Get("user_id").(string) diff --git a/internal/services/invitations/invitation_resource_test.go b/internal/services/invitations/invitation_resource_test.go index 76b34e76fd..3a99c03533 100644 --- a/internal/services/invitations/invitation_resource_test.go +++ b/internal/services/invitations/invitation_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccInvitation_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_invitation", "test") r := InvitationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("redeem_url").Exists(), check.That(data.ResourceName).Key("redirect_url").HasValue("https://portal.azure.com"), @@ -43,10 +42,10 @@ func TestAccInvitation_member(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_invitation", "test") r := InvitationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.member(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("redeem_url").Exists(), check.That(data.ResourceName).Key("redirect_url").HasValue("https://portal.azure.com"), @@ -62,10 +61,10 @@ func TestAccInvitation_message(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_invitation", "test") r := InvitationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withMessage(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("redeem_url").Exists(), check.That(data.ResourceName).Key("redirect_url").HasValue("https://portal.azure.com"), @@ -83,10 +82,10 @@ func TestAccInvitation_messageWithCustomizedBody(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_invitation", "test") r := InvitationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withMessageHavingCustomizedBody(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("redeem_url").Exists(), check.That(data.ResourceName).Key("redirect_url").HasValue("https://portal.azure.com"), @@ -107,10 +106,10 @@ func TestAccInvitation_messageWithLanguage(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_invitation", "test") r := InvitationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withMessageHavingLanguage(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("redeem_url").Exists(), check.That(data.ResourceName).Key("redirect_url").HasValue("https://portal.azure.com"), @@ -130,10 +129,10 @@ func TestAccInvitation_withGroupMembership(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_invitation", fmt.Sprintf("test.%d", count-1)) r := InvitationResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withGroupMembership(data, count), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/invitations/registration.go b/internal/services/invitations/registration.go index b9705dc8a8..33694b725e 100644 --- a/internal/services/invitations/registration.go +++ b/internal/services/invitations/registration.go @@ -3,9 +3,7 @@ package invitations -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,13 +20,13 @@ 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{} +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_invitation": invitationResource(), } } diff --git a/internal/services/policies/claims_mapping_policy_resource.go b/internal/services/policies/claims_mapping_policy_resource.go index 73b5e3c46f..926ea12965 100644 --- a/internal/services/policies/claims_mapping_policy_resource.go +++ b/internal/services/policies/claims_mapping_policy_resource.go @@ -12,47 +12,47 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "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/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) -func claimsMappingPolicyResource() *schema.Resource { - return &schema.Resource{ +func claimsMappingPolicyResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: claimsMappingPolicyResourceCreate, ReadContext: claimsMappingPolicyResourceRead, UpdateContext: claimsMappingPolicyResourceUpdate, DeleteContext: claimsMappingPolicyResourceDelete, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "definition": { Description: "A string collection containing a JSON string that defines the rules and settings for this policy", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "display_name": { Description: "Display name for this policy", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, }, } } -func claimsMappingPolicyResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func claimsMappingPolicyResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Policies.ClaimsMappingPolicyClient claimsMappingPolicy := msgraph.ClaimsMappingPolicy{ @@ -73,7 +73,7 @@ func claimsMappingPolicyResourceCreate(ctx context.Context, d *schema.ResourceDa return claimsMappingPolicyResourceRead(ctx, d, meta) } -func claimsMappingPolicyResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func claimsMappingPolicyResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Policies.ClaimsMappingPolicyClient objectId := d.Id() @@ -94,7 +94,7 @@ func claimsMappingPolicyResourceRead(ctx context.Context, d *schema.ResourceData return nil } -func claimsMappingPolicyResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func claimsMappingPolicyResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Policies.ClaimsMappingPolicyClient objectId := d.Id() @@ -113,7 +113,7 @@ func claimsMappingPolicyResourceUpdate(ctx context.Context, d *schema.ResourceDa return claimsMappingPolicyResourceRead(ctx, d, meta) } -func claimsMappingPolicyResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func claimsMappingPolicyResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Policies.ClaimsMappingPolicyClient objectId := d.Id() diff --git a/internal/services/policies/claims_mapping_policy_resource_test.go b/internal/services/policies/claims_mapping_policy_resource_test.go index 8d6ed1c3d4..3e3958202f 100644 --- a/internal/services/policies/claims_mapping_policy_resource_test.go +++ b/internal/services/policies/claims_mapping_policy_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -23,17 +22,17 @@ func TestClaimsMappingPolicy_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_claims_mapping_policy", "test") r := ClaimsMappingPolicyResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { Config: r.update(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/policies/registration.go b/internal/services/policies/registration.go index 667edf5f75..2e0f30431b 100644 --- a/internal/services/policies/registration.go +++ b/internal/services/policies/registration.go @@ -3,9 +3,7 @@ package policies -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,13 +20,13 @@ 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{} +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_claims_mapping_policy": claimsMappingPolicyResource(), } } diff --git a/internal/services/serviceprincipals/client_config_data_source.go b/internal/services/serviceprincipals/client_config_data_source.go index bc794b74c4..f8d3edbce8 100644 --- a/internal/services/serviceprincipals/client_config_data_source.go +++ b/internal/services/serviceprincipals/client_config_data_source.go @@ -8,47 +8,85 @@ import ( "fmt" "time" - "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/sdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) -func clientConfigDataSource() *schema.Resource { - return &schema.Resource{ - ReadContext: clientConfigDataSourceRead, +type ClientConfigId struct { + TenantId string + ClientId string + ObjectId string +} + +func (id ClientConfigId) ID() string { + return fmt.Sprintf("%s-%s-%s", id.TenantId, id.ClientId, id.ObjectId) +} + +func (ClientConfigId) String() string { + return "Client Config" +} + +type ClientConfigDataSourceModel struct { + ClientId string `tfschema:"client_id"` + TenantId string `tfschema:"tenant_id"` + ObjectId string `tfschema:"object_id"` +} + +type ClientConfigDataSource struct{} + +var _ sdk.DataSource = ClientConfigDataSource{} + +func (r ClientConfigDataSource) ResourceType() string { + return "azurerm_aadb2c_directory" +} - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), +func (r ClientConfigDataSource) ModelObject() interface{} { + return &ClientConfigDataSourceModel{} +} + +func (r ClientConfigDataSource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r ClientConfigDataSource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "client_id": { + Description: "The client ID (application ID) linked to the authenticated principal, or the application used for delegated authentication", + Type: pluginsdk.TypeString, + Computed: true, + }, + + "tenant_id": { + Description: "The tenant ID of the authenticated principal", + Type: pluginsdk.TypeString, + Computed: true, }, - Schema: map[string]*schema.Schema{ - "client_id": { - Description: "The client ID (application ID) linked to the authenticated principal, or the application used for delegated authentication", - Type: schema.TypeString, - Computed: true, - }, - - "tenant_id": { - Description: "The tenant ID of the authenticated principal", - Type: schema.TypeString, - Computed: true, - }, - - "object_id": { - Description: "The object ID of the authenticated principal", - Type: schema.TypeString, - Computed: true, - }, + "object_id": { + Description: "The object ID of the authenticated principal", + Type: pluginsdk.TypeString, + Computed: true, }, } } -func clientConfigDataSourceRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client := meta.(*clients.Client) - d.SetId(fmt.Sprintf("%s-%s-%s", client.TenantID, client.ClientID, client.ObjectID)) - tf.Set(d, "tenant_id", client.TenantID) - tf.Set(d, "client_id", client.ClientID) - tf.Set(d, "object_id", client.ObjectID) - return nil +func (r ClientConfigDataSource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + state := ClientConfigDataSourceModel{ + TenantId: metadata.Client.TenantID, + ClientId: metadata.Client.ClientID, + ObjectId: metadata.Client.ObjectID, + } + + metadata.SetID(ClientConfigId{ + TenantId: metadata.Client.TenantID, + ClientId: metadata.Client.ClientID, + ObjectId: metadata.Client.ObjectID, + }) + + return metadata.Encode(&state) + }, + } } diff --git a/internal/services/serviceprincipals/client_config_data_source_test.go b/internal/services/serviceprincipals/client_config_data_source_test.go index 206e1a1fe1..0c0cd97169 100644 --- a/internal/services/serviceprincipals/client_config_data_source_test.go +++ b/internal/services/serviceprincipals/client_config_data_source_test.go @@ -7,7 +7,6 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -19,10 +18,10 @@ func TestAccClientConfigDataSource_basic(t *testing.T) { clientId := os.Getenv("ARM_CLIENT_ID") tenantId := os.Getenv("ARM_TENANT_ID") - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: ClientConfigDataSource{}.basic(), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("client_id").HasValue(clientId), check.That(data.ResourceName).Key("tenant_id").HasValue(tenantId), check.That(data.ResourceName).Key("object_id").IsUuid(), diff --git a/internal/services/serviceprincipals/migrations/service_principal_password_resource.go b/internal/services/serviceprincipals/migrations/service_principal_password_resource.go index a716e32b56..ac40f9c4d8 100644 --- a/internal/services/serviceprincipals/migrations/service_principal_password_resource.go +++ b/internal/services/serviceprincipals/migrations/service_principal_password_resource.go @@ -8,39 +8,38 @@ import ( "fmt" "log" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/parse" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" ) -func ResourceServicePrincipalPasswordInstanceResourceV0() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ +func ResourceServicePrincipalPasswordInstanceResourceV0() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "service_principal_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "key_id": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "description": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, }, "value": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, Sensitive: true, @@ -48,7 +47,7 @@ func ResourceServicePrincipalPasswordInstanceResourceV0() *schema.Resource { }, "start_date": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -56,7 +55,7 @@ func ResourceServicePrincipalPasswordInstanceResourceV0() *schema.Resource { }, "end_date": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -65,11 +64,11 @@ func ResourceServicePrincipalPasswordInstanceResourceV0() *schema.Resource { }, "end_date_relative": { - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ExactlyOneOf: []string{"end_date"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, } diff --git a/internal/services/serviceprincipals/registration.go b/internal/services/serviceprincipals/registration.go index f0394735d1..a40e53497b 100644 --- a/internal/services/serviceprincipals/registration.go +++ b/internal/services/serviceprincipals/registration.go @@ -4,7 +4,8 @@ package serviceprincipals import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azuread/internal/sdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) type Registration struct{} @@ -22,17 +23,16 @@ 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_client_config": clientConfigDataSource(), +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_service_principal": servicePrincipalData(), "azuread_service_principals": servicePrincipalsDataSource(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_service_principal": servicePrincipalResource(), "azuread_service_principal_certificate": servicePrincipalCertificateResource(), "azuread_service_principal_claims_mapping_policy_assignment": servicePrincipalClaimsMappingPolicyAssignmentResource(), @@ -43,3 +43,15 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azuread_synchronization_secret": synchronizationSecretResource(), } } + +// DataSources returns the typed DataSources supported by this service +func (r Registration) DataSources() []sdk.DataSource { + return []sdk.DataSource{ + ClientConfigDataSource{}, + } +} + +// Resources returns the typed Resources supported by this service +func (r Registration) Resources() []sdk.Resource { + return []sdk.Resource{} +} diff --git a/internal/services/serviceprincipals/schema.go b/internal/services/serviceprincipals/schema.go index ba644fa426..830e934d29 100644 --- a/internal/services/serviceprincipals/schema.go +++ b/internal/services/serviceprincipals/schema.go @@ -3,51 +3,51 @@ package serviceprincipals -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" -func schemaAppRolesComputed() *schema.Schema { - return &schema.Schema{ +func schemaAppRolesComputed() *pluginsdk.Schema { + return &pluginsdk.Schema{ Description: "", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier of the app role", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "allowed_member_types": { Description: "Specifies whether this app role definition can be assigned to users and groups, or to other applications (that are accessing this application in a standalone scenario). Possible values are `User` or `Application`, or both", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "description": { Description: "Description of the app role that appears when the role is being assigned and, if the role functions as an application permissions, during the consent experiences", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "display_name": { Description: "Display name for the app role that appears during app role assignment and in consent experiences", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "enabled": { Description: "The unique identifier of the app role", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "value": { Description: "The value that is used for the `roles` claim in ID tokens and OAuth 2.0 access tokens that are authenticating an assigned service or user principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -55,58 +55,58 @@ func schemaAppRolesComputed() *schema.Schema { } } -func schemaOauth2PermissionScopesComputed() *schema.Schema { - return &schema.Schema{ +func schemaOauth2PermissionScopesComputed() *pluginsdk.Schema { + return &pluginsdk.Schema{ Description: "", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "id": { Description: "The unique identifier of the delegated permission. Must be a valid UUID", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "admin_consent_description": { Description: "Delegated permission description that appears in all tenant-wide admin consent experiences, intended to be read by an administrator granting the permission on behalf of all users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "admin_consent_display_name": { Description: "Display name for the delegated permission, intended to be read by an administrator granting the permission on behalf of all users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "enabled": { Description: "Determines if the permission scope is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "type": { Description: "Whether this delegated permission should be considered safe for non-admin users to consent to on behalf of themselves, or whether an administrator should be required for consent to the permissions. Possible values are `User` or `Admin`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_consent_description": { Description: "Delegated permission description that appears in the end user consent experience, intended to be read by a user consenting on their own behalf", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_consent_display_name": { Description: "Display name for the delegated permission that appears in the end user consent experience", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "value": { Description: "The value that is used for the `scp` claim in OAuth 2.0 access tokens", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, diff --git a/internal/services/serviceprincipals/service_principal_certificate_resource.go b/internal/services/serviceprincipals/service_principal_certificate_resource.go index 43e46574e4..cbc23abbef 100644 --- a/internal/services/serviceprincipals/service_principal_certificate_resource.go +++ b/internal/services/serviceprincipals/service_principal_certificate_resource.go @@ -14,57 +14,55 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func servicePrincipalCertificateResource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalCertificateResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: servicePrincipalCertificateResourceCreate, ReadContext: servicePrincipalCertificateResourceRead, DeleteContext: servicePrincipalCertificateResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.CertificateID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "service_principal_id": { Description: "The object ID of the service principal for which this certificate should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "key_id": { Description: "A UUID used to uniquely identify this certificate. If not specified a UUID will be automatically generated", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "encoding": { Description: "Specifies the encoding used for the supplied certificate data", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, Default: "pem", @@ -77,7 +75,7 @@ func servicePrincipalCertificateResource() *schema.Resource { "start_date": { Description: "The start date from which the certificate is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`). If this isn't specified, the current date is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -86,7 +84,7 @@ func servicePrincipalCertificateResource() *schema.Resource { "end_date": { Description: "The end date until which the certificate is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -96,16 +94,16 @@ func servicePrincipalCertificateResource() *schema.Resource { "end_date_relative": { Description: "A relative duration for which the certificate is valid until, for example `240h` (10 days) or `2400h30m`. Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ConflictsWith: []string{"end_date"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "type": { Description: "The type of key/certificate", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ @@ -116,7 +114,7 @@ func servicePrincipalCertificateResource() *schema.Resource { "value": { Description: "The certificate data, which can be PEM encoded, base64 encoded DER or hexadecimal encoded DER", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, Sensitive: true, @@ -125,7 +123,7 @@ func servicePrincipalCertificateResource() *schema.Resource { } } -func servicePrincipalCertificateResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalCertificateResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient objectId := d.Get("service_principal_id").(string) @@ -178,7 +176,7 @@ func servicePrincipalCertificateResourceCreate(ctx context.Context, d *schema.Re // Wait for the credential to appear in the service principal manifest, this can take several minutes timeout, _ := ctx.Deadline() - polledForCredential, err := (&resource.StateChangeConf{ //nolint:staticcheck + polledForCredential, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -213,7 +211,7 @@ func servicePrincipalCertificateResourceCreate(ctx context.Context, d *schema.Re return servicePrincipalCertificateResourceRead(ctx, d, meta) } -func servicePrincipalCertificateResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalCertificateResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.CertificateID(d.Id()) @@ -257,7 +255,7 @@ func servicePrincipalCertificateResourceRead(ctx context.Context, d *schema.Reso return nil } -func servicePrincipalCertificateResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalCertificateResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.CertificateID(d.Id()) diff --git a/internal/services/serviceprincipals/service_principal_certificate_resource_test.go b/internal/services/serviceprincipals/service_principal_certificate_resource_test.go index 7ab61d89f9..08d134b803 100644 --- a/internal/services/serviceprincipals/service_principal_certificate_resource_test.go +++ b/internal/services/serviceprincipals/service_principal_certificate_resource_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -73,10 +72,10 @@ func TestAccServicePrincipalCertificate_basic(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ServicePrincipalCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -91,10 +90,10 @@ func TestAccServicePrincipalCertificate_complete(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ServicePrincipalCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data, startDate, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -108,10 +107,10 @@ func TestAccServicePrincipalCertificate_base64Cert(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ServicePrincipalCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.base64Cert(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -125,10 +124,10 @@ func TestAccServicePrincipalCertificate_hexCert(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ServicePrincipalCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.hexCert(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), @@ -141,10 +140,10 @@ func TestAccServicePrincipalCertificate_relativeEndDate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_certificate", "test") r := ServicePrincipalCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.relativeEndDate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), check.That(data.ResourceName).Key("end_date").Exists(), @@ -159,10 +158,10 @@ func TestAccServicePrincipalCertificate_requiresImport(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := ServicePrincipalCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), ), diff --git a/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource.go b/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource.go index dd77d52892..7422d64a4f 100644 --- a/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource.go +++ b/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource.go @@ -11,36 +11,36 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/services/serviceprincipals/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) -func servicePrincipalClaimsMappingPolicyAssignmentResource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalClaimsMappingPolicyAssignmentResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: servicePrincipalClaimsMappingPolicyAssignmentResourceCreate, ReadContext: servicePrincipalClaimsMappingPolicyAssignmentResourceRead, DeleteContext: servicePrincipalClaimsMappingPolicyAssignmentResourceDelete, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.ObjectSubResourceID(id, "claimsMappingPolicy") return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "claims_mapping_policy_id": { Description: "ID of the claims mapping policy to assign", - Type: schema.TypeString, + Type: pluginsdk.TypeString, ForceNew: true, Required: true, }, "service_principal_id": { Description: "Object ID of the service principal for which to assign the policy", - Type: schema.TypeString, + Type: pluginsdk.TypeString, ForceNew: true, Required: true, }, @@ -48,7 +48,7 @@ func servicePrincipalClaimsMappingPolicyAssignmentResource() *schema.Resource { } } -func servicePrincipalClaimsMappingPolicyAssignmentResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalClaimsMappingPolicyAssignmentResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient tenantId := meta.(*clients.Client).TenantID @@ -89,7 +89,7 @@ func servicePrincipalClaimsMappingPolicyAssignmentResourceCreate(ctx context.Con return servicePrincipalClaimsMappingPolicyAssignmentResourceRead(ctx, d, meta) } -func servicePrincipalClaimsMappingPolicyAssignmentResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalClaimsMappingPolicyAssignmentResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.ClaimsMappingPolicyAssignmentID(d.Id()) @@ -132,7 +132,7 @@ func servicePrincipalClaimsMappingPolicyAssignmentResourceRead(ctx context.Conte return nil } -func servicePrincipalClaimsMappingPolicyAssignmentResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalClaimsMappingPolicyAssignmentResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.ClaimsMappingPolicyAssignmentID(d.Id()) diff --git a/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource_test.go b/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource_test.go index 9fdb69d369..e6c163d903 100644 --- a/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource_test.go +++ b/internal/services/serviceprincipals/service_principal_claims_mapping_policy_assignment_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestClaimsMappingPolicyAssignment_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_claims_mapping_policy_assignment", "test") r := ServicePrincipalClaimsMappingPolicyAssignmentResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basicClaimsMappingPolicyAssignment(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/serviceprincipals/service_principal_data_source.go b/internal/services/serviceprincipals/service_principal_data_source.go index 2178c7fa50..7c2c0adfdd 100644 --- a/internal/services/serviceprincipals/service_principal_data_source.go +++ b/internal/services/serviceprincipals/service_principal_data_source.go @@ -13,74 +13,74 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func servicePrincipalData() *schema.Resource { - return &schema.Resource{ +func servicePrincipalData() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: servicePrincipalDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "object_id": { Description: "The object ID of the service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"application_id", "display_name", "object_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "The display name of the application associated with this service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"application_id", "display_name", "object_id"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "application_id": { Description: "The application ID (client ID) of the application associated with this service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"application_id", "display_name", "object_id"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "account_enabled": { Description: "Whether or not the service principal account is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "alternative_names": { Description: "A list of alternative names, used to retrieve service principals by subscription, identify resource group and full resource ids for managed identities", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "app_role_assignment_required": { Description: "Whether this service principal requires an app role assignment to a user or group before Azure AD will issue a user or access token to the application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "application_tenant_id": { Description: "The tenant ID where the associated application is registered", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, @@ -88,46 +88,46 @@ func servicePrincipalData() *schema.Resource { "app_role_ids": { Description: "Mapping of app role names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "description": { Description: "Description of the service principal provided for internal end-users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "feature_tags": { Description: "Block of features configured for this service principal using tags", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "custom_single_sign_on": { Description: "Whether this service principal represents a custom SAML application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "enterprise": { Description: "Whether this service principal represents an Enterprise Application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "gallery": { Description: "Whether this service principal represents a gallery application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "hide": { Description: "Whether this app is invisible to users in My Apps and Office 365 Launcher", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, @@ -137,31 +137,31 @@ func servicePrincipalData() *schema.Resource { "features": { Deprecated: "This block has been renamed to `feature_tags` and will be removed in version 3.0 of the provider", Description: "Block of features configured for this service principal using tags", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "custom_single_sign_on_app": { Description: "Whether this service principal represents a custom SAML application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "enterprise_application": { Description: "Whether this service principal represents an Enterprise Application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "gallery_application": { Description: "Whether this service principal represents a gallery application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "visible_to_users": { Description: "Whether this app is visible to users in My Apps and Office 365 Launcher", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, }, @@ -170,34 +170,34 @@ func servicePrincipalData() *schema.Resource { "homepage_url": { Description: "Home page or landing page of the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "login_url": { Description: "The URL where the service provider redirects the user to Azure AD to authenticate. Azure AD uses the URL to launch the application from Microsoft 365 or the Azure AD My Apps", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "logout_url": { Description: "The URL that will be used by Microsoft's authorization service to sign out a user using front-channel, back-channel or SAML logout protocols", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "notes": { Description: "Free text field to capture information about the service principal, typically used for operational purposes", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "notification_email_addresses": { Description: "List of email addresses where Azure AD sends a notification when the active certificate is near the expiration date. This is only for the certificates used to sign the SAML token issued for Azure AD Gallery applications", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, @@ -205,43 +205,43 @@ func servicePrincipalData() *schema.Resource { "oauth2_permission_scope_ids": { Description: "Mapping of OAuth2.0 permission scope names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "preferred_single_sign_on_mode": { Description: "The single sign-on mode configured for this application. Azure AD uses the preferred single sign-on mode to launch the application from Microsoft 365 or the Azure AD My Apps", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in with the associated application, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent for the associated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "saml_metadata_url": { Description: "The URL where the service exposes SAML metadata for federation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "saml_single_sign_on": { Description: "Settings related to SAML single sign-on", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "relay_state": { Description: "The relative URI the service provider would redirect to after completion of the single sign-on flow", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -250,38 +250,38 @@ func servicePrincipalData() *schema.Resource { "service_principal_names": { Description: "A list of identifier URI(s), copied over from the associated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "sign_in_audience": { Description: "The Microsoft account types that are supported for the associated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "tags": { Description: "A set of tags to apply to the service principal", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "type": { Description: "Identifies whether the service principal represents an application or a managed identity", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func servicePrincipalDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/serviceprincipals/service_principal_data_source_test.go b/internal/services/serviceprincipals/service_principal_data_source_test.go index 23d2448be5..7fa8e93dc0 100644 --- a/internal/services/serviceprincipals/service_principal_data_source_test.go +++ b/internal/services/serviceprincipals/service_principal_data_source_test.go @@ -9,7 +9,6 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -20,7 +19,7 @@ func TestAccServicePrincipalDataSource_byApplicationId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principal", "test") r := ServicePrincipalDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byApplicationId(data), Check: r.testCheckFunc(data), @@ -32,7 +31,7 @@ func TestAccServicePrincipalDataSource_byDisplayName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principal", "test") r := ServicePrincipalDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayName(data), Check: r.testCheckFunc(data), @@ -44,7 +43,7 @@ func TestAccServicePrincipalDataSource_byDisplayNameDuplicates(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principal", "test") r := ServicePrincipalDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byDisplayNameDuplicates(data), ExpectError: regexp.MustCompile("Found multiple service principals matching filter:"), @@ -56,7 +55,7 @@ func TestAccServicePrincipalDataSource_byObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principal", "test") r := ServicePrincipalDataSource{} - data.DataSourceTest(t, []resource.TestStep{ + data.DataSourceTest(t, []acceptance.TestStep{ { Config: r.byObjectId(data), Check: r.testCheckFunc(data), @@ -64,9 +63,9 @@ func TestAccServicePrincipalDataSource_byObjectId(t *testing.T) { }) } -func (ServicePrincipalDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheckFunc { +func (ServicePrincipalDataSource) testCheckFunc(data acceptance.TestData) acceptance.TestCheckFunc { tenantId := os.Getenv("ARM_TENANT_ID") - return resource.ComposeTestCheckFunc( + return acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("account_enabled").HasValue("false"), check.That(data.ResourceName).Key("alternative_names.#").HasValue("2"), check.That(data.ResourceName).Key("app_role_assignment_required").HasValue("true"), diff --git a/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource.go b/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource.go index 145fe2f7f4..0a0964c55c 100644 --- a/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource.go +++ b/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource.go @@ -13,75 +13,75 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func servicePrincipalDelegatedPermissionGrantResource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalDelegatedPermissionGrantResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: servicePrincipalDelegatedPermissionGrantResourceCreate, UpdateContext: servicePrincipalDelegatedPermissionGrantResourceUpdate, ReadContext: servicePrincipalDelegatedPermissionGrantResourceRead, DeleteContext: servicePrincipalDelegatedPermissionGrantResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if len(id) == 0 { return fmt.Errorf("specified ID is not valid: %q", id) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "claim_values": { Description: "A set of claim values for delegated permission scopes which should be included in access tokens for the resource", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Required: true, MinItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "resource_service_principal_object_id": { Description: "The object ID of the service principal representing the resource to be accessed", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "service_principal_object_id": { Description: "The object ID of the service principal for which this delegated permission grant should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "user_object_id": { Description: "The object ID of the user on behalf of whom the service principal is authorized to access the resource", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, } } -func servicePrincipalDelegatedPermissionGrantResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalDelegatedPermissionGrantResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.DelegatedPermissionGrantsClient servicePrincipalsClient := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient @@ -105,7 +105,7 @@ func servicePrincipalDelegatedPermissionGrantResourceCreate(ctx context.Context, properties := msgraph.DelegatedPermissionGrant{ ClientId: utils.String(servicePrincipalId), ResourceId: utils.String(resourceId), - Scopes: tf.ExpandStringSlicePtr(d.Get("claim_values").(*schema.Set).List()), + Scopes: tf.ExpandStringSlicePtr(d.Get("claim_values").(*pluginsdk.Set).List()), } if v, ok := d.GetOk("user_object_id"); ok && v.(string) != "" { @@ -129,12 +129,12 @@ func servicePrincipalDelegatedPermissionGrantResourceCreate(ctx context.Context, return servicePrincipalDelegatedPermissionGrantResourceRead(ctx, d, meta) } -func servicePrincipalDelegatedPermissionGrantResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalDelegatedPermissionGrantResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.DelegatedPermissionGrantsClient properties := msgraph.DelegatedPermissionGrant{ Id: utils.String(d.Id()), - Scopes: tf.ExpandStringSlicePtr(d.Get("claim_values").(*schema.Set).List()), + Scopes: tf.ExpandStringSlicePtr(d.Get("claim_values").(*pluginsdk.Set).List()), } if _, err := client.Update(ctx, properties); err != nil { @@ -144,7 +144,7 @@ func servicePrincipalDelegatedPermissionGrantResourceUpdate(ctx context.Context, return servicePrincipalDelegatedPermissionGrantResourceRead(ctx, d, meta) } -func servicePrincipalDelegatedPermissionGrantResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalDelegatedPermissionGrantResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.DelegatedPermissionGrantsClient delegatedPermissionGrant, status, err := client.Get(ctx, d.Id(), odata.Query{}) @@ -165,7 +165,7 @@ func servicePrincipalDelegatedPermissionGrantResourceRead(ctx context.Context, d return nil } -func servicePrincipalDelegatedPermissionGrantResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalDelegatedPermissionGrantResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.DelegatedPermissionGrantsClient id := d.Id() diff --git a/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource_test.go b/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource_test.go index 03de94ee6e..b54c380024 100644 --- a/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource_test.go +++ b/internal/services/serviceprincipals/service_principal_delegated_permission_grant_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccServicePrincipalDelegatedPermissionGrant_allUsers(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_delegated_permission_grant", "test") r := ServicePrincipalDelegatedPermissionGrantResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.allUsers(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -39,10 +38,10 @@ func TestAccServicePrincipalDelegatedPermissionGrant_singleUser(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_delegated_permission_grant", "test") r := ServicePrincipalDelegatedPermissionGrantResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.singleUser(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/serviceprincipals/service_principal_password_resource.go b/internal/services/serviceprincipals/service_principal_password_resource.go index 1f89d6e131..17bae881b5 100644 --- a/internal/services/serviceprincipals/service_principal_password_resource.go +++ b/internal/services/serviceprincipals/service_principal_password_resource.go @@ -14,33 +14,31 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/migrations" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" ) -func servicePrincipalPasswordResource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalPasswordResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: servicePrincipalPasswordResourceCreate, ReadContext: servicePrincipalPasswordResourceRead, DeleteContext: servicePrincipalPasswordResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, SchemaVersion: 1, - StateUpgraders: []schema.StateUpgrader{ + StateUpgraders: []pluginsdk.StateUpgrader{ { Type: migrations.ResourceServicePrincipalPasswordInstanceResourceV0().CoreConfigSchema().ImpliedType(), Upgrade: migrations.ResourceServicePrincipalPasswordInstanceStateUpgradeV0, @@ -48,18 +46,18 @@ func servicePrincipalPasswordResource() *schema.Resource { }, }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "service_principal_id": { Description: "The object ID of the service principal for which this password should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "A display name for the password", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -67,7 +65,7 @@ func servicePrincipalPasswordResource() *schema.Resource { "start_date": { Description: "The start date from which the password is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`). If this isn't specified, the current date is used", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -76,7 +74,7 @@ func servicePrincipalPasswordResource() *schema.Resource { "end_date": { Description: "The end date until which the password is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -86,32 +84,32 @@ func servicePrincipalPasswordResource() *schema.Resource { "end_date_relative": { Description: "A relative duration for which the password is valid until, for example `240h` (10 days) or `2400h30m`. Changing this field forces a new resource to be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ForceNew: true, ConflictsWith: []string{"end_date"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "rotate_when_changed": { Description: "Arbitrary map of values that, when changed, will trigger rotation of the password", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Optional: true, ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "key_id": { Description: "A UUID used to uniquely identify this password credential", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "value": { Description: "The password for this service principal, which is generated by Azure Active Directory", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, Sensitive: true, }, @@ -119,7 +117,7 @@ func servicePrincipalPasswordResource() *schema.Resource { } } -func servicePrincipalPasswordResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalPasswordResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient objectId := d.Get("service_principal_id").(string) @@ -167,7 +165,7 @@ func servicePrincipalPasswordResourceCreate(ctx context.Context, d *schema.Resou // Wait for the credential to appear in the service principal manifest, this can take several minutes timeout, _ := ctx.Deadline() - polledForCredential, err := (&resource.StateChangeConf{ //nolint:staticcheck + polledForCredential, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -203,7 +201,7 @@ func servicePrincipalPasswordResourceCreate(ctx context.Context, d *schema.Resou return servicePrincipalPasswordResourceRead(ctx, d, meta) } -func servicePrincipalPasswordResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalPasswordResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.PasswordID(d.Id()) @@ -256,7 +254,7 @@ func servicePrincipalPasswordResourceRead(ctx context.Context, d *schema.Resourc return nil } -func servicePrincipalPasswordResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalPasswordResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.PasswordID(d.Id()) diff --git a/internal/services/serviceprincipals/service_principal_password_resource_test.go b/internal/services/serviceprincipals/service_principal_password_resource_test.go index 45fc4129c9..1831f0f255 100644 --- a/internal/services/serviceprincipals/service_principal_password_resource_test.go +++ b/internal/services/serviceprincipals/service_principal_password_resource_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -26,10 +25,10 @@ func TestAccServicePrincipalPassword_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_password", "test") r := ServicePrincipalPasswordResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), check.That(data.ResourceName).Key("start_date").Exists(), @@ -46,10 +45,10 @@ func TestAccServicePrincipalPassword_complete(t *testing.T) { endDate := time.Now().AddDate(0, 5, 27).UTC().Format(time.RFC3339) r := ServicePrincipalPasswordResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data, startDate, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("key_id").Exists(), check.That(data.ResourceName).Key("start_date").Exists(), @@ -64,10 +63,10 @@ func TestAccServicePrincipalPassword_relativeEndDate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_password", "test") r := ServicePrincipalPasswordResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.relativeEndDate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("end_date").Exists(), check.That(data.ResourceName).Key("end_date_relative").HasValue("8760h"), diff --git a/internal/services/serviceprincipals/service_principal_resource.go b/internal/services/serviceprincipals/service_principal_resource.go index 89e5427379..37cdc47699 100644 --- a/internal/services/serviceprincipals/service_principal_resource.go +++ b/internal/services/serviceprincipals/service_principal_resource.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "strings" @@ -15,107 +16,106 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) const servicePrincipalResourceName = "azuread_service_principal" -func servicePrincipalResource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: servicePrincipalResourceCreate, ReadContext: servicePrincipalResourceRead, UpdateContext: servicePrincipalResourceUpdate, DeleteContext: servicePrincipalResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(10 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(10 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "application_id": { Description: "The application ID (client ID) of the application for which to create a service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "account_enabled": { Description: "Whether or not the service principal account is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "alternative_names": { Description: "A list of alternative names, used to retrieve service principals by subscription, identify resource group and full resource ids for managed identities", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "app_role_assignment_required": { Description: "Whether this service principal requires an app role assignment to a user or group before Azure AD will issue a user or access token to the application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "description": { Description: "Description of the service principal provided for internal end-users", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringLenBetween(0, 1024), }, "feature_tags": { Description: "Block of features to configure for this service principal using tags", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ConflictsWith: []string{"features", "tags"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "custom_single_sign_on": { Description: "Whether this service principal represents a custom SAML application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "enterprise": { Description: "Whether this service principal represents an Enterprise Application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "gallery": { Description: "Whether this service principal represents a gallery application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "hide": { Description: "Whether this app is invisible to users in My Apps and Office 365 Launcher", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, }, @@ -125,33 +125,33 @@ func servicePrincipalResource() *schema.Resource { "features": { Deprecated: "This block has been renamed to `feature_tags` and will be removed in version 3.0 of the provider", Description: "Block of features to configure for this service principal using tags", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ConflictsWith: []string{"feature_tags", "tags"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "custom_single_sign_on_app": { Description: "Whether this service principal represents a custom SAML application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "enterprise_application": { Description: "Whether this service principal represents an Enterprise Application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "gallery_application": { Description: "Whether this service principal represents a gallery application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, "visible_to_users": { Description: "Whether this app is visible to users in My Apps and Office 365 Launcher", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, @@ -161,42 +161,42 @@ func servicePrincipalResource() *schema.Resource { "login_url": { Description: "The URL where the service provider redirects the user to Azure AD to authenticate. Azure AD uses the URL to launch the application from Microsoft 365 or the Azure AD My Apps. When blank, Azure AD performs IdP-initiated sign-on for applications configured with SAML-based single sign-on", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.IsHttpOrHttpsUrl, + ValidateDiagFunc: validation2.IsHttpOrHttpsUrl, }, "notes": { Description: "Free text field to capture information about the service principal, typically used for operational purposes", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringLenBetween(0, 1024), }, "notification_email_addresses": { Description: "List of email addresses where Azure AD sends a notification when the active certificate is near the expiration date. This is only for the certificates used to sign the SAML token issued for Azure AD Gallery applications", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "owners": { Description: "A list of object IDs of principals that will be granted ownership of the service principal", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Set: schema.HashString, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Set: pluginsdk.HashString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "preferred_single_sign_on_mode": { Description: "The single sign-on mode configured for this application. Azure AD uses the preferred single sign-on mode to launch the application from Microsoft 365 or the Azure AD My Apps", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ string(msgraph.PreferredSingleSignOnModeNone), @@ -209,19 +209,19 @@ func servicePrincipalResource() *schema.Resource { "tags": { Description: "A set of tags to apply to the service principal", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, Computed: true, - Set: schema.HashString, + Set: pluginsdk.HashString, ConflictsWith: []string{"features", "feature_tags"}, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "use_existing": { Description: "When true, the resource will return an existing service principal instead of failing with an error", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, }, @@ -229,34 +229,34 @@ func servicePrincipalResource() *schema.Resource { "app_role_ids": { Description: "Mapping of app role names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "application_tenant_id": { Description: "The tenant ID where the associated application is registered", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "display_name": { Description: "The display name of the application associated with this service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "homepage_url": { Description: "Home page or landing page of the application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "logout_url": { Description: "The URL that will be used by Microsoft's authorization service to sign out a user using front-channel, back-channel or SAML logout protocols", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, @@ -264,47 +264,47 @@ func servicePrincipalResource() *schema.Resource { "oauth2_permission_scope_ids": { Description: "Mapping of OAuth2.0 permission scope names to UUIDs", - Type: schema.TypeMap, + Type: pluginsdk.TypeMap, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "object_id": { Description: "The object ID of the service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "redirect_uris": { Description: "The URLs where user tokens are sent for sign-in with the associated application, or the redirect URIs where OAuth 2.0 authorization codes and access tokens are sent for the associated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "saml_metadata_url": { Description: "The URL where the service exposes SAML metadata for federation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "saml_single_sign_on": { Description: "Settings related to SAML single sign-on", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, MaxItems: 1, DiffSuppressFunc: servicePrincipalDiffSuppress, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "relay_state": { Description: "The relative URI the service provider would redirect to after completion of the single sign-on flow", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, }, @@ -312,29 +312,29 @@ func servicePrincipalResource() *schema.Resource { "service_principal_names": { Description: "A list of identifier URI(s), copied over from the associated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "sign_in_audience": { Description: "The Microsoft account types that are supported for the associated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "type": { Description: "Identifies whether the service principal represents an application or a managed identity", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func servicePrincipalDiffSuppress(k, old, new string, d *schema.ResourceData) bool { +func servicePrincipalDiffSuppress(k, old, new string, d *pluginsdk.ResourceData) bool { suppress := false switch { @@ -352,7 +352,7 @@ func servicePrincipalDiffSuppress(k, old, new string, d *schema.ResourceData) bo return suppress } -func servicePrincipalResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient directoryObjectsClient := meta.(*clients.Client).ServicePrincipals.DirectoryObjectsClient callerId := meta.(*clients.Client).ObjectID @@ -392,7 +392,7 @@ func servicePrincipalResourceCreate(ctx context.Context, d *schema.ResourceData, } else if v, ok := d.GetOk("features"); ok { tags = helpers.ApplicationExpandFeatures(v.([]interface{})) } else { - tags = tf.ExpandStringSlice(d.Get("tags").(*schema.Set).List()) + tags = tf.ExpandStringSlice(d.Get("tags").(*pluginsdk.Set).List()) } // Set a temporary description as we'll attempt to patch the service principal with the correct description after creating it @@ -404,13 +404,13 @@ func servicePrincipalResourceCreate(ctx context.Context, d *schema.ResourceData, properties := msgraph.ServicePrincipal{ AccountEnabled: utils.Bool(d.Get("account_enabled").(bool)), - AlternativeNames: tf.ExpandStringSlicePtr(d.Get("alternative_names").(*schema.Set).List()), + AlternativeNames: tf.ExpandStringSlicePtr(d.Get("alternative_names").(*pluginsdk.Set).List()), AppId: utils.String(d.Get("application_id").(string)), AppRoleAssignmentRequired: utils.Bool(d.Get("app_role_assignment_required").(bool)), Description: utils.NullableString(tempDescription), LoginUrl: utils.NullableString(d.Get("login_url").(string)), Notes: utils.NullableString(d.Get("notes").(string)), - NotificationEmailAddresses: tf.ExpandStringSlicePtr(d.Get("notification_email_addresses").(*schema.Set).List()), + NotificationEmailAddresses: tf.ExpandStringSlicePtr(d.Get("notification_email_addresses").(*pluginsdk.Set).List()), PreferredSingleSignOnMode: utils.NullableString(d.Get("preferred_single_sign_on_mode").(string)), SamlSingleSignOnSettings: expandSamlSingleSignOn(d.Get("saml_single_sign_on").([]interface{})), Tags: &tags, @@ -439,7 +439,7 @@ func servicePrincipalResourceCreate(ctx context.Context, d *schema.ResourceData, // Retrieve and set the initial owners, which can be up to 20 in total when creating the service principal if v, ok := d.GetOk("owners"); ok { ownerCount := 0 - for _, ownerIdRaw := range v.(*schema.Set).List() { + for _, ownerIdRaw := range v.(*pluginsdk.Set).List() { ownerId := ownerIdRaw.(string) // If the calling principal was found in the specified owners, we won't remove them later @@ -509,7 +509,7 @@ func servicePrincipalResourceCreate(ctx context.Context, d *schema.ResourceData, return servicePrincipalResourceRead(ctx, d, meta) } -func servicePrincipalResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient tenantId := meta.(*clients.Client).TenantID @@ -519,20 +519,20 @@ func servicePrincipalResourceUpdate(ctx context.Context, d *schema.ResourceData, } else if v, ok := d.GetOk("features"); ok && len(v.([]interface{})) > 0 && d.HasChange("features") { tags = helpers.ApplicationExpandFeatures(v.([]interface{})) } else { - tags = tf.ExpandStringSlice(d.Get("tags").(*schema.Set).List()) + tags = tf.ExpandStringSlice(d.Get("tags").(*pluginsdk.Set).List()) } properties := msgraph.ServicePrincipal{ DirectoryObject: msgraph.DirectoryObject{ Id: utils.String(d.Id()), }, - AlternativeNames: tf.ExpandStringSlicePtr(d.Get("alternative_names").(*schema.Set).List()), + AlternativeNames: tf.ExpandStringSlicePtr(d.Get("alternative_names").(*pluginsdk.Set).List()), AccountEnabled: utils.Bool(d.Get("account_enabled").(bool)), AppRoleAssignmentRequired: utils.Bool(d.Get("app_role_assignment_required").(bool)), Description: utils.NullableString(d.Get("description").(string)), LoginUrl: utils.NullableString(d.Get("login_url").(string)), Notes: utils.NullableString(d.Get("notes").(string)), - NotificationEmailAddresses: tf.ExpandStringSlicePtr(d.Get("notification_email_addresses").(*schema.Set).List()), + NotificationEmailAddresses: tf.ExpandStringSlicePtr(d.Get("notification_email_addresses").(*pluginsdk.Set).List()), PreferredSingleSignOnMode: utils.NullableString(d.Get("preferred_single_sign_on_mode").(string)), SamlSingleSignOnSettings: expandSamlSingleSignOn(d.Get("saml_single_sign_on").([]interface{})), Tags: &tags, @@ -548,7 +548,7 @@ func servicePrincipalResourceUpdate(ctx context.Context, d *schema.ResourceData, return tf.ErrorDiagF(err, "Could not retrieve owners for service principal with object ID: %q", d.Id()) } - desiredOwners := *tf.ExpandStringSlicePtr(d.Get("owners").(*schema.Set).List()) + desiredOwners := *tf.ExpandStringSlicePtr(d.Get("owners").(*pluginsdk.Set).List()) existingOwners := *owners ownersForRemoval := utils.Difference(existingOwners, desiredOwners) ownersToAdd := utils.Difference(desiredOwners, existingOwners) @@ -579,7 +579,7 @@ func servicePrincipalResourceUpdate(ctx context.Context, d *schema.ResourceData, return servicePrincipalResourceRead(ctx, d, meta) } -func servicePrincipalResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient objectId := d.Id() @@ -641,7 +641,7 @@ func servicePrincipalResourceRead(ctx context.Context, d *schema.ResourceData, m return nil } -func servicePrincipalResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient servicePrincipalId := d.Id() diff --git a/internal/services/serviceprincipals/service_principal_resource_test.go b/internal/services/serviceprincipals/service_principal_resource_test.go index 14d4f258c2..d4850a7610 100644 --- a/internal/services/serviceprincipals/service_principal_resource_test.go +++ b/internal/services/serviceprincipals/service_principal_resource_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -27,10 +26,10 @@ func TestAccServicePrincipal_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -43,10 +42,10 @@ func TestAccServicePrincipal_complete(t *testing.T) { r := ServicePrincipalResource{} tenantId := os.Getenv("ARM_TENANT_ID") - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("2"), check.That(data.ResourceName).Key("app_roles.#").HasValue("2"), @@ -69,10 +68,10 @@ func TestAccServicePrincipal_completeUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_roles.#").HasValue("0"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("0"), @@ -83,7 +82,7 @@ func TestAccServicePrincipal_completeUpdate(t *testing.T) { data.ImportStep("use_existing"), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_roles.#").HasValue("2"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("2"), @@ -94,7 +93,7 @@ func TestAccServicePrincipal_completeUpdate(t *testing.T) { data.ImportStep("use_existing"), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_roles.#").HasValue("0"), check.That(data.ResourceName).Key("app_role_ids.%").HasValue("0"), @@ -110,10 +109,10 @@ func TestAccServicePrincipal_featureTags(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -125,66 +124,66 @@ func TestAccServicePrincipal_featureTagsUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.noFeatureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.noFeatureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("use_existing"), { Config: r.featureTags(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -196,10 +195,10 @@ func TestAccServicePrincipal_owners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -207,7 +206,7 @@ func TestAccServicePrincipal_owners(t *testing.T) { data.ImportStep(), { Config: r.singleOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -215,7 +214,7 @@ func TestAccServicePrincipal_owners(t *testing.T) { data.ImportStep(), { Config: r.noOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -223,7 +222,7 @@ func TestAccServicePrincipal_owners(t *testing.T) { data.ImportStep(), { Config: r.singleOwner(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("1"), ), @@ -231,7 +230,7 @@ func TestAccServicePrincipal_owners(t *testing.T) { data.ImportStep(), { Config: r.threeOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("3"), ), @@ -239,7 +238,7 @@ func TestAccServicePrincipal_owners(t *testing.T) { data.ImportStep(), { Config: r.noOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -252,10 +251,10 @@ func TestAccApplication_createWithNoOwners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.noOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("0"), ), @@ -268,10 +267,10 @@ func TestAccServicePrincipal_manyOwners(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.manyOwners(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("owners.#").HasValue("45"), ), @@ -284,10 +283,10 @@ func TestAccServicePrincipal_useExisting(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "msgraph") r := ServicePrincipalResource{} - data.ResourceTestIgnoreDangling(t, r, []resource.TestStep{ + data.ResourceTestIgnoreDangling(t, r, []acceptance.TestStep{ { Config: r.useExisting(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("app_roles.#").Exists(), check.That(data.ResourceName).Key("app_role_ids.%").Exists(), @@ -303,10 +302,10 @@ func TestAccServicePrincipal_fromApplicationTemplate(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal", "test") r := ServicePrincipalResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.fromApplicationTemplate(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource.go b/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource.go index c91520ba80..d9d19468a2 100644 --- a/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource.go +++ b/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "regexp" @@ -15,57 +16,55 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func servicePrincipalTokenSigningCertificateResource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalTokenSigningCertificateResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: servicePrincipalTokenSigningCertificateResourceCreate, ReadContext: servicePrincipalTokenSigningCertificateResourceRead, DeleteContext: servicePrincipalTokenSigningCertificateResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SigningCertificateID(id) return err }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "service_principal_id": { Description: "The object ID of the service principal for which this certificate should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "display_name": { Description: "A friendly name for the certificate", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, - ValidateDiagFunc: validate.ValidateDiag(validation.StringMatch(regexp.MustCompile("^CN=.+$|^$"), "")), + ValidateDiagFunc: validation2.ValidateDiag(validation.StringMatch(regexp.MustCompile("^CN=.+$|^$"), "")), }, "end_date": { Description: "The end date until which the certificate is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`). Default is 3 years from current date.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ForceNew: true, @@ -74,25 +73,25 @@ func servicePrincipalTokenSigningCertificateResource() *schema.Resource { "key_id": { Description: "A UUID used to uniquely identify the verify certificate.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "thumbprint": { Description: "The thumbprint of the certificate.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "start_date": { Description: "The start date from which the certificate is valid, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`).", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "value": { Description: "The certificate data, which is PEM encoded but does not include the header/footer", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, Sensitive: true, }, @@ -100,7 +99,7 @@ func servicePrincipalTokenSigningCertificateResource() *schema.Resource { } } -func servicePrincipalTokenSigningCertificateResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalTokenSigningCertificateResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient objectId := d.Get("service_principal_id").(string) @@ -127,7 +126,7 @@ func servicePrincipalTokenSigningCertificateResourceCreate(ctx context.Context, // Wait for the credential to appear in the service principal manifest, this can take several minutes timeout, _ := ctx.Deadline() - polledForCredential, err := (&resource.StateChangeConf{ //nolint:staticcheck + polledForCredential, err := (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -175,7 +174,7 @@ func servicePrincipalTokenSigningCertificateResourceCreate(ctx context.Context, return servicePrincipalTokenSigningCertificateResourceRead(ctx, d, meta) } -func servicePrincipalTokenSigningCertificateResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalTokenSigningCertificateResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.SigningCertificateID(d.Id()) @@ -234,7 +233,7 @@ func servicePrincipalTokenSigningCertificateResourceRead(ctx context.Context, d return nil } -func servicePrincipalTokenSigningCertificateResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalTokenSigningCertificateResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient id, err := parse.SigningCertificateID(d.Id()) diff --git a/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource_test.go b/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource_test.go index 4a84898b08..68598fb273 100644 --- a/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource_test.go +++ b/internal/services/serviceprincipals/service_principal_token_signing_certificate_resource_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -26,10 +25,10 @@ func TestAccServicePrincipalTokenSigningCertificate_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_service_principal_token_signing_certificate", "test") r := servicePrincipalTokenSigningCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("display_name").Exists(), check.That(data.ResourceName).Key("end_date").Exists(), @@ -47,10 +46,10 @@ func TestAccServicePrincipalTokenSigningCertificate_complete(t *testing.T) { endDate := time.Now().AddDate(0, 3, 27).UTC().Format(time.RFC3339) r := servicePrincipalTokenSigningCertificateResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data, endDate), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("display_name").Exists(), check.That(data.ResourceName).Key("end_date").Exists(), diff --git a/internal/services/serviceprincipals/service_principals_data_source.go b/internal/services/serviceprincipals/service_principals_data_source.go index c769647027..e520d8f51d 100644 --- a/internal/services/serviceprincipals/service_principals_data_source.go +++ b/internal/services/serviceprincipals/service_principals_data_source.go @@ -15,61 +15,61 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/manicminer/hamilton/msgraph" ) -func servicePrincipalsDataSource() *schema.Resource { - return &schema.Resource{ +func servicePrincipalsDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: servicePrincipalsDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "application_ids": { Description: "The application IDs (client IDs) of the applications associated with the service principals", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"application_ids", "display_names", "object_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "display_names": { Description: "The display names of the applications associated with the service principals", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"application_ids", "display_names", "object_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "object_ids": { Description: "The object IDs of the service principals", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"application_ids", "display_names", "object_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "ignore_missing": { Description: "Ignore missing service principals and return the service principals that were found. The data source will still fail if no service principals are found", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, ConflictsWith: []string{"return_all"}, @@ -77,7 +77,7 @@ func servicePrincipalsDataSource() *schema.Resource { "return_all": { Description: "Fetch all service principals with no filter and return all that were found. The data source will still fail if no service principals are found.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, ConflictsWith: []string{"ignore_missing"}, @@ -86,85 +86,85 @@ func servicePrincipalsDataSource() *schema.Resource { "service_principals": { Description: "A list of service_principals", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "account_enabled": { Description: "Whether or not the service principal account is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "app_role_assignment_required": { Description: "Whether this service principal requires an app role assignment to a user or group before Azure AD will issue a user or access token to the application", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "application_id": { Description: "The application ID (client ID) for the associated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "application_tenant_id": { Description: "The tenant ID where the associated application is registered", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "display_name": { Description: "The display name of the application associated with this service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the service principal", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "preferred_single_sign_on_mode": { Description: "The single sign-on mode configured for this application. Azure AD uses the preferred single sign-on mode to launch the application from Microsoft 365 or the Azure AD My Apps", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "saml_metadata_url": { Description: "The URL where the service exposes SAML metadata for federation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "service_principal_names": { Description: "A list of identifier URI(s), copied over from the associated application", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "sign_in_audience": { Description: "The Microsoft account types that are supported for the associated application", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "tags": { Description: "A set of tags to apply to the service principal", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "type": { Description: "Identifies whether the service principal represents an application or a managed identity", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -174,7 +174,7 @@ func servicePrincipalsDataSource() *schema.Resource { } } -func servicePrincipalsDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func servicePrincipalsDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/serviceprincipals/service_principals_data_source_test.go b/internal/services/serviceprincipals/service_principals_data_source_test.go index d37f0a8fe1..a1b4b1db3c 100644 --- a/internal/services/serviceprincipals/service_principals_data_source_test.go +++ b/internal/services/serviceprincipals/service_principals_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,9 +16,9 @@ type ServicePrincipalsDataSource struct{} func TestAccServicePrincipalsDataSource_byApplicationIds(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.byApplicationIds(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("application_ids.#").HasValue("2"), check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), @@ -31,9 +30,9 @@ func TestAccServicePrincipalsDataSource_byApplicationIds(t *testing.T) { func TestAccServicePrincipalsDataSource_byApplicationIdsWithIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.byApplicationIdsWithIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("application_ids.#").HasValue("2"), check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), @@ -45,9 +44,9 @@ func TestAccServicePrincipalsDataSource_byApplicationIdsWithIgnoreMissing(t *tes func TestAccServicePrincipalsDataSource_byDisplayNames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.byDisplayNames(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("service_principals.#").HasValue("2"), @@ -58,9 +57,9 @@ func TestAccServicePrincipalsDataSource_byDisplayNames(t *testing.T) { func TestAccServicePrincipalsDataSource_byDisplayNamesWithIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.byDisplayNamesWithIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("3"), check.That(data.ResourceName).Key("object_ids.#").HasValue("3"), check.That(data.ResourceName).Key("service_principals.#").HasValue("3"), @@ -71,9 +70,9 @@ func TestAccServicePrincipalsDataSource_byDisplayNamesWithIgnoreMissing(t *testi func TestAccServicePrincipalsDataSource_byObjectIds(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.byObjectIds(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("service_principals.#").HasValue("2"), @@ -84,9 +83,9 @@ func TestAccServicePrincipalsDataSource_byObjectIds(t *testing.T) { func TestAccServicePrincipalsDataSource_byObjectIdsWithIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.byObjectIdsWithIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("display_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("service_principals.#").HasValue("2"), @@ -97,9 +96,9 @@ func TestAccServicePrincipalsDataSource_byObjectIdsWithIgnoreMissing(t *testing. func TestAccServicePrincipalsDataSource_noNames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.noNames(), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("application_ids.#").HasValue("0"), check.That(data.ResourceName).Key("display_names.#").HasValue("0"), check.That(data.ResourceName).Key("object_ids.#").HasValue("0"), @@ -111,9 +110,9 @@ func TestAccServicePrincipalsDataSource_noNames(t *testing.T) { func TestAccServicePrincipalsDataSource_returnAll(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_service_principals", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: ServicePrincipalsDataSource{}.returnAll(), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("application_ids.#").Exists(), check.That(data.ResourceName).Key("display_names.#").Exists(), check.That(data.ResourceName).Key("object_ids.#").Exists(), diff --git a/internal/services/serviceprincipals/synchronization_job_resource.go b/internal/services/serviceprincipals/synchronization_job_resource.go index 89d2b9ea79..93e8f88169 100644 --- a/internal/services/serviceprincipals/synchronization_job_resource.go +++ b/internal/services/serviceprincipals/synchronization_job_resource.go @@ -13,76 +13,75 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func synchronizationJobResource() *schema.Resource { - return &schema.Resource{ +func synchronizationJobResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: synchronizationJobResourceCreate, ReadContext: synchronizationJobResourceRead, UpdateContext: synchronizationJobResourceUpdate, DeleteContext: synchronizationJobResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(15 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(15 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.SynchronizationJobID(id) return err }), SchemaVersion: 0, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "service_principal_id": { Description: "The object ID of the service principal for which this synchronization job should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "template_id": { Description: "Identifier of the synchronization template this job is based on.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, }, "enabled": { Description: "Whether or not the synchronization job is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Default: true, Optional: true, }, "schedule": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "expiration": { Description: "Date and time when this job will expire, formatted as an RFC3339 date string (e.g. `2018-01-01T01:02:03Z`).", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "interval": { Description: "The interval between synchronization iterations ISO8601. E.g. PT40M run every 40 minutes.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "state": { Description: "State.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -92,7 +91,7 @@ func synchronizationJobResource() *schema.Resource { } } -func synchronizationJobResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationJobResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient spClient := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient objectId := d.Get("service_principal_id").(string) @@ -131,7 +130,7 @@ func synchronizationJobResourceCreate(ctx context.Context, d *schema.ResourceDat // Wait for the job to appear, this can take several moments timeout, _ := ctx.Deadline() - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -166,7 +165,7 @@ func synchronizationJobResourceCreate(ctx context.Context, d *schema.ResourceDat return synchronizationJobResourceRead(ctx, d, meta) } -func synchronizationJobResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationJobResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient id, err := parse.SynchronizationJobID(d.Id()) @@ -190,7 +189,7 @@ func synchronizationJobResourceRead(ctx context.Context, d *schema.ResourceData, return nil } -func synchronizationJobResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationJobResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient id, err := parse.SynchronizationJobID(d.Id()) if err != nil { @@ -212,7 +211,7 @@ func synchronizationJobResourceUpdate(ctx context.Context, d *schema.ResourceDat return synchronizationJobResourceRead(ctx, d, meta) } -func synchronizationJobResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationJobResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient id, err := parse.SynchronizationJobID(d.Id()) diff --git a/internal/services/serviceprincipals/synchronization_job_resource_test.go b/internal/services/serviceprincipals/synchronization_job_resource_test.go index 03cbf1b1a6..1f85766c09 100644 --- a/internal/services/serviceprincipals/synchronization_job_resource_test.go +++ b/internal/services/serviceprincipals/synchronization_job_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccSynchronizationJob_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_synchronization_job", "test") r := SynchronizationJobResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("template_id").Exists(), check.That(data.ResourceName).Key("enabled").HasValue("true"), @@ -41,10 +40,10 @@ func TestAccSynchronizationJob_disabled(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_synchronization_job", "test") r := SynchronizationJobResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.disabled(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("template_id").Exists(), check.That(data.ResourceName).Key("enabled").HasValue("false"), diff --git a/internal/services/serviceprincipals/synchronization_secret_resource.go b/internal/services/serviceprincipals/synchronization_secret_resource.go index f0b26774e9..3599ce6231 100644 --- a/internal/services/serviceprincipals/synchronization_secret_resource.go +++ b/internal/services/serviceprincipals/synchronization_secret_resource.go @@ -13,54 +13,53 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/services/serviceprincipals/parse" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func synchronizationSecretResource() *schema.Resource { - return &schema.Resource{ +func synchronizationSecretResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: synchronizationSecretResourceCreate, ReadContext: synchronizationSecretResourceRead, UpdateContext: synchronizationSecretResourceUpdate, DeleteContext: synchronizationSecretResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(4 * time.Minute), - Update: schema.DefaultTimeout(3 * time.Minute), - Delete: schema.DefaultTimeout(3 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(4 * time.Minute), + Update: pluginsdk.DefaultTimeout(3 * time.Minute), + Delete: pluginsdk.DefaultTimeout(3 * time.Minute), }, SchemaVersion: 0, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "service_principal_id": { Description: "The object ID of the service principal for which this synchronization secret should be created", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "credential": { - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "key": { Description: "Name for this key-value pair.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "value": { Description: "Value for this key-value pair.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, Sensitive: true, }, @@ -71,7 +70,7 @@ func synchronizationSecretResource() *schema.Resource { } } -func synchronizationSecretResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationSecretResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient spClient := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient objectId := d.Get("service_principal_id").(string) @@ -102,7 +101,7 @@ func synchronizationSecretResourceCreate(ctx context.Context, d *schema.Resource // Wait for the secret to appear timeout, _ := ctx.Deadline() - _, err = (&resource.StateChangeConf{ //nolint:staticcheck + _, err = (&pluginsdk.StateChangeConf{ //nolint:staticcheck Pending: []string{"Waiting"}, Target: []string{"Done"}, Timeout: time.Until(timeout), @@ -136,12 +135,12 @@ func synchronizationSecretResourceCreate(ctx context.Context, d *schema.Resource return synchronizationSecretResourceRead(ctx, d, meta) } -func synchronizationSecretResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationSecretResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { // Update is same as create return synchronizationSecretResourceCreate(ctx, d, meta) } -func synchronizationSecretResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationSecretResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient id, err := parse.SynchronizationSecretID(d.Id()) @@ -163,7 +162,7 @@ func synchronizationSecretResourceRead(ctx context.Context, d *schema.ResourceDa return nil } -func synchronizationSecretResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func synchronizationSecretResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).ServicePrincipals.SynchronizationJobClient spClient := meta.(*clients.Client).ServicePrincipals.ServicePrincipalsClient diff --git a/internal/services/serviceprincipals/synchronization_secret_resource_test.go b/internal/services/serviceprincipals/synchronization_secret_resource_test.go index 50dcf7f29a..be493d4d64 100644 --- a/internal/services/serviceprincipals/synchronization_secret_resource_test.go +++ b/internal/services/serviceprincipals/synchronization_secret_resource_test.go @@ -9,7 +9,6 @@ import ( "net/http" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccSynchronizationSecret_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_synchronization_secret", "test") r := SynchronizationSecretResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("credential.#").HasValue("2"), check.That(data.ResourceName).Key("credential.0.key").HasValue("BaseAddress"), diff --git a/internal/services/userflows/registration.go b/internal/services/userflows/registration.go index 2d6c610183..d9b6043ab9 100644 --- a/internal/services/userflows/registration.go +++ b/internal/services/userflows/registration.go @@ -3,9 +3,7 @@ package userflows -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,13 +20,13 @@ func (r Registration) WebsiteCategories() []string { } // SupportedDataSources returns the supported Data Sources supported by this Service -func (r Registration) SupportedDataSources() map[string]*schema.Resource { +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { return nil } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_user_flow_attribute": userFlowAttributeResource(), } } diff --git a/internal/services/userflows/user_flow_attribute_resource.go b/internal/services/userflows/user_flow_attribute_resource.go index d5d766d5d1..9961b91874 100644 --- a/internal/services/userflows/user_flow_attribute_resource.go +++ b/internal/services/userflows/user_flow_attribute_resource.go @@ -14,40 +14,40 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" "github.com/manicminer/hamilton/msgraph" ) -func userFlowAttributeResource() *schema.Resource { - return &schema.Resource{ +func userFlowAttributeResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: userFlowAttributeResourceCreate, ReadContext: userFlowAttributeResourceRead, UpdateContext: userFlowAttributeResourceUpdate, DeleteContext: userFlowAttributeResourceDelete, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "display_name": { Description: "The display name of the user flow attribute.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, }, "data_type": { Description: "The data type of the user flow attribute", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ @@ -61,20 +61,20 @@ func userFlowAttributeResource() *schema.Resource { "description": { Description: "The description of the user flow attribute that is shown to the user at the time of sign-up", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, }, "attribute_type": { Description: "The type of the user flow attribute", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func userFlowAttributeResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userFlowAttributeResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).UserFlows.UserFlowAttributesClient displayName := d.Get("display_name").(string) @@ -110,7 +110,7 @@ func userFlowAttributeResourceCreate(ctx context.Context, d *schema.ResourceData return userFlowAttributeResourceRead(ctx, d, meta) } -func userFlowAttributeResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userFlowAttributeResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).UserFlows.UserFlowAttributesClient id := d.Id() @@ -126,7 +126,7 @@ func userFlowAttributeResourceUpdate(ctx context.Context, d *schema.ResourceData return userFlowAttributeResourceRead(ctx, d, meta) } -func userFlowAttributeResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userFlowAttributeResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).UserFlows.UserFlowAttributesClient id := d.Id() @@ -148,7 +148,7 @@ func userFlowAttributeResourceRead(ctx context.Context, d *schema.ResourceData, return nil } -func userFlowAttributeResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userFlowAttributeResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).UserFlows.UserFlowAttributesClient id := d.Id() diff --git a/internal/services/userflows/user_flow_attribute_resource_test.go b/internal/services/userflows/user_flow_attribute_resource_test.go index ceb9a44b6d..bc0487a3f9 100644 --- a/internal/services/userflows/user_flow_attribute_resource_test.go +++ b/internal/services/userflows/user_flow_attribute_resource_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -24,10 +23,10 @@ func TestAccUserFlowAttribute_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user_flow_attribute", "test") r := UserflowAttributeResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -38,16 +37,16 @@ func TestAccUserFlowAttribute_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user_flow_attribute", "test") r := UserflowAttributeResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, { Config: r.update(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -58,10 +57,10 @@ func TestAccUserFlowAttribute_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user_flow_attribute", "test") r := UserflowAttributeResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, diff --git a/internal/services/users/registration.go b/internal/services/users/registration.go index e5491c98f9..a1eb8758f7 100644 --- a/internal/services/users/registration.go +++ b/internal/services/users/registration.go @@ -3,9 +3,7 @@ package users -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) +import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" type Registration struct{} @@ -22,16 +20,16 @@ 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{ +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_user": userDataSource(), "azuread_users": usersData(), } } // SupportedResources returns the supported Resources supported by this Service -func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{ +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ "azuread_user": userResource(), } } diff --git a/internal/services/users/user_data_source.go b/internal/services/users/user_data_source.go index cc2bf14eae..fc4486d78c 100644 --- a/internal/services/users/user_data_source.go +++ b/internal/services/users/user_data_source.go @@ -12,312 +12,312 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func userDataSource() *schema.Resource { - return &schema.Resource{ +func userDataSource() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: userDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "employee_id": { Description: "The employee identifier assigned to the user by the organisation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ExactlyOneOf: []string{"employee_id", "mail", "mail_nickname", "object_id", "user_principal_name"}, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "mail": { Description: "The SMTP address for the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ExactlyOneOf: []string{"employee_id", "mail", "mail_nickname", "object_id", "user_principal_name"}, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "mail_nickname": { Description: "The email alias of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ExactlyOneOf: []string{"employee_id", "mail", "mail_nickname", "object_id", "user_principal_name"}, Computed: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "object_id": { Description: "The object ID of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"employee_id", "mail", "mail_nickname", "object_id", "user_principal_name"}, - ValidateDiagFunc: validate.UUID, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, "user_principal_name": { Description: "The user principal name (UPN) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, ExactlyOneOf: []string{"employee_id", "mail", "mail_nickname", "object_id", "user_principal_name"}, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "account_enabled": { Description: "Whether or not the account is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "age_group": { Description: "The age group of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "business_phones": { Description: "The telephone numbers for the user", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "city": { Description: "The city in which the user is located", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "company_name": { Description: "The company name which the user is associated. This property can be useful for describing the company that an external user comes from", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "consent_provided_for_minor": { Description: "Whether consent has been obtained for minors", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "cost_center": { Description: "The cost center associated with the user.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "country": { Description: "The country/region in which the user is located, e.g. `US` or `UK`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "creation_type": { Description: "Indicates whether the user account was created as a regular school or work account (`null`), an external account (`Invitation`), a local account for an Azure Active Directory B2C tenant (`LocalAccount`) or self-service sign-up using email verification (`EmailVerified`)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "department": { Description: "The name for the department in which the user works", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "display_name": { Description: "The display name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "division": { Description: "The name of the division in which the user works.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "employee_type": { Description: "Captures enterprise worker type. For example, Employee, Contractor, Consultant, or Vendor.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "external_user_state": { Description: "For an external user invited to the tenant, this property represents the invited user's invitation status", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "fax_number": { Description: "The fax number of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "given_name": { Description: "The given name (first name) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "im_addresses": { Description: "The instant message voice over IP (VOIP) session initiation protocol (SIP) addresses for the user", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "job_title": { Description: "The user’s job title", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "manager_id": { Description: "The object ID of the user's manager", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "mobile_phone": { Description: "The primary cellular telephone number for the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "office_location": { Description: "The office location in the user's place of business", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_distinguished_name": { Description: "The on-premise Active Directory distinguished name (DN) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_domain_name": { Description: "The on-premise FQDN (i.e. dnsDomainName) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_immutable_id": { Description: "The value used to associate an on-premise Active Directory user account with their Azure AD user object", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sam_account_name": { Description: "The on-premise SAM account name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_security_identifier": { Description: "The on-premise security identifier (SID) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sync_enabled": { Description: "Whether this user is synchronized from an on-premises directory (true), no longer synchronized (false), or has never been synchronized (null)", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "onpremises_user_principal_name": { Description: "The on-premise user principal name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "other_mails": { Description: "Additional email addresses for the user", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "postal_code": { Description: "The postal code for the user's postal address. The postal code is specific to the user's country/region. In the United States of America, this attribute contains the ZIP code", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "preferred_language": { Description: "The user's preferred language, in ISO 639-1 notation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "proxy_addresses": { Description: "Email addresses for the user that direct to the same mailbox", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "show_in_address_list": { Description: "Whether or not the Outlook global address list should include this user", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "state": { Description: "The state or province in the user's address", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "street_address": { Description: "The street address of the user's place of business", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "surname": { Description: "The user's surname (family name or last name)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "usage_location": { Description: "The usage location of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_type": { Description: "The user type in the directory. Possible values are `Guest` or `Member`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func userDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.UsersClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/users/user_data_source_test.go b/internal/services/users/user_data_source_test.go index dbca2fb22d..0c96735999 100644 --- a/internal/services/users/user_data_source_test.go +++ b/internal/services/users/user_data_source_test.go @@ -8,7 +8,6 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -19,7 +18,7 @@ func TestAccUserDataSource_byUserPrincipalName(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") r := UserDataSource{} - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: r.byUserPrincipalName(data), Check: r.testCheckFunc(data), }}) @@ -28,7 +27,7 @@ func TestAccUserDataSource_byUserPrincipalName(t *testing.T) { func TestAccUserDataSource_byUserPrincipalNameNonexistent(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UserDataSource{}.byUserPrincipalNameNonexistent(data), ExpectError: regexp.MustCompile("User with UPN \"[^\"]+\" was not found"), }}) @@ -38,7 +37,7 @@ func TestAccUserDataSource_byObjectId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") r := UserDataSource{} - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: r.byObjectId(data), Check: r.testCheckFunc(data), }}) @@ -47,7 +46,7 @@ func TestAccUserDataSource_byObjectId(t *testing.T) { func TestAccUserDataSource_byObjectIdNonexistent(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UserDataSource{}.byObjectIdNonexistent(), ExpectError: regexp.MustCompile("User not found with object ID:"), }}) @@ -57,7 +56,7 @@ func TestAccUserDataSource_byMailNickname(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") r := UserDataSource{} - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: r.byMailNickname(data), Check: r.testCheckFunc(data), }}) @@ -66,7 +65,7 @@ func TestAccUserDataSource_byMailNickname(t *testing.T) { func TestAccUserDataSource_byMailNicknameNonexistent(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UserDataSource{}.byMailNicknameNonexistent(data), ExpectError: regexp.MustCompile("User not found with email alias:"), }}) @@ -76,7 +75,7 @@ func TestAccUserDataSource_byMail(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") r := UserDataSource{} - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: r.byMail(data), Check: r.testCheckFunc(data), }}) @@ -85,7 +84,7 @@ func TestAccUserDataSource_byMail(t *testing.T) { func TestAccUserDataSource_byMailNonexistent(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UserDataSource{}.byMailNonexistent(data), ExpectError: regexp.MustCompile("User not found with mail:"), }}) @@ -95,7 +94,7 @@ func TestAccUserDataSource_byEmployeeId(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") r := UserDataSource{} - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: r.byEmployeeId(data), Check: r.testCheckFunc(data), }}) @@ -104,14 +103,14 @@ func TestAccUserDataSource_byEmployeeId(t *testing.T) { func TestAccUserDataSource_byEmployeeIdNonexistent(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_user", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UserDataSource{}.byEmployeeIdNonexistent(data), ExpectError: regexp.MustCompile("User not found with employee ID:"), }}) } -func (UserDataSource) testCheckFunc(data acceptance.TestData) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( +func (UserDataSource) testCheckFunc(data acceptance.TestData) acceptance.TestCheckFunc { + return acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("account_enabled").Exists(), check.That(data.ResourceName).Key("city").HasValue(fmt.Sprintf("acctestUser-%d-City", data.RandomInteger)), check.That(data.ResourceName).Key("company_name").HasValue(fmt.Sprintf("acctestUser-%d-Company", data.RandomInteger)), diff --git a/internal/services/users/user_resource.go b/internal/services/users/user_resource.go index 9f6614ba4d..db4f3b33fd 100644 --- a/internal/services/users/user_resource.go +++ b/internal/services/users/user_resource.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + validation2 "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "log" "net/http" "strings" @@ -15,18 +16,17 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-azuread/internal/clients" "github.com/hashicorp/terraform-provider-azuread/internal/helpers" "github.com/hashicorp/terraform-provider-azuread/internal/tf" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func userResource() *schema.Resource { - return &schema.Resource{ +func userResource() *pluginsdk.Resource { + return &pluginsdk.Resource{ CreateContext: userResourceCreate, ReadContext: userResourceRead, UpdateContext: userResourceUpdate, @@ -34,45 +34,45 @@ func userResource() *schema.Resource { CustomizeDiff: userResourceCustomizeDiff, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(5 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(5 * time.Minute), + Delete: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Importer: tf.ValidateResourceIDPriorToImport(func(id string) error { + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { if _, err := uuid.ParseUUID(id); err != nil { return fmt.Errorf("specified ID (%q) is not valid: %s", id, err) } return nil }), - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "user_principal_name": { Description: "The user principal name (UPN) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.StringIsEmailAddress, + ValidateDiagFunc: validation2.StringIsEmailAddress, }, "display_name": { Description: "The name to display in the address book for the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Required: true, - ValidateDiagFunc: validate.NoEmptyStrings, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, "account_enabled": { Description: "Whether or not the account should be enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "age_group": { Description: "The age group of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ string(msgraph.AgeGroupNone), @@ -84,29 +84,29 @@ func userResource() *schema.Resource { "business_phones": { Description: "The telephone numbers for the user. Only one number can be set for this property. Read-only for users synced with Azure AD Connect", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "city": { Description: "The city in which the user is located", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "company_name": { Description: "The company name which the user is associated. This property can be useful for describing the company that an external user comes from", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "consent_provided_for_minor": { Description: "Whether consent has been obtained for minors", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{ string(msgraph.ConsentProvidedForMinorNone), @@ -118,118 +118,118 @@ func userResource() *schema.Resource { "cost_center": { Description: "The cost center associated with the user.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "country": { Description: "The country/region in which the user is located, e.g. `US` or `UK`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "department": { Description: "The name for the department in which the user works", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "division": { Description: "The name of the division in which the user works.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "employee_id": { Description: "The employee identifier assigned to the user by the organisation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringLenBetween(0, 16), }, "employee_type": { Description: "Captures enterprise worker type. For example, Employee, Contractor, Consultant, or Vendor.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringInSlice([]string{"Employee", "Contractor", "Consultant", "Vendor"}, false), }, "force_password_change": { Description: "Whether the user is forced to change the password during the next sign-in. Only takes effect when also changing the password", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "given_name": { Description: "The given name (first name) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "fax_number": { Description: "The fax number of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "job_title": { Description: "The user’s job title", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "mail": { Description: "The SMTP address for the user. Cannot be unset.", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, }, "mail_nickname": { Description: "The mail alias for the user. Defaults to the user name part of the user principal name (UPN)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, }, "manager_id": { Description: "The object ID of the user's manager", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "mobile_phone": { Description: "The primary cellular telephone number for the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "office_location": { Description: "The office location in the user's place of business", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "onpremises_immutable_id": { Description: "The value used to associate an on-premise Active Directory user account with their Azure AD user object. This must be specified if you are using a federated domain for the user's `user_principal_name` property when creating a new user account", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, }, "other_mails": { Description: "Additional email addresses for the user", - Type: schema.TypeSet, + Type: pluginsdk.TypeSet, Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "password": { Description: "The password for the user. The password must satisfy minimum requirements as specified by the password policy. The maximum length is 256 characters. This property is required when creating a new user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, Computed: true, Sensitive: true, @@ -238,149 +238,149 @@ func userResource() *schema.Resource { "disable_strong_password": { Description: "Whether the user is allowed weaker passwords than the default policy to be specified.", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "disable_password_expiration": { Description: "Whether the users password is exempt from expiring", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: false, }, "postal_code": { Description: "The postal code for the user's postal address. The postal code is specific to the user's country/region. In the United States of America, this attribute contains the ZIP code", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "preferred_language": { Description: "The user's preferred language, in ISO 639-1 notation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, - ValidateDiagFunc: validate.ISO639Language, + ValidateDiagFunc: validation2.ISO639Language, }, "show_in_address_list": { Description: "Whether or not the Outlook global address list should include this user", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Optional: true, Default: true, }, "state": { Description: "The state or province in the user's address", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "street_address": { Description: "The street address of the user's place of business", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "surname": { Description: "The user's surname (family name or last name)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "usage_location": { Description: "The usage location of the user. Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. The usage location is a two letter country code (ISO standard 3166). Examples include: `NO`, `JP`, and `GB`. Cannot be reset to null once set", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Optional: true, }, "about_me": { Description: "A freeform field for the user to describe themselves", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "creation_type": { Description: "Indicates whether the user account was created as a regular school or work account (`null`), an external account (`Invitation`), a local account for an Azure Active Directory B2C tenant (`LocalAccount`) or self-service sign-up using email verification (`EmailVerified`)", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "external_user_state": { Description: "For an external user invited to the tenant, this property represents the invited user's invitation status", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "im_addresses": { Description: "The instant message voice over IP (VOIP) session initiation protocol (SIP) addresses for the user", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "onpremises_distinguished_name": { Description: "The on-premise Active Directory distinguished name (DN) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_domain_name": { Description: "The on-premise FQDN (i.e. dnsDomainName) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sam_account_name": { Description: "The on-premise SAM account name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_security_identifier": { Description: "The on-premise security identifier (SID) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sync_enabled": { Description: "Whether this user is synchronized from an on-premises directory (true), no longer synchronized (false), or has never been synchronized (null)", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "onpremises_user_principal_name": { Description: "The on-premise user principal name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "proxy_addresses": { Description: "Email addresses for the user that direct to the same mailbox", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, "user_type": { Description: "The user type in the directory. Possible values are `Guest` or `Member`", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, } } -func userResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func userResourceCustomizeDiff(ctx context.Context, diff *pluginsdk.ResourceDiff, meta interface{}) error { ageGroup := diff.Get("age_group").(string) consentRequired := diff.Get("consent_provided_for_minor").(string) @@ -391,7 +391,7 @@ func userResourceCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, m return nil } -func userResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userResourceCreate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.UsersClient directoryObjectsClient := meta.(*clients.Client).Users.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -443,7 +443,7 @@ func userResourceCreate(ctx context.Context, d *schema.ResourceData, meta interf MailNickname: utils.String(mailNickName), MobilePhone: utils.NullableString(d.Get("mobile_phone").(string)), OfficeLocation: utils.NullableString(d.Get("office_location").(string)), - OtherMails: tf.ExpandStringSlicePtr(d.Get("other_mails").(*schema.Set).List()), + OtherMails: tf.ExpandStringSlicePtr(d.Get("other_mails").(*pluginsdk.Set).List()), PasswordPolicies: utils.NullableString(passwordPolicies), PostalCode: utils.NullableString(d.Get("postal_code").(string)), PreferredLanguage: utils.NullableString(d.Get("preferred_language").(string)), @@ -498,7 +498,7 @@ func userResourceCreate(ctx context.Context, d *schema.ResourceData, meta interf return userResourceRead(ctx, d, meta) } -func userResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userResourceUpdate(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.UsersClient directoryObjectsClient := meta.(*clients.Client).Users.DirectoryObjectsClient tenantId := meta.(*clients.Client).TenantID @@ -539,7 +539,7 @@ func userResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interf MailNickname: utils.String(d.Get("mail_nickname").(string)), MobilePhone: utils.NullableString(d.Get("mobile_phone").(string)), OfficeLocation: utils.NullableString(d.Get("office_location").(string)), - OtherMails: tf.ExpandStringSlicePtr(d.Get("other_mails").(*schema.Set).List()), + OtherMails: tf.ExpandStringSlicePtr(d.Get("other_mails").(*pluginsdk.Set).List()), PasswordPolicies: utils.NullableString(passwordPolicies), PostalCode: utils.NullableString(d.Get("postal_code").(string)), PreferredLanguage: utils.NullableString(d.Get("preferred_language").(string)), @@ -588,7 +588,7 @@ func userResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interf return userResourceRead(ctx, d, meta) } -func userResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userResourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.UsersClient objectId := d.Id() @@ -682,7 +682,7 @@ func userResourceRead(ctx context.Context, d *schema.ResourceData, meta interfac return nil } -func userResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func userResourceDelete(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.UsersClient userId := d.Id() diff --git a/internal/services/users/user_resource_test.go b/internal/services/users/user_resource_test.go index f47fb61ffa..cf1c2e8211 100644 --- a/internal/services/users/user_resource_test.go +++ b/internal/services/users/user_resource_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/hashicorp/go-azure-sdk/sdk/odata" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" @@ -25,10 +24,10 @@ func TestAccUser_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user", "test") r := UserResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -40,10 +39,10 @@ func TestAccUser_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user", "test") r := UserResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -55,24 +54,24 @@ func TestAccUser_update(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user", "test") r := UserResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("force_password_change", "password"), { Config: r.complete(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep("force_password_change", "password"), { Config: r.basic(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -86,10 +85,10 @@ func TestAccUser_threeUsersABC(t *testing.T) { dataC := acceptance.BuildTestData(t, "azuread_user", "testC") r := UserResource{} - dataA.ResourceTest(t, r, []resource.TestStep{ + dataA.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.threeUsersABC(dataA), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(dataA.ResourceName).ExistsInAzure(r), check.That(dataB.ResourceName).ExistsInAzure(r), check.That(dataC.ResourceName).ExistsInAzure(r), @@ -105,10 +104,10 @@ func TestAccUser_withRandomProvider(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user", "test") r := UserResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.withRandomProvider(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, @@ -120,7 +119,7 @@ func TestAccUser_passwordOmitted(t *testing.T) { data := acceptance.BuildTestData(t, "azuread_user", "test") r := UserResource{} - data.ResourceTest(t, r, []resource.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.passwordOmitted(data), ExpectError: regexp.MustCompile("`password` is required when creating a new user"), diff --git a/internal/services/users/users_data_source.go b/internal/services/users/users_data_source.go index e7f0132321..bd77af1f99 100644 --- a/internal/services/users/users_data_source.go +++ b/internal/services/users/users_data_source.go @@ -15,74 +15,74 @@ import ( "github.com/hashicorp/go-azure-sdk/sdk/odata" "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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/validation" "github.com/hashicorp/terraform-provider-azuread/internal/utils" - "github.com/hashicorp/terraform-provider-azuread/internal/validate" "github.com/manicminer/hamilton/msgraph" ) -func usersData() *schema.Resource { - return &schema.Resource{ +func usersData() *pluginsdk.Resource { + return &pluginsdk.Resource{ ReadContext: usersDataSourceRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), + Timeouts: &pluginsdk.ResourceTimeout{ + Read: pluginsdk.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ + Schema: map[string]*pluginsdk.Schema{ "employee_ids": { Description: "The employee identifier assigned to the user by the organisation", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "employee_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "mail_nicknames": { Description: "The email aliases of the users", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "employee_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "object_ids": { Description: "The object IDs of the users", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "employee_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.UUID, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID), }, }, "user_principal_names": { Description: "The user principal names (UPNs) of the users", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Optional: true, Computed: true, ExactlyOneOf: []string{"object_ids", "user_principal_names", "mail_nicknames", "employee_ids", "return_all"}, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateDiagFunc: validate.NoEmptyStrings, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty), }, }, "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, + Type: pluginsdk.TypeBool, Optional: true, Default: false, ConflictsWith: []string{"return_all"}, @@ -90,7 +90,7 @@ func usersData() *schema.Resource { "return_all": { 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, + Type: pluginsdk.TypeBool, Optional: true, Default: false, ConflictsWith: []string{"ignore_missing"}, @@ -99,73 +99,73 @@ func usersData() *schema.Resource { "users": { Description: "A list of users", - Type: schema.TypeList, + Type: pluginsdk.TypeList, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ "account_enabled": { Description: "Whether or not the account is enabled", - Type: schema.TypeBool, + Type: pluginsdk.TypeBool, Computed: true, }, "display_name": { Description: "The display name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "employee_id": { Description: "The employee identifier assigned to the user by the organisation", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "mail": { Description: "The primary email address of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "mail_nickname": { Description: "The email alias of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "object_id": { Description: "The object ID of the user", - Type: schema.TypeString, + Type: pluginsdk.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, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_sam_account_name": { Description: "The on-premise SAM account name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "onpremises_user_principal_name": { Description: "The on-premise user principal name of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "usage_location": { Description: "The usage location of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, "user_principal_name": { Description: "The user principal name (UPN) of the user", - Type: schema.TypeString, + Type: pluginsdk.TypeString, Computed: true, }, }, @@ -175,7 +175,7 @@ func usersData() *schema.Resource { } } -func usersDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func usersDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*clients.Client).Users.UsersClient client.BaseClient.DisableRetries = true defer func() { client.BaseClient.DisableRetries = false }() diff --git a/internal/services/users/users_data_source_test.go b/internal/services/users/users_data_source_test.go index 4d4ec59f84..1520f40e8a 100644 --- a/internal/services/users/users_data_source_test.go +++ b/internal/services/users/users_data_source_test.go @@ -7,7 +7,6 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance" "github.com/hashicorp/terraform-provider-azuread/internal/acceptance/check" ) @@ -17,9 +16,9 @@ type UsersDataSource struct{} func TestAccUsersDataSource_byUserPrincipalNames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byUserPrincipalNames(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -32,9 +31,9 @@ func TestAccUsersDataSource_byUserPrincipalNames(t *testing.T) { func TestAccUsersDataSource_byUserPrincipalNamesIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byUserPrincipalNamesIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("3"), check.That(data.ResourceName).Key("object_ids.#").HasValue("3"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("3"), @@ -47,9 +46,9 @@ func TestAccUsersDataSource_byUserPrincipalNamesIgnoreMissing(t *testing.T) { func TestAccUsersDataSource_byObjectIds(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byObjectIds(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -62,9 +61,9 @@ func TestAccUsersDataSource_byObjectIds(t *testing.T) { func TestAccUsersDataSource_byObjectIdsIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byObjectIdsIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -77,9 +76,9 @@ func TestAccUsersDataSource_byObjectIdsIgnoreMissing(t *testing.T) { func TestAccUsersDataSource_byMailNicknames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byMailNicknames(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -92,9 +91,9 @@ func TestAccUsersDataSource_byMailNicknames(t *testing.T) { func TestAccUsersDataSource_byMailNicknamesIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byMailNicknamesIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -107,9 +106,9 @@ func TestAccUsersDataSource_byMailNicknamesIgnoreMissing(t *testing.T) { func TestAccUsersDataSource_byEmployeeIds(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byEmployeeIds(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -122,9 +121,9 @@ func TestAccUsersDataSource_byEmployeeIds(t *testing.T) { func TestAccUsersDataSource_byEmployeeIdsIgnoreMissing(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.byEmployeeIdsIgnoreMissing(data), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("2"), check.That(data.ResourceName).Key("object_ids.#").HasValue("2"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("2"), @@ -137,9 +136,9 @@ func TestAccUsersDataSource_byEmployeeIdsIgnoreMissing(t *testing.T) { func TestAccUsersDataSource_noNames(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.noNames(), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("user_principal_names.#").HasValue("0"), check.That(data.ResourceName).Key("object_ids.#").HasValue("0"), check.That(data.ResourceName).Key("mail_nicknames.#").HasValue("0"), @@ -152,9 +151,9 @@ func TestAccUsersDataSource_noNames(t *testing.T) { func TestAccUsersDataSource_returnAll(t *testing.T) { data := acceptance.BuildTestData(t, "data.azuread_users", "test") - data.DataSourceTest(t, []resource.TestStep{{ + data.DataSourceTest(t, []acceptance.TestStep{{ Config: UsersDataSource{}.returnAll(), - Check: resource.ComposeTestCheckFunc( + Check: acceptance.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(), diff --git a/internal/tf/import.go b/internal/tf/import.go deleted file mode 100644 index 17a2b1ce80..0000000000 --- a/internal/tf/import.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package tf - -import ( - "context" - "fmt" - "log" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -// ResourceIDValidator takes a Resource ID and confirms that it's Valid -type ResourceIDValidator func(resourceId string) error - -// ValidateResourceIDPriorToImport parses the Resource ID to confirm it's -// valid for this Resource prior to performing an import - allowing for incorrect -// Resource ID's to be caught prior to Import and subsequent crashes -func ValidateResourceIDPriorToImport(idParser ResourceIDValidator) *schema.ResourceImporter { - return ValidateResourceIDPriorToImportThen(idParser, schema.ImportStatePassthroughContext) -} - -// ValidateResourceIDPriorToImportThen parses the Resource ID to confirm it's -// valid for this Resource prior to calling the importer - allowing for incorrect -// Resource ID's to be caught prior to Import and subsequent crashes -func ValidateResourceIDPriorToImportThen(idParser ResourceIDValidator, importer schema.StateContextFunc) *schema.ResourceImporter { - return &schema.ResourceImporter{ - StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - log.Printf("[DEBUG] Importing Resource - parsing %q", d.Id()) - - if err := idParser(d.Id()); err != nil { - return []*schema.ResourceData{d}, fmt.Errorf("parsing Resource ID %q: %+v", d.Id(), err) - } - - return importer(ctx, d, meta) - }, - } -} diff --git a/internal/tf/marshall.go b/internal/tf/marshal.go similarity index 100% rename from internal/tf/marshall.go rename to internal/tf/marshal.go diff --git a/internal/tf/pluginsdk.go b/internal/tf/pluginsdk/unknowns.go similarity index 98% rename from internal/tf/pluginsdk.go rename to internal/tf/pluginsdk/unknowns.go index 402e3afed8..c36a77e0c8 100644 --- a/internal/tf/pluginsdk.go +++ b/internal/tf/pluginsdk/unknowns.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package tf +package pluginsdk // PluginSdkUnknownValue is a dummy value used/sent by the plugin SDK when a real value is not known at plan time, // e.g. during a CustomizeDiff function diff --git a/internal/tf/suppress/string.go b/internal/tf/suppress/string.go index 812a840fcc..3e6e6ccf28 100644 --- a/internal/tf/suppress/string.go +++ b/internal/tf/suppress/string.go @@ -6,9 +6,9 @@ package suppress import ( "strings" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" ) -func CaseDifference(_, old, new string, _ *schema.ResourceData) bool { +func CaseDifference(_, old, new string, _ *pluginsdk.ResourceData) bool { return strings.EqualFold(old, new) } diff --git a/internal/validate/diag.go b/internal/tf/validation/diag.go similarity index 97% rename from internal/validate/diag.go rename to internal/tf/validation/diag.go index 7a6f49f5a1..1da716614c 100644 --- a/internal/validate/diag.go +++ b/internal/tf/validation/diag.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "fmt" diff --git a/internal/validate/lang.go b/internal/tf/validation/lang.go similarity index 97% rename from internal/validate/lang.go rename to internal/tf/validation/lang.go index 5731b067de..5eaee1721c 100644 --- a/internal/validate/lang.go +++ b/internal/tf/validation/lang.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "strings" diff --git a/internal/validate/lang_test.go b/internal/tf/validation/lang_test.go similarity index 98% rename from internal/validate/lang_test.go rename to internal/tf/validation/lang_test.go index 1a5c4a7a47..85ac4a319d 100644 --- a/internal/validate/lang_test.go +++ b/internal/tf/validation/lang_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "testing" diff --git a/internal/validate/mail.go b/internal/tf/validation/mail_nickname.go similarity index 97% rename from internal/validate/mail.go rename to internal/tf/validation/mail_nickname.go index f8ec78fe8b..5267371f27 100644 --- a/internal/validate/mail.go +++ b/internal/tf/validation/mail_nickname.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "regexp" diff --git a/internal/validate/mail_test.go b/internal/tf/validation/mail_nickname_test.go similarity index 98% rename from internal/validate/mail_test.go rename to internal/tf/validation/mail_nickname_test.go index 1f9524e866..37fedc31a0 100644 --- a/internal/validate/mail_test.go +++ b/internal/tf/validation/mail_nickname_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "testing" diff --git a/internal/tf/validation/pluginsdk.go b/internal/tf/validation/pluginsdk.go new file mode 100644 index 0000000000..7c5ba72e77 --- /dev/null +++ b/internal/tf/validation/pluginsdk.go @@ -0,0 +1,294 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validation + +import ( + "fmt" + "net/url" + "regexp" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +// This file is intended to provide a transition from Plugin SDKv1 to Plugin SDKv2 +// without introducing a merge conflict into every PR. + +// All returns a SchemaValidateFunc which tests if the provided value +// passes all provided SchemaValidateFunc +// lint:ignore SA1019 SDKv2 migration - staticcheck's own linter directives are currently being ignored under golanci-lint +func All(validators ...schema.SchemaValidateFunc) schema.SchemaValidateFunc { //nolint:staticcheck + return validation.All(validators...) +} + +// Any returns a SchemaValidateFunc which tests if the provided value +// passes any of the provided SchemaValidateFunc +// +//lint:ignore SA1019 SDKv2 migration - staticcheck's own linter directives are currently being ignored under golanci-lint +func Any(validators ...schema.SchemaValidateFunc) schema.SchemaValidateFunc { //nolint:staticcheck + return validation.Any(validators...) +} + +// FloatAtLeast returns a SchemaValidateFunc which tests if the provided value +// is of type float and is at least min (inclusive) +func FloatAtLeast(min float64) func(interface{}, string) ([]string, []error) { + return validation.FloatAtLeast(min) +} + +// FloatBetween returns a SchemaValidateFunc which tests if the provided value +// is of type float64 and is between min and max (inclusive). +func FloatBetween(min, max float64) func(interface{}, string) ([]string, []error) { + return validation.FloatBetween(min, max) +} + +// FloatInSlice returns a SchemaValidateFunc which tests if the provided value +// is of type float64 and matches the value of an element in the valid slice +func FloatInSlice(valid []float64) func(interface{}, string) ([]string, []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(float64) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be float", i)) + return warnings, errors + } + + for _, validFloat := range valid { + if v == validFloat { + return warnings, errors + } + } + + errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %f", k, valid, v)) + return warnings, errors + } +} + +// IntNotInSlice returns a SchemaValidateFunc which tests if the provided value +// is of type int and matches the value of an element in the valid slice +func IntNotInSlice(valid []int) func(interface{}, string) ([]string, []error) { + return validation.IntNotInSlice(valid) +} + +// IntAtLeast returns a SchemaValidateFunc which tests if the provided value +// is of type int and is at least min (inclusive) +func IntAtLeast(min int) func(interface{}, string) ([]string, []error) { + return validation.IntAtLeast(min) +} + +// IntAtMost returns a SchemaValidateFunc which tests if the provided value +// is of type int and is at most max (inclusive) +func IntAtMost(max int) func(interface{}, string) ([]string, []error) { + return validation.IntAtMost(max) +} + +// IntBetween returns a SchemaValidateFunc which tests if the provided value +// is of type int and is between min and max (inclusive) +func IntBetween(min, max int) func(interface{}, string) ([]string, []error) { + return validation.IntBetween(min, max) +} + +// IntDivisibleBy returns a SchemaValidateFunc which tests if the provided value +// is of type int and is divisible by a given number +func IntDivisibleBy(divisor int) func(interface{}, string) ([]string, []error) { + return validation.IntDivisibleBy(divisor) +} + +// IntInSlice returns a SchemaValidateFunc which tests if the provided value +// is of type int and matches the value of an element in the valid slice +func IntInSlice(valid []int) func(interface{}, string) ([]string, []error) { + return validation.IntInSlice(valid) +} + +func IntPositive(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(int) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be int", i)) + return + } + if v <= 0 { + errors = append(errors, fmt.Errorf("expected %s to be positive, got %d", k, v)) + return + } + return +} + +// IsCIDR is a SchemaValidateFunc which tests if the provided value is of type string and a valid CIDR +func IsCIDR(i interface{}, k string) ([]string, []error) { + return validation.IsCIDR(i, k) +} + +// IsDayOfTheWeek id a SchemaValidateFunc which tests if the provided value is of type string and a valid english day of the week +func IsDayOfTheWeek(ignoreCase bool) func(interface{}, string) ([]string, []error) { + return validation.IsDayOfTheWeek(ignoreCase) +} + +// IsIPAddress is a SchemaValidateFunc which tests if the provided value is of type string and is a single IP (v4 or v6) +func IsIPAddress(i interface{}, k string) ([]string, []error) { + return validation.IsIPAddress(i, k) +} + +// IsIPv4Address is a SchemaValidateFunc which tests if the provided value is of type string and a valid IPv4 address +func IsIPv4Address(i interface{}, k string) ([]string, []error) { + return validation.IsIPv4Address(i, k) +} + +// IsIPv4Range is a SchemaValidateFunc which tests if the provided value is of type string, and in valid IP range +func IsIPv4Range(i interface{}, k string) ([]string, []error) { + return validation.IsIPv4Range(i, k) +} + +// IsIPv6Address is a SchemaValidateFunc which tests if the provided value is of type string and a valid IPv6 address +func IsIPv6Address(i interface{}, k string) ([]string, []error) { + return validation.IsIPv6Address(i, k) +} + +// IsMonth id a SchemaValidateFunc which tests if the provided value is of type string and a valid english month +func IsMonth(ignoreCase bool) func(interface{}, string) ([]string, []error) { + return validation.IsMonth(ignoreCase) +} + +// IsPortNumber is a SchemaValidateFunc which tests if the provided value is of type string and a valid TCP Port Number +func IsPortNumber(i interface{}, k string) ([]string, []error) { + return validation.IsPortNumber(i, k) +} + +// IsRFC3339Time is a SchemaValidateFunc which tests if the provided value is of type string and a valid RFC33349Time +func IsRFC3339Time(i interface{}, k string) ([]string, []error) { + return validation.IsRFC3339Time(i, k) +} + +// IsURLWithHTTPorHTTPS is a SchemaValidateFunc which tests if the provided value is of type string and a valid HTTP or HTTPS URL +func IsURLWithHTTPorHTTPS(i interface{}, k string) ([]string, []error) { + return validation.IsURLWithHTTPorHTTPS(i, k) +} + +// IsURLWithHTTPS is a SchemaValidateFunc which tests if the provided value is of type string and a valid HTTPS URL +func IsURLWithHTTPS(i interface{}, k string) ([]string, []error) { + return validation.IsURLWithHTTPS(i, k) +} + +// IsURLWithScheme is a SchemaValidateFunc which tests if the provided value is of type string and a valid URL with the provided schemas +func IsURLWithScheme(validSchemes []string) func(interface{}, string) ([]string, []error) { + return validation.IsURLWithScheme(validSchemes) +} + +// IsURLWithPath is a SchemaValidateFunc that tests if the provided value is of type string and a valid URL with a path +func IsURLWithPath(i interface{}, k string) (_ []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if v == "" { + errors = append(errors, fmt.Errorf("expected %q url to not be empty, got %v", k, i)) + return + } + + u, err := url.Parse(v) + if err != nil { + errors = append(errors, fmt.Errorf("expected %q to be a valid url, got %v: %+v", k, v, err)) + return + } + + if strings.TrimPrefix(u.Path, "/") == "" { + errors = append(errors, fmt.Errorf("expected %q to have a non empty path got %v", k, v)) + return + } + + return +} + +// IsUUID is a ValidateFunc that ensures a string can be parsed as UUID +func IsUUID(i interface{}, k string) ([]string, []error) { + return validation.IsUUID(i, k) +} + +// None returns a SchemaValidateFunc which tests if the provided value +// returns errors for all of the provided SchemaValidateFunc +func None(validators map[string]func(interface{}, string) ([]string, []error)) func(interface{}, string) ([]string, []error) { + return func(i interface{}, k string) ([]string, []error) { + var allErrors []error + var allWarnings []string + for name, validator := range validators { + validatorWarnings, validatorErrors := validator(i, k) + if len(validatorWarnings) == 0 && len(validatorErrors) == 0 { + allErrors = append(allErrors, fmt.Errorf("ID cannot be a %s", name)) + } + } + return allWarnings, allErrors + } +} + +// NoZeroValues is a SchemaValidateFunc which tests if the provided value is +// not a zero value. It's useful in situations where you want to catch +// explicit zero values on things like required fields during validation. +func NoZeroValues(i interface{}, k string) ([]string, []error) { + return validation.NoZeroValues(i, k) +} + +// StringDoesNotContainAny returns a SchemaValidateFunc which validates that the +// provided value does not contain any of the specified Unicode code points in chars. +func StringDoesNotContainAny(chars string) func(interface{}, string) ([]string, []error) { + return validation.StringDoesNotContainAny(chars) +} + +// StringInSlice returns a SchemaValidateFunc which tests if the provided value +// is of type string and matches the value of an element in the valid slice +// will test with in lower case if ignoreCase is true +func StringInSlice(valid []string, ignoreCase bool) func(interface{}, string) ([]string, []error) { + return func(i interface{}, k string) ([]string, []error) { + return validation.StringInSlice(valid, ignoreCase)(i, k) + } +} + +// StringIsBase64 is a ValidateFunc that ensures a string can be parsed as Base64 +func StringIsBase64(i interface{}, k string) ([]string, []error) { + return validation.StringIsBase64(i, k) +} + +// StringIsJSON is a SchemaValidateFunc which tests to make sure the supplied string is valid JSON. +func StringIsJSON(i interface{}, k string) ([]string, []error) { + return validation.StringIsJSON(i, k) +} + +// StringIsEmpty is a ValidateFunc that ensures a string has no characters +func StringIsEmpty(i interface{}, k string) ([]string, []error) { + return validation.StringIsEmpty(i, k) +} + +// StringIsNotEmpty is a ValidateFunc that ensures a string is not empty +func StringIsNotEmpty(i interface{}, k string) ([]string, []error) { + return validation.StringIsNotEmpty(i, k) +} + +// StringIsNotWhiteSpace is a ValidateFunc that ensures a string is not empty or consisting entirely of whitespace characters +func StringIsNotWhiteSpace(i interface{}, k string) ([]string, []error) { + return validation.StringIsNotWhiteSpace(i, k) +} + +// StringIsValidRegExp returns a SchemaValidateFunc which tests to make sure the supplied string is a valid regular expression. +func StringIsValidRegExp(i interface{}, k string) ([]string, []error) { + return validation.StringIsValidRegExp(i, k) +} + +// StringLenBetween returns a SchemaValidateFunc which tests if the provided value +// is of type string and has length between min and max (inclusive) +func StringLenBetween(min, max int) func(interface{}, string) ([]string, []error) { + return validation.StringLenBetween(min, max) +} + +// StringMatch returns a SchemaValidateFunc which tests if the provided value +// matches a given regexp. Optionally an error message can be provided to +// return something friendlier than "must match some globby regexp". +func StringMatch(r *regexp.Regexp, message string) func(interface{}, string) ([]string, []error) { + return validation.StringMatch(r, message) +} + +// StringNotInSlice returns a SchemaValidateFunc which tests if the provided value +// is of type string and does not match the value of any element in the invalid slice +// will test with in lower case if ignoreCase is true +func StringNotInSlice(invalid []string, ignoreCase bool) func(interface{}, string) ([]string, []error) { + return validation.StringNotInSlice(invalid, ignoreCase) +} diff --git a/internal/tf/validation/pluginsdk_test.go b/internal/tf/validation/pluginsdk_test.go new file mode 100644 index 0000000000..c52d8d50ee --- /dev/null +++ b/internal/tf/validation/pluginsdk_test.go @@ -0,0 +1,53 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validation + +import ( + "testing" + + "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk" +) + +func TestValidateFloatInSlice(t *testing.T) { + cases := map[string]struct { + Value interface{} + ValidateFunc pluginsdk.SchemaValidateFunc + ExpectValidationErrors bool + }{ + "accept valid value": { + Value: 1.5, + ValidateFunc: FloatInSlice([]float64{1.0, 1.5, 2.0}), + ExpectValidationErrors: false, + }, + "accept valid negative value ": { + Value: -1.0, + ValidateFunc: FloatInSlice([]float64{-1.0, 2.0}), + ExpectValidationErrors: false, + }, + "accept zero": { + Value: 0.0, + ValidateFunc: FloatInSlice([]float64{0.0, 2.0}), + ExpectValidationErrors: false, + }, + "reject out of range value": { + Value: -1.0, + ValidateFunc: FloatInSlice([]float64{0.0, 2.0}), + ExpectValidationErrors: true, + }, + "reject incorrectly typed value": { + Value: 1, + ValidateFunc: FloatInSlice([]float64{0, 1, 2}), + ExpectValidationErrors: true, + }, + } + + for tn, tc := range cases { + _, errors := tc.ValidateFunc(tc.Value, tn) + if len(errors) > 0 && !tc.ExpectValidationErrors { + t.Errorf("%s: unexpected errors %s", tn, errors) + } else if len(errors) == 0 && tc.ExpectValidationErrors { + t.Errorf("%s: expected errors but got none", tn) + } + } +} diff --git a/internal/validate/strings.go b/internal/tf/validation/strings.go similarity index 66% rename from internal/validate/strings.go rename to internal/tf/validation/strings.go index b049ba869e..1702a6a9da 100644 --- a/internal/validate/strings.go +++ b/internal/tf/validation/strings.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "regexp" @@ -11,29 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) -// NoEmptyStrings validates that the string is not just whitespace characters (equal to [\r\n\t\f\v ]) -func NoEmptyStrings(i interface{}, path cty.Path) (ret diag.Diagnostics) { - v, ok := i.(string) - if !ok { - ret = append(ret, diag.Diagnostic{ - Severity: diag.Error, - Summary: "Expected a string value", - AttributePath: path, - }) - return - } - - if strings.TrimSpace(v) == "" { - ret = append(ret, diag.Diagnostic{ - Severity: diag.Error, - Summary: "Value must not be empty", - AttributePath: path, - }) - } - - return -} - // StringIsEmailAddress validates that the given string is a valid email address (foo@bar.com) func StringIsEmailAddress(i interface{}, path cty.Path) (ret diag.Diagnostics) { v, ok := i.(string) diff --git a/internal/tf/validation/strings_test.go b/internal/tf/validation/strings_test.go new file mode 100644 index 0000000000..a6eeb5db2a --- /dev/null +++ b/internal/tf/validation/strings_test.go @@ -0,0 +1,44 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validation + +import ( + "testing" + + "github.com/hashicorp/go-cty/cty" +) + +func TestStringIsEmailAddress(t *testing.T) { + cases := []struct { + Value string + TestName string + ErrCount int + }{ + { + Value: "j.doe@hashicorp.com", + TestName: "Valid_EmailAddress", + ErrCount: 0, + }, + { + Value: "j.doehashicorp.com", + TestName: "Invalid_EmailAddress_NoAtChar", + ErrCount: 1, + }, + { + Value: "j/doe@ha$hicorp.com", + TestName: "Invalid_EmailAddress_InvalidChars", + ErrCount: 1, + }, + } + + for _, tc := range cases { + t.Run(tc.TestName, func(t *testing.T) { + diags := StringIsEmailAddress(tc.Value, cty.Path{}) + + if len(diags) != tc.ErrCount { + t.Fatalf("Expected StringIsEmailAddress to have %d not %d errors for %q", tc.ErrCount, len(diags), tc.TestName) + } + }) + } +} diff --git a/internal/validate/uri.go b/internal/tf/validation/uri.go similarity index 99% rename from internal/validate/uri.go rename to internal/tf/validation/uri.go index 2cec90c8da..be59b9ad38 100644 --- a/internal/validate/uri.go +++ b/internal/tf/validation/uri.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "fmt" diff --git a/internal/validate/uri_test.go b/internal/tf/validation/uri_test.go similarity index 99% rename from internal/validate/uri_test.go rename to internal/tf/validation/uri_test.go index 9003c1f92a..8d1b1c5e9e 100644 --- a/internal/validate/uri_test.go +++ b/internal/tf/validation/uri_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package validate +package validation import ( "testing" diff --git a/internal/validate/strings_test.go b/internal/validate/strings_test.go deleted file mode 100644 index 21d825ac40..0000000000 --- a/internal/validate/strings_test.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package validate - -import ( - "testing" - - "github.com/hashicorp/go-cty/cty" -) - -func TestNoEmptyStrings(t *testing.T) { - cases := []struct { - Value string - TestName string - ErrCount int - }{ - { - Value: "!", - TestName: "Exclamation", - ErrCount: 0, - }, - { - Value: ".", - TestName: "Period", - ErrCount: 0, - }, - { - Value: "-", - TestName: "Hyphen", - ErrCount: 0, - }, - { - Value: "_", - TestName: "Underscore", - ErrCount: 0, - }, - { - Value: "10.1.0.0/16", - TestName: "IP", - ErrCount: 0, - }, - { - Value: "", - TestName: "Empty", - ErrCount: 1, - }, - { - Value: " ", - TestName: "Space", - ErrCount: 1, - }, - { - Value: " ", - TestName: "FiveSpaces", - ErrCount: 1, - }, - { - Value: " 1", - TestName: "DoubleSpaceOne", - ErrCount: 0, - }, - { - Value: "1 ", - TestName: "OneSpace", - ErrCount: 0, - }, - { - Value: "\r", - TestName: "CarriageReturn", - ErrCount: 1, - }, - { - Value: "\n", - TestName: "NewLine", - ErrCount: 1, - }, - { - Value: "\t", - TestName: "HorizontalTab", - ErrCount: 1, - }, - { - Value: "\f", - TestName: "FormFeed", - ErrCount: 1, - }, - { - Value: "\v", - TestName: "VerticalTab", - ErrCount: 1, - }, - } - - for _, tc := range cases { - t.Run(tc.TestName, func(t *testing.T) { - diags := NoEmptyStrings(tc.Value, cty.Path{}) - - if len(diags) != tc.ErrCount { - t.Fatalf("Expected NoEmptyStrings to have %d not %d errors for %q", tc.ErrCount, len(diags), tc.TestName) - } - }) - } -} - -func TestStringIsEmailAddress(t *testing.T) { - cases := []struct { - Value string - TestName string - ErrCount int - }{ - { - Value: "j.doe@hashicorp.com", - TestName: "Valid_EmailAddress", - ErrCount: 0, - }, - { - Value: "j.doehashicorp.com", - TestName: "Invalid_EmailAddress_NoAtChar", - ErrCount: 1, - }, - { - Value: "j/doe@ha$hicorp.com", - TestName: "Invalid_EmailAddress_InvalidChars", - ErrCount: 1, - }, - } - - for _, tc := range cases { - t.Run(tc.TestName, func(t *testing.T) { - diags := StringIsEmailAddress(tc.Value, cty.Path{}) - - if len(diags) != tc.ErrCount { - t.Fatalf("Expected StringIsEmailAddress to have %d not %d errors for %q", tc.ErrCount, len(diags), tc.TestName) - } - }) - } -} diff --git a/internal/validate/uuid.go b/internal/validate/uuid.go deleted file mode 100644 index 739ebbc604..0000000000 --- a/internal/validate/uuid.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package validate - -import ( - "github.com/hashicorp/go-cty/cty" - "github.com/hashicorp/go-uuid" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" -) - -func UUID(i interface{}, path cty.Path) (ret diag.Diagnostics) { - v, ok := i.(string) - if !ok { - ret = append(ret, diag.Diagnostic{ - Severity: diag.Error, - Summary: "Expected a string value", - AttributePath: path, - }) - return - } - - if _, err := uuid.ParseUUID(v); err != nil { - ret = append(ret, diag.Diagnostic{ - Severity: diag.Error, - Summary: "Value must be a valid UUID", - AttributePath: path, - }) - } - - return -} diff --git a/internal/validate/uuid_test.go b/internal/validate/uuid_test.go deleted file mode 100644 index e075fd9f92..0000000000 --- a/internal/validate/uuid_test.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package validate - -import ( - "testing" - - "github.com/hashicorp/go-cty/cty" -) - -func TestUUID(t *testing.T) { - cases := []struct { - Input string - Errors int - }{ - { - Input: "", - Errors: 1, - }, - { - Input: "hello-world", - Errors: 1, - }, - { - Input: "00000000-0000-111-0000-000000000000", - Errors: 1, - }, - { - Input: "00000000-0000-0000-0000-000000000000", - Errors: 0, - }, - } - - for _, tc := range cases { - t.Run(tc.Input, func(t *testing.T) { - diags := UUID(tc.Input, cty.Path{}) - - if len(diags) != tc.Errors { - t.Fatalf("Expected UUID to have %d not %d errors for %q", tc.Errors, len(diags), tc.Input) - } - }) - } -}