Skip to content

Commit

Permalink
Search - update API version to 2024-06-01-preview (hashicorp#27803)
Browse files Browse the repository at this point in the history
* feat: update Search Service API version from 2022-09-01 and 2023-11-01 to 2024-06-01-preview

* test: update identity tests with PR feedback
  • Loading branch information
jan-mrm authored Nov 28, 2024
1 parent e40f92d commit 1b8d927
Show file tree
Hide file tree
Showing 106 changed files with 344 additions and 2,009 deletions.
2 changes: 1 addition & 1 deletion internal/services/cognitive/cognitive_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/cognitiveservicesaccounts"
search "github.com/hashicorp/go-azure-sdk/resource-manager/search/2022-09-01/services"
search "github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/services"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
commonValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down
8 changes: 4 additions & 4 deletions internal/services/search/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package client
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/adminkeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/querykeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/sharedprivatelinkresources"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/adminkeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/querykeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/sharedprivatelinkresources"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
14 changes: 9 additions & 5 deletions internal/services/search/search_service_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/adminkeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/querykeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/adminkeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/querykeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/services"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -88,7 +88,7 @@ func dataSourceSearchService() *pluginsdk.Resource {
Computed: true,
},

"identity": commonschema.SystemAssignedIdentityComputed(),
"identity": commonschema.SystemOrUserAssignedIdentityComputed(),

"tags": commonschema.TagsDataSource(),
},
Expand Down Expand Up @@ -141,7 +141,11 @@ func dataSourceSearchServiceRead(d *pluginsdk.ResourceData, meta interface{}) er
d.Set("public_network_access_enabled", publicNetworkAccess)
}

if err = d.Set("identity", identity.FlattenSystemAssigned(model.Identity)); err != nil {
flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %+v", err)
}
if err = d.Set("identity", flattenedIdentity); err != nil {
return fmt.Errorf("setting `identity`: %s", err)
}

Expand Down
18 changes: 11 additions & 7 deletions internal/services/search/search_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/adminkeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/querykeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/adminkeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/querykeys"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/services"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -187,7 +187,7 @@ func resourceSearchService() *pluginsdk.Resource {
},
},

"identity": commonschema.SystemAssignedIdentityOptional(),
"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"tags": commonschema.Tags(),
},
Expand Down Expand Up @@ -310,7 +310,7 @@ func resourceSearchServiceCreate(d *pluginsdk.ResourceData, meta interface{}) er
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

expandedIdentity, err := identity.ExpandSystemAssigned(d.Get("identity").([]interface{}))
expandedIdentity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func resourceSearchServiceUpdate(d *pluginsdk.ResourceData, meta interface{}) er
}

if d.HasChange("identity") {
expandedIdentity, err := identity.ExpandSystemAssigned(d.Get("identity").([]interface{}))
expandedIdentity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}
Expand Down Expand Up @@ -596,7 +596,11 @@ func resourceSearchServiceRead(d *pluginsdk.ResourceData, meta interface{}) erro
d.Set("semantic_search_sku", semanticSearchSku)
}

if err = d.Set("identity", identity.FlattenSystemAssigned(model.Identity)); err != nil {
flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %+v", err)
}
if err = d.Set("identity", flattenedIdentity); err != nil {
return fmt.Errorf("setting `identity`: %s", err)
}

Expand Down
137 changes: 136 additions & 1 deletion internal/services/search/search_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/services"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -242,6 +242,79 @@ func TestAccSearchService_identity(t *testing.T) {
})
}

func TestAccSearchService_identityUserAssigned(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
r := SearchServiceResource{}

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

func TestAccSearchService_identitySystemAndUserAssigned(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
r := SearchServiceResource{}

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

func TestAccSearchService_identityUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
r := SearchServiceResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, "standard"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.identity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.identityUserAssigned(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.identitySystemAndUserAssigned(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data, "standard"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSearchService_hostingMode(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
r := SearchServiceResource{}
Expand Down Expand Up @@ -629,6 +702,68 @@ resource "azurerm_search_service" "test" {
`, template, data.RandomInteger)
}

func (r SearchServiceResource) identityUserAssigned(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestUAI-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_search_service" "test" {
name = "acctestsearchservice%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "standard"
identity {
type = "UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
}
`, template, data.RandomInteger)
}

func (r SearchServiceResource) identitySystemAndUserAssigned(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestUAI-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_search_service" "test" {
name = "acctestsearchservice%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "standard"
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
}
`, template, data.RandomInteger)
}

func (r SearchServiceResource) hostingMode(data acceptance.TestData, sku string) string {
template := r.template(data)
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/sharedprivatelinkresources"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/services"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/sharedprivatelinkresources"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/search/2023-11-01/sharedprivatelinkresources"
"github.com/hashicorp/go-azure-sdk/resource-manager/search/2024-06-01-preview/sharedprivatelinkresources"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
Loading

0 comments on commit 1b8d927

Please sign in to comment.