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_search_service - add support for local_authentication_enabled, authentication_failure_mode, authentication_options and hosting_mode #21323

Merged
merged 17 commits into from
Apr 26, 2023

Conversation

WodansSon
Copy link
Collaborator

(fixes #10151)

@WodansSon WodansSon added this to the Future milestone Apr 6, 2023
@WodansSon WodansSon marked this pull request as draft April 6, 2023 19:21
@WodansSon WodansSon changed the title azurerm_search_service - add support for authentication_options, cmk_encryption and hosting_mode azurerm_search_service - add support for api_access_control, cmk_encryption and hosting_mode Apr 7, 2023
@WodansSon WodansSon changed the title azurerm_search_service - add support for api_access_control, cmk_encryption and hosting_mode azurerm_search_service - add support for api_access_control, cmk_enforcement_enabled and hosting_mode Apr 9, 2023
@WodansSon
Copy link
Collaborator Author

Progress! 🙂
image

@WodansSon WodansSon marked this pull request as ready for review April 13, 2023 08:51
@WodansSon WodansSon modified the milestones: Future, v3.53.0 Apr 13, 2023
@WodansSon
Copy link
Collaborator Author

image

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @WodansSon

Thanks for this PR - I've taken a look through and left some design comments inline, but if we can fix those up then we should be able to take another look here.

Thanks!

internal/services/search/search_service_resource.go Outdated Show resolved Hide resolved
internal/services/search/search_service_resource.go Outdated Show resolved Hide resolved
internal/services/search/search_service_resource.go Outdated Show resolved Hide resolved
Comment on lines +293 to +296
// fix for issue #10151, if the identity type is TypeNone do not include it
// in the create call, only in the update call when 'identity' is removed from the
// configuration file...
if expandedIdentity.Type != identity.TypeNone {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a Swagger issue for this if memory serves?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know... I looked but was not able to locate it... 🤷‍♂️

return fmt.Errorf("expanding `identity`: %+v", err)
}

// NOTE: Passing type 'None' on update will remove all identities from the service.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the standard behaviour in ARM, so I think we can remove this comment?

Suggested change
// NOTE: Passing type 'None' on update will remove all identities from the service.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 491 to 495
var cmkCompliance string
if props.EncryptionWithCmk != nil {
cmkEnforcement = strings.EqualFold(string(pointer.From(props.EncryptionWithCmk.Enforcement)), string(services.SearchEncryptionWithCmkEnabled))
cmkCompliance = string(pointer.From(props.EncryptionWithCmk.EncryptionComplianceStatus))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the compliance status is checking data within the search service, it's a reasonable expectation that this would be as async value, therefore the value returned from the API is likely to be outdated on the initial run, so I'm curious as to the value of exposing these field(s)? Whilst the enabled toggle may make sense, the status isn't going to be something users are likely to action upon in Terraform (and would instead be triggered via a report/interactively via the CLI/Portal etc) - so I have a feeling we shouldn't expose status here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, but I would lean toward exposing it rather than hide it as we don't know how the end-users would use this field. On a side note, what is the harm in having it exposed even if no one uses it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a side note, what is the harm in having it exposed even if no one uses it?

The challenge in doing so is where doing so can have unintended consequences - for example in this case since the status field is likely to be updated asynchronously, the value being returned by Terraform here likely doesn't make sense for us to expose. Whilst we could expose the enabled field - since the status field is both:

a) possible out of date since it's likely this is updated OOB
b) likely run interactively (e.g. via the Azure CLI, or alerted on via a monitor etc)

I think we should remove the status field for now until we have a valid use-case for that


func TestAccSearchService_replicaCountInvalid(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
// NOTE: The default qouta for the 'free' sku is 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NOTE: The default qouta for the 'free' sku is 1
// NOTE: The default quota for the 'free' sku is 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 18 to 22
sku string
count int
enforceCmk bool
apiAccessControlType string
apiAccessControlAuthenticationFailureMode string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: elsewhere in the provider we pass these arguments in where required - but typically use pre-templated Terraform configurations as tests - could we update this to match the convention used in the rest of the provider?

Suggested change
sku string
count int
enforceCmk bool
apiAccessControlType string
apiAccessControlAuthenticationFailureMode string

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 327 to 329
rbac := SearchServiceResource{sku: "standard", apiAccessControlType: "role_based_access_control"}
rbacApiFourZeroOne := SearchServiceResource{sku: "standard", apiAccessControlType: "role_based_access_control_and_api_keys", apiAccessControlAuthenticationFailureMode: "http401WithBearerChallenge"}
rbacApiFourZeroThree := SearchServiceResource{sku: "standard", apiAccessControlType: "role_based_access_control_and_api_keys", apiAccessControlAuthenticationFailureMode: "http403"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whilst there's some readability benefits on a per-test basis here - it's more likely we'll introduce bugs with this approach since the configs are harder to reason with, can we update this to use distinct Terraform configurations (as above)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 8 to 19
partitionCount := v.(int)

switch partitionCount {
case 5, 7, 8, 9, 10, 11:
errors = append(errors, fmt.Errorf("%q must be 1, 2, 3, 4, 6, or 12, got %d", k, partitionCount))
}

if partitionCount > 12 {
errors = append(errors, fmt.Errorf("%q must be 1, 2, 3, 4, 6, or 12, got %d", k, partitionCount))
}

return warnings, errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can reuse an existing validation function here:

Suggested change
partitionCount := v.(int)
switch partitionCount {
case 5, 7, 8, 9, 10, 11:
errors = append(errors, fmt.Errorf("%q must be 1, 2, 3, 4, 6, or 12, got %d", k, partitionCount))
}
if partitionCount > 12 {
errors = append(errors, fmt.Errorf("%q must be 1, 2, 3, 4, 6, or 12, got %d", k, partitionCount))
}
return warnings, errors
return validation.IntInSlice([]int{
1,
2,
3,
4,
6,
12,
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@WodansSon
Copy link
Collaborator Author

image

@WodansSon WodansSon changed the title azurerm_search_service - add support for api_access_control, cmk_enforcement_enabled and hosting_mode azurerm_search_service - add support for local_authentication_disabled, authentication_failure_mode and hosting_mode Apr 14, 2023
@WodansSon WodansSon changed the title azurerm_search_service - add support for local_authentication_disabled, authentication_failure_mode and hosting_mode azurerm_search_service - add support for local_authentication_disabled, authentication_failure_mode, authentication_options and hosting_mode Apr 15, 2023
@katbyte katbyte modified the milestones: v3.53.0, v3.54.0 Apr 21, 2023
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @WodansSon

Thanks for pushing those changes, I've taken a look through and left some comments inline - so that we can get this PR merged I hope you don't mind but I'm going to push a commit to fix those, so that we can get this shipped.

Thanks!

internal/services/search/search_service_resource.go Outdated Show resolved Hide resolved
internal/services/search/search_service_resource.go Outdated Show resolved Hide resolved

// NOTE: hosting mode is only valid if the SKU is 'standard3'
if skuName != services.SkuNameStandardThree && hostingMode == services.HostingModeHighDensity {
return fmt.Errorf("'hosting_mode' can only be defined if the 'sku' field is set to the 'standard3' SKU, got %q", skuName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link the other PR? Where a constant value is used in an error message, we should be referencing the constant value, since this ensures we avoid typos etc

Comment on lines 491 to 495
var cmkCompliance string
if props.EncryptionWithCmk != nil {
cmkEnforcement = strings.EqualFold(string(pointer.From(props.EncryptionWithCmk.Enforcement)), string(services.SearchEncryptionWithCmkEnabled))
cmkCompliance = string(pointer.From(props.EncryptionWithCmk.EncryptionComplianceStatus))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a side note, what is the harm in having it exposed even if no one uses it?

The challenge in doing so is where doing so can have unintended consequences - for example in this case since the status field is likely to be updated asynchronously, the value being returned by Terraform here likely doesn't make sense for us to expose. Whilst we could expose the enabled field - since the status field is both:

a) possible out of date since it's likely this is updated OOB
b) likely run interactively (e.g. via the Azure CLI, or alerted on via a monitor etc)

I think we should remove the status field for now until we have a valid use-case for that

internal/services/search/search_service_resource.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added size/XS and removed size/XL labels Apr 26, 2023
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WodansSon & @tombuildsstuff - This LGTM 👍

@tombuildsstuff tombuildsstuff changed the title azurerm_search_service - add support for local_authentication_disabled, authentication_failure_mode, authentication_options and hosting_mode azurerm_search_service - add support for local_authentication_enabled, authentication_failure_mode, authentication_options and hosting_mode Apr 26, 2023
@tombuildsstuff
Copy link
Contributor

Tests pass:

Screenshot 2023-04-26 at 16 27 09

@tombuildsstuff tombuildsstuff merged commit 7b14fce into main Apr 26, 2023
@tombuildsstuff tombuildsstuff deleted the e_search_fix branch April 26, 2023 14:30
tombuildsstuff added a commit that referenced this pull request Apr 26, 2023
@github-actions
Copy link

This functionality has been released in v3.54.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@njglenuk
Copy link

njglenuk commented May 1, 2023

There seems to be an issue with the new argument: "hosting_mode" with azurerm 3.54. It is forcing a replacement of the search service due to the API returning 'Default' with a capital and azurerm trying change this to 'default' without a capital:

hosting_mode = "Default" -> "default" # forces replacement

I've checked the terraform state: terraform state show "azurerm_search_service.example"
And it returns:

resource "azurerm_search_service" "example" {
...
hosting_mode = "Default"
...

Removing the resource from state and re-importing does not help to resolve the issue.

Setting the argument in the Terraform code to: hosting_mode = "default" also forces the replacement.

Trying to use hosting_mode = "Default" errors out too.

I've had to lock the azurerm provider to 3.53 to allow the run to complete without forcing the replacement.

Here is the original Terrafrom code:

resource "azurerm_search_service" "example" {
name = local.cognitive_search_name
resource_group_name = local.resource_group_name
location = local.location
sku = "standard"
public_network_access_enabled = false
identity {
type = "SystemAssigned"
}
tags = local.common_tags
}

Copy link

github-actions bot commented Jun 1, 2024

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/search_service: API requires omitting the "identity" block for free tier sku's
5 participants