Skip to content

Commit

Permalink
fix failing update test for ai services and update requires import er…
Browse files Browse the repository at this point in the history
…ror check with correct resource name
  • Loading branch information
stephybun committed Nov 28, 2024
1 parent 399b9e4 commit afa745d
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 28 deletions.
131 changes: 124 additions & 7 deletions internal/services/cognitive/ai_services_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,15 @@ func TestAccCognitiveAIServices_update(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("tags.%").HasValue("0"),
check.That(data.ResourceName).Key("primary_access_key").Exists(),
check.That(data.ResourceName).Key("secondary_access_key").Exists(),
),
},
{
Config: r.complete(data),
Config: r.update(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("tags.Acceptance").HasValue("Test"),
),
},
})
Expand Down Expand Up @@ -466,6 +461,128 @@ resource "azurerm_ai_services" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomIntOfLength(8))
}

func (AIServices) update(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "test" {
name = "acctestRG-cognitive-%[1]d"
location = "%[2]s"
}
resource "azurerm_user_assigned_identity" "test" {
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
name = "%[3]s"
}
resource "azurerm_key_vault" "test" {
name = "acctestkv%[3]s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
soft_delete_retention_days = 7
purge_protection_enabled = true
access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
key_permissions = [
"Get", "Create", "Delete", "List", "Restore", "Recover", "UnwrapKey", "WrapKey", "Purge", "Encrypt", "Decrypt", "Sign", "Verify", "GetRotationPolicy"
]
secret_permissions = [
"Get",
]
}
access_policy {
tenant_id = azurerm_user_assigned_identity.test.tenant_id
object_id = azurerm_user_assigned_identity.test.principal_id
key_permissions = [
"Get", "Create", "Delete", "List", "Restore", "Recover", "UnwrapKey", "WrapKey", "Purge", "Encrypt", "Decrypt", "Sign", "Verify", "GetRotationPolicy"
]
secret_permissions = [
"Get",
]
}
}
resource "azurerm_key_vault_key" "test" {
name = "acctestkvkey%[3]s"
key_vault_id = azurerm_key_vault.test.id
key_type = "RSA"
key_size = 2048
key_opts = ["decrypt", "encrypt", "sign", "unwrapKey", "verify", "wrapKey"]
}
resource "azurerm_virtual_network" "test" {
name = "acctestvirtnet%[1]d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_subnet" "test_a" {
name = "acctestsubneta%[1]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.2.0/24"]
service_endpoints = ["Microsoft.CognitiveServices"]
}
resource "azurerm_subnet" "test_b" {
name = "acctestsubnetb%[1]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.4.0/24"]
service_endpoints = ["Microsoft.CognitiveServices"]
}
resource "azurerm_ai_services" "test" {
name = "acctestcogacc-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku_name = "S0"
fqdns = ["foo.com"]
local_authentication_enabled = true
outbound_network_access_restricted = true
public_network_access = "Enabled"
custom_subdomain_name = "acctestcogacc-%[1]d"
customer_managed_key {
key_vault_key_id = azurerm_key_vault_key.test.id
identity_client_id = azurerm_user_assigned_identity.test.client_id
}
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id
]
}
network_acls {
default_action = "Allow"
virtual_network_rules {
subnet_id = azurerm_subnet.test_a.id
}
virtual_network_rules {
subnet_id = azurerm_subnet.test_b.id
}
}
tags = {
Acceptance = "Test"
Environment = "Dev"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomIntOfLength(8))
}

func (r AIServices) networkACLs(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (r AIFoundryProject) Create() sdk.ResourceFunc {
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_ai_services_project", id.ID())
return tf.ImportAsExistsError("azurerm_ai_foundry_project", id.ID())
}

payload := workspaces.Workspace{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ resource "azurerm_ai_foundry_project" "test" {
type = "SystemAssigned"
}
}
`, AIServicesHub{}.basic(data), data.RandomInteger)
`, AIFoundry{}.basic(data), data.RandomInteger)
}

func (r AIFoundryProject) complete(data acceptance.TestData) string {
Expand All @@ -134,7 +134,7 @@ resource "azurerm_ai_foundry_project" "test" {
model = "regression"
}
}
`, AIServicesHub{}.complete(data), data.RandomInteger)
`, AIFoundry{}.complete(data), data.RandomInteger)
}

func (r AIFoundryProject) update(data acceptance.TestData) string {
Expand Down Expand Up @@ -166,7 +166,7 @@ resource "azurerm_ai_foundry_project" "test" {
env = "test"
}
}
`, AIServicesHub{}.complete(data), data.RandomInteger)
`, AIFoundry{}.complete(data), data.RandomInteger)
}

func (AIFoundryProject) requiresImport(data acceptance.TestData) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/machinelearning/ai_foundry_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (r AIFoundry) Create() sdk.ResourceFunc {
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_ai_services_hub", id.ID())
return tf.ImportAsExistsError("azurerm_ai_foundry", id.ID())
}

storageAccountId, err := commonids.ParseStorageAccountID(model.StorageAccountId)
Expand Down
32 changes: 16 additions & 16 deletions internal/services/machinelearning/ai_foundry_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type AIServicesHub struct{}
type AIFoundry struct{}

func TestAccAIFoundry_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_ai_foundry", "test")
r := AIServicesHub{}
r := AIFoundry{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -32,7 +32,7 @@ func TestAccAIFoundry_basic(t *testing.T) {

func TestAccAIFoundry_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_ai_foundry", "test")
r := AIServicesHub{}
r := AIFoundry{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -47,7 +47,7 @@ func TestAccAIFoundry_requiresImport(t *testing.T) {

func TestAccAIFoundry_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_ai_foundry", "test")
r := AIServicesHub{}
r := AIFoundry{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -62,7 +62,7 @@ func TestAccAIFoundry_complete(t *testing.T) {

func TestAccAIFoundry_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_ai_foundry", "test")
r := AIServicesHub{}
r := AIFoundry{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -84,7 +84,7 @@ func TestAccAIFoundry_update(t *testing.T) {

func TestAccAIFoundry_encryptionWithSystemAssignedId(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_ai_foundry", "test")
r := AIServicesHub{}
r := AIFoundry{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -99,7 +99,7 @@ func TestAccAIFoundry_encryptionWithSystemAssignedId(t *testing.T) {

func TestAccAIFoundry_encryptionWithUserAssignedId(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_ai_foundry", "test")
r := AIServicesHub{}
r := AIFoundry{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -112,7 +112,7 @@ func TestAccAIFoundry_encryptionWithUserAssignedId(t *testing.T) {
})
}

func (AIServicesHub) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
func (AIFoundry) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := workspaces.ParseWorkspaceID(state.ID)
if err != nil {
return nil, err
Expand All @@ -126,7 +126,7 @@ func (AIServicesHub) Exists(ctx context.Context, clients *clients.Client, state
return pointer.To(resp.Model != nil), nil
}

func (r AIServicesHub) basic(data acceptance.TestData) string {
func (r AIFoundry) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {
Expand All @@ -153,7 +153,7 @@ resource "azurerm_ai_foundry" "test" {
`, r.template(data), data.RandomInteger)
}

func (r AIServicesHub) complete(data acceptance.TestData) string {
func (r AIFoundry) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {
Expand Down Expand Up @@ -221,7 +221,7 @@ resource "azurerm_ai_foundry" "test" {
`, r.template(data), data.RandomInteger)
}

func (r AIServicesHub) update(data acceptance.TestData) string {
func (r AIFoundry) update(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {
Expand Down Expand Up @@ -296,7 +296,7 @@ resource "azurerm_ai_foundry" "test" {
`, r.template(data), data.RandomInteger)
}

func (r AIServicesHub) encryptionWithUserAssignedId(data acceptance.TestData) string {
func (r AIFoundry) encryptionWithUserAssignedId(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {
Expand Down Expand Up @@ -379,7 +379,7 @@ resource "azurerm_ai_foundry" "test" {
`, r.template(data), data.RandomInteger)
}

func (r AIServicesHub) encryptionWithSystemAssignedId(data acceptance.TestData) string {
func (r AIFoundry) encryptionWithSystemAssignedId(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {
Expand Down Expand Up @@ -427,8 +427,8 @@ resource "azurerm_ai_foundry" "test" {
`, r.template(data), data.RandomInteger)
}

func (AIServicesHub) requiresImport(data acceptance.TestData) string {
template := AIServicesHub{}.basic(data)
func (AIFoundry) requiresImport(data acceptance.TestData) string {
template := AIFoundry{}.basic(data)
return fmt.Sprintf(`
%s
Expand All @@ -446,7 +446,7 @@ resource "azurerm_ai_foundry" "import" {
`, template)
}

func (AIServicesHub) template(data acceptance.TestData) string {
func (AIFoundry) template(data acceptance.TestData) string {
return fmt.Sprintf(`
data "azurerm_client_config" "current" {}
Expand Down

0 comments on commit afa745d

Please sign in to comment.