Skip to content

Commit

Permalink
Use pluginsdk shims, convert data.azuread_client_config to typed data…
Browse files Browse the repository at this point in the history
…source
  • Loading branch information
manicminer committed Sep 13, 2023
1 parent 2f4a871 commit a02dcaf
Show file tree
Hide file tree
Showing 134 changed files with 2,631 additions and 2,672 deletions.
6 changes: 3 additions & 3 deletions internal/helpers/consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions internal/helpers/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/hashicorp/terraform-provider-azuread/internal/sdk"
"log"
"os"

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,66 @@ 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/validate"
"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,
},

"display_name": {
Description: "The display name for the administrative unit",
Type: schema.TypeString,
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateDiagFunc: validate.NoEmptyStrings,
},

"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)),
),
},
Expand All @@ -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)),
),
},
Expand All @@ -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"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,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-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/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 {
_, 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,
},

"member_object_id": {
Description: "The object ID of the member",
Type: schema.TypeString,
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateDiagFunc: validate.UUID,
Expand All @@ -62,7 +61,7 @@ func administrativeUnitMemberResource() *schema.Resource {
}
}

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
Expand Down Expand Up @@ -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,
Expand All @@ -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())
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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),
),
},
Expand Down
Loading

0 comments on commit a02dcaf

Please sign in to comment.