Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/datalakestore/filesystems"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/datalakestore/paths"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/queue/queues"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/entities"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/tables"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/directories"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/entities"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/tables"
)

type Client struct {
Expand Down Expand Up @@ -256,7 +256,11 @@ func (client Client) QueuesClient(ctx context.Context, account accountDetails) (
}

func (client Client) TableEntityClient(ctx context.Context, account accountDetails) (*entities.Client, error) {
// NOTE: Table Entity does not support AzureAD Authentication
if client.storageAdAuth != nil {
entitiesClient := entities.NewWithEnvironment(client.Environment)
entitiesClient.Client.Authorizer = *client.storageAdAuth
return &entitiesClient, nil
}

accountKey, err := account.AccountKey(ctx, client)
if err != nil {
Expand All @@ -274,7 +278,12 @@ func (client Client) TableEntityClient(ctx context.Context, account accountDetai
}

func (client Client) TablesClient(ctx context.Context, account accountDetails) (shim.StorageTableWrapper, error) {
// NOTE: Tables do not support AzureAD Authentication
if client.storageAdAuth != nil {
tablesClient := tables.NewWithEnvironment(client.Environment)
tablesClient.Client.Authorizer = *client.storageAdAuth
shim := shim.NewDataPlaneStorageTableWrapper(&tablesClient)
return shim, nil
}

accountKey, err := account.AccountKey(ctx, client)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/hashicorp/terraform-provider-azurerm/internal/resourceid"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/tables"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/tables"
)

// TODO: tests for this
Expand Down
2 changes: 1 addition & 1 deletion internal/services/storage/shim/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package shim
import (
"context"

"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/tables"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/tables"
)

type StorageTableWrapper interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/storage/shim/tables_data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/tables"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/tables"
)

type DataPlaneStorageTableWrapper struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/entities"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/entities"
)

func dataSourceStorageTableEntity() *pluginsdk.Resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/entities"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/entities"
)

func resourceStorageTableEntity() *pluginsdk.Resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/entities"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/entities"
)

type StorageTableEntityResource struct{}
Expand All @@ -30,6 +30,21 @@ func TestAccTableEntity_basic(t *testing.T) {
})
}

func TestAccTableEntity_basicAzureADAuth(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test")
r := StorageTableEntityResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicAzureADAuth(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccTableEntity_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test")
r := StorageTableEntityResource{}
Expand Down Expand Up @@ -118,6 +133,44 @@ resource "azurerm_storage_table_entity" "test" {
`, template, data.RandomInteger, data.RandomInteger)
}

func (r StorageTableEntityResource) basicAzureADAuth(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
storage_use_azuread = true
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_storage_account" "test" {
name = "acctestsa%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_table" "test" {
name = "acctestst%d"
storage_account_name = azurerm_storage_account.test.name
}

resource "azurerm_storage_table_entity" "test" {
storage_account_name = azurerm_storage_account.test.name
table_name = azurerm_storage_table.test.name

partition_key = "test_partition%d"
row_key = "test_row%d"
entity = {
Foo = "Bar"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r StorageTableEntityResource) requiresImport(data acceptance.TestData) string {
template := r.basic(data)
return fmt.Sprintf(`
Expand Down
2 changes: 1 addition & 1 deletion internal/services/storage/storage_table_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/tables"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/tables"
)

func resourceStorageTable() *pluginsdk.Resource {
Expand Down
46 changes: 46 additions & 0 deletions internal/services/storage/storage_table_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ func TestAccStorageTable_basic(t *testing.T) {
})
}

func TestAccStorageTable_basicAzureADAuth(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_table", "test")
r := StorageTableResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicAzureADAuth(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccStorageTable_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_table", "test")
r := StorageTableResource{}
Expand Down Expand Up @@ -159,6 +174,37 @@ resource "azurerm_storage_table" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger)
}

func (r StorageTableResource) basicAzureADAuth(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
storage_use_azuread = true
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_storage_account" "test" {
name = "acctestacc%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"

tags = {
environment = "staging"
}
}

resource "azurerm_storage_table" "test" {
name = "acctestst%d"
storage_account_name = azurerm_storage_account.test.name
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger)
}

func (r StorageTableResource) requiresImport(data acceptance.TestData) string {
template := r.basic(data)
return fmt.Sprintf(`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ github.com/tombuildsstuff/giovanni/storage/2019-12-12/blob/containers
github.com/tombuildsstuff/giovanni/storage/2019-12-12/datalakestore/filesystems
github.com/tombuildsstuff/giovanni/storage/2019-12-12/datalakestore/paths
github.com/tombuildsstuff/giovanni/storage/2019-12-12/queue/queues
github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/entities
github.com/tombuildsstuff/giovanni/storage/2019-12-12/table/tables
github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/directories
github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files
github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares
github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/entities
github.com/tombuildsstuff/giovanni/storage/2020-08-04/table/tables
github.com/tombuildsstuff/giovanni/storage/accesscontrol
github.com/tombuildsstuff/giovanni/storage/internal/endpoints
github.com/tombuildsstuff/giovanni/storage/internal/metadata
Expand Down