Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_batch_pool - support container_image_names property #6689

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package azure
package batch

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch"
)

// ExpandBatchAccountKeyVaultReference expands Batch account KeyVault reference
func ExpandBatchAccountKeyVaultReference(list []interface{}) (*batch.KeyVaultReference, error) {
// expandBatchAccountKeyVaultReference expands Batch account KeyVault reference
func expandBatchAccountKeyVaultReference(list []interface{}) (*batch.KeyVaultReference, error) {
if len(list) == 0 {
return nil, fmt.Errorf("Error: key vault reference should be defined")
}
Expand All @@ -25,8 +25,8 @@ func ExpandBatchAccountKeyVaultReference(list []interface{}) (*batch.KeyVaultRef
return ref, nil
}

// FlattenBatchAccountKeyvaultReference flattens a Batch account keyvault reference
func FlattenBatchAccountKeyvaultReference(keyVaultReference *batch.KeyVaultReference) interface{} {
// flattenBatchAccountKeyvaultReference flattens a Batch account keyvault reference
func flattenBatchAccountKeyvaultReference(keyVaultReference *batch.KeyVaultReference) interface{} {
result := make(map[string]interface{})

if keyVaultReference == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func dataSourceArmBatchAccountRead(d *schema.ResourceData, meta interface{}) err
// set empty keyvault reference which is not needed in Batch Service allocation mode.
d.Set("key_vault_reference", []interface{}{})
} else if poolAllocationMode == string(batch.UserSubscription) {
if err := d.Set("key_vault_reference", azure.FlattenBatchAccountKeyvaultReference(props.KeyVaultReference)); err != nil {
if err := d.Set("key_vault_reference", flattenBatchAccountKeyvaultReference(props.KeyVaultReference)); err != nil {
return fmt.Errorf("Error flattening `key_vault_reference`: %+v", err)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package batch_test

import (
"fmt"
Expand All @@ -10,15 +10,15 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
)

func TestAccDataSourceAzureRMBatchAccount_basic(t *testing.T) {
func TestAccBatchAccountDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMBatchAccount_basic(data),
Config: testAccBatchAccountDataSource_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)),
Expand All @@ -29,15 +29,15 @@ func TestAccDataSourceAzureRMBatchAccount_basic(t *testing.T) {
})
}

func TestAccDataSourceAzureRMBatchAccount_complete(t *testing.T) {
func TestAccBatchAccountDataSource_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMBatchAccount_complete(data),
Config: testAccBatchAccountDataSource_complete(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)),
Expand All @@ -50,7 +50,7 @@ func TestAccDataSourceAzureRMBatchAccount_complete(t *testing.T) {
})
}

func TestAccDataSourceAzureRMBatchAccount_userSubscription(t *testing.T) {
func TestAccBatchAccountDataSource_userSubscription(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test")

tenantID := os.Getenv("ARM_TENANT_ID")
Expand All @@ -61,7 +61,7 @@ func TestAccDataSourceAzureRMBatchAccount_userSubscription(t *testing.T) {
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureBatchAccount_userSubscription(data, tenantID, subscriptionID),
Config: testAccBatchAccountDataSource_userSubscription(data, tenantID, subscriptionID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)),
resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)),
Expand All @@ -73,7 +73,7 @@ func TestAccDataSourceAzureRMBatchAccount_userSubscription(t *testing.T) {
})
}

func testAccDataSourceAzureRMBatchAccount_basic(data acceptance.TestData) string {
func testAccBatchAccountDataSource_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -98,7 +98,7 @@ data "azurerm_batch_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccDataSourceAzureRMBatchAccount_complete(data acceptance.TestData) string {
func testAccBatchAccountDataSource_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -136,7 +136,7 @@ data "azurerm_batch_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString)
}

func testAccDataSourceAzureBatchAccount_userSubscription(data acceptance.TestData, tenantID string, subscriptionID string) string {
func testAccBatchAccountDataSource_userSubscription(data acceptance.TestData, tenantID string, subscriptionID string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/batch/batch_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func resourceArmBatchAccountCreate(d *schema.ResourceData, meta interface{}) err
// if pool allocation mode is UserSubscription, a key vault reference needs to be set
if poolAllocationMode == string(batch.UserSubscription) {
keyVaultReferenceSet := d.Get("key_vault_reference").([]interface{})
keyVaultReference, err := azure.ExpandBatchAccountKeyVaultReference(keyVaultReferenceSet)
keyVaultReference, err := expandBatchAccountKeyVaultReference(keyVaultReferenceSet)
if err != nil {
return fmt.Errorf("Error creating Batch account %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package batch_test

import (
"fmt"
Expand Down Expand Up @@ -42,68 +42,68 @@ func TestValidateBatchAccountName(t *testing.T) {
}
}

func TestAccAzureRMBatchAccount_basic(t *testing.T) {
func TestAccBatchAccount_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBatchAccountDestroy,
CheckDestroy: testCheckBatchAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMBatchAccount_basic(data),
Config: testAccBatchAccount_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchAccountExists(data.ResourceName),
testCheckBatchAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"),
),
},
},
})
}

func TestAccAzureRMBatchAccount_requiresImport(t *testing.T) {
func TestAccBatchAccount_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBatchAccountDestroy,
CheckDestroy: testCheckBatchAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMBatchAccount_basic(data),
Config: testAccBatchAccount_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchAccountExists(data.ResourceName),
testCheckBatchAccountExists(data.ResourceName),
),
},
{
Config: testAccAzureRMBatchAccount_requiresImport(data),
Config: testAccBatchAccount_requiresImport(data),
ExpectError: acceptance.RequiresImportError("azurerm_batch_account"),
},
},
})
}

func TestAccAzureRMBatchAccount_complete(t *testing.T) {
func TestAccBatchAccount_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBatchAccountDestroy,
CheckDestroy: testCheckBatchAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMBatchAccount_complete(data),
Config: testAccBatchAccount_complete(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchAccountExists(data.ResourceName),
testCheckBatchAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"),
),
},
{
Config: testAccAzureRMBatchAccount_completeUpdated(data),
Config: testAccBatchAccount_completeUpdated(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchAccountExists(data.ResourceName),
testCheckBatchAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"),
Expand All @@ -114,27 +114,27 @@ func TestAccAzureRMBatchAccount_complete(t *testing.T) {
})
}

func TestAccAzureRMBatchAccount_userSubscription(t *testing.T) {
func TestAccBatchAccount_userSubscription(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_account", "test")
tenantID := os.Getenv("ARM_TENANT_ID")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBatchAccountDestroy,
CheckDestroy: testCheckBatchAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMBatchAccount_userSubscription(data, tenantID),
Config: testAccBatchAccount_userSubscription(data, tenantID),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchAccountExists(data.ResourceName),
testCheckBatchAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "UserSubscription"),
),
},
},
})
}

func testCheckAzureRMBatchAccountExists(resourceName string) resource.TestCheckFunc {
func testCheckBatchAccountExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
conn := acceptance.AzureProvider.Meta().(*clients.Client).Batch.AccountClient
Expand Down Expand Up @@ -165,7 +165,7 @@ func testCheckAzureRMBatchAccountExists(resourceName string) resource.TestCheckF
}
}

func testCheckAzureRMBatchAccountDestroy(s *terraform.State) error {
func testCheckBatchAccountDestroy(s *terraform.State) error {
conn := acceptance.AzureProvider.Meta().(*clients.Client).Batch.AccountClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext

Expand All @@ -192,7 +192,7 @@ func testCheckAzureRMBatchAccountDestroy(s *terraform.State) error {
return nil
}

func testAccAzureRMBatchAccount_basic(data acceptance.TestData) string {
func testAccBatchAccount_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -212,8 +212,8 @@ resource "azurerm_batch_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMBatchAccount_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMBatchAccount_basic(data)
func testAccBatchAccount_requiresImport(data acceptance.TestData) string {
template := testAccBatchAccount_basic(data)
return fmt.Sprintf(`
%s
resource "azurerm_batch_account" "import" {
Expand All @@ -225,7 +225,7 @@ resource "azurerm_batch_account" "import" {
`, template)
}

func testAccAzureRMBatchAccount_complete(data acceptance.TestData) string {
func testAccBatchAccount_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -258,7 +258,7 @@ resource "azurerm_batch_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString)
}

func testAccAzureRMBatchAccount_completeUpdated(data acceptance.TestData) string {
func testAccBatchAccount_completeUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -292,7 +292,7 @@ resource "azurerm_batch_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString)
}

func testAccAzureRMBatchAccount_userSubscription(data acceptance.TestData, tenantID string) string {
func testAccBatchAccount_userSubscription(data acceptance.TestData, tenantID string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package batch_test

import (
"fmt"
Expand All @@ -12,52 +12,52 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func TestAccAzureRMBatchApplication_basic(t *testing.T) {
func TestAccBatchApplication_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_application", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBatchApplicationDestroy,
CheckDestroy: testCheckBatchApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMBatchApplication_template(data, ""),
Config: testAccBatchApplication_template(data, ""),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchApplicationExists(data.ResourceName),
testCheckBatchApplicationExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMBatchApplication_update(t *testing.T) {
func TestAccBatchApplication_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_application", "test")
displayName := fmt.Sprintf("TestAccDisplayName-%d", data.RandomInteger)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBatchApplicationDestroy,
CheckDestroy: testCheckBatchApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMBatchApplication_template(data, ""),
Config: testAccBatchApplication_template(data, ""),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchApplicationExists(data.ResourceName),
testCheckBatchApplicationExists(data.ResourceName),
),
},
{
Config: testAccAzureRMBatchApplication_template(data, fmt.Sprintf(`display_name = "%s"`, displayName)),
Config: testAccBatchApplication_template(data, fmt.Sprintf(`display_name = "%s"`, displayName)),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMBatchApplicationExists(data.ResourceName),
testCheckBatchApplicationExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "display_name", displayName),
),
},
},
})
}

func testCheckAzureRMBatchApplicationExists(resourceName string) resource.TestCheckFunc {
func testCheckBatchApplicationExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Batch.ApplicationClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand All @@ -83,7 +83,7 @@ func testCheckAzureRMBatchApplicationExists(resourceName string) resource.TestCh
}
}

func testCheckAzureRMBatchApplicationDestroy(s *terraform.State) error {
func testCheckBatchApplicationDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Batch.ApplicationClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext

Expand All @@ -109,7 +109,7 @@ func testCheckAzureRMBatchApplicationDestroy(s *terraform.State) error {
return nil
}

func testAccAzureRMBatchApplication_template(data acceptance.TestData, displayName string) string {
func testAccBatchApplication_template(data acceptance.TestData, displayName string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down
Loading