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

Search - update API version to 2024-06-01-preview #27803

Merged
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
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 @@ -83,7 +83,7 @@ func dataSourceSearchService() *pluginsdk.Resource {
Computed: true,
},

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

"tags": commonschema.TagsDataSource(),
},
Expand Down Expand Up @@ -132,7 +132,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 @@ -182,7 +182,7 @@ func resourceSearchService() *pluginsdk.Resource {
},
},

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

"tags": commonschema.Tags(),
},
Expand Down Expand Up @@ -305,7 +305,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 @@ -387,7 +387,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 @@ -590,7 +590,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 @@ -628,6 +701,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
Loading