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

New data source azurerm_search_service #10181

Merged
merged 9 commits into from
Jan 28, 2021

Conversation

jackbatzner
Copy link
Contributor

Fixes #10153

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 @Brunhil

Thanks for this PR :)

I've taken a look through and this is looking good, if we can fix up the comments and linting issues then this should otherwise be good to go 👍

Thanks!

if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[INFO] Error reading Search Service %q - removing from state", d.Id())
d.SetId("")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a Data Source we should raise an error if this is not found rather than returning nil here - so could we make this:

Suggested change
return nil
return fmt.Errorf("%s was not found", id)

(the format string for "id" will be "Search Service %q (Resource Group %q)")

{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").Exists(),
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 remove this, since otherwise the resource won't be in the state/will raise an error (which'll be hit before this point)

Suggested change
check.That(data.ResourceName).Key("id").Exists(),


* `replica_count` - The number of replica's which have been created.

-> **Note:** `partition_count` and `replica_count` can only be configured when using a `standard` sku.
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a data source, this isn't configurable - so we can remove this (since the fields should get a default value either way)

Suggested change
-> **Note:** `partition_count` and `replica_count` can only be configured when using a `standard` sku.


* `query_keys` - A `query_keys` block as defined below.

* `public_network_access_enabled` - Whether or not public network access is allowed for this resource. Defaults to `true`.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a Data Source which is read-only, so the default value doesn't apply here - could we also update the messaging to highlight this isn't configurable:

Suggested change
* `public_network_access_enabled` - Whether or not public network access is allowed for this resource. Defaults to `true`.
* `public_network_access_enabled` - Whether or not public network access is enabled for this Search Service.


* `identity` - An `identity` block as defined below.

* `tags` - (Optional) A mapping of tags which should be assigned to the Search Service.
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) since this isn't configurable can we update the wording to highlight that this is read only:

Suggested change
* `tags` - (Optional) A mapping of tags which should be assigned to the Search Service.
* `tags` - A mapping of tags which are assigned to the Search Service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't actually set the tags on this data source so I'll just remove this line 😄


A `identity` block supports the following:

* `type` - The Type of Identity which should be used for the Search Service. At this time the only possible value is `SystemAssigned`.
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above)

Suggested change
* `type` - The Type of Identity which should be used for the Search Service. At this time the only possible value is `SystemAssigned`.
* `type` - The type of Managed Identity which used for the Search Service.

@tombuildsstuff tombuildsstuff added this to the v2.44.0 milestone Jan 14, 2021
@tombuildsstuff tombuildsstuff modified the milestones: v2.44.0, v2.45.0 Jan 21, 2021
@jackbatzner
Copy link
Contributor Author

Thanks for the review @tombuildsstuff ! Let me know if there are any other changes you see

@ghost ghost removed the waiting-response label Jan 21, 2021
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 @Brunhil

Thanks for pushing those changes - I've taken a look through and left some comments inline but if we can fix those up then this should be good to go 👍

Thanks!

"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

as the linter says, a Data Sources properties can't be ForceNew - so we can remove this:

Suggested change
ForceNew: true,

"identity": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

as the linter mentions, since this is a Data Source we can remove the max items here, since these are read-only/not user configurable:

Suggested change
MaxItems: 1,

if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[INFO] Error reading Search Service %q - removing from state", d.Id())
d.SetId("")
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 remove both of these lines since the error will raise this anyway

id, err := parse.SearchServiceID(d.Id())
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

a Data Source won't have an ID at this point, instead it needs to look this up using the name and resource_group_name - that said we need to build this up to use it below - so can we make this:

Suggested change
}
subscriptionId := meta.(*clients.Client).Account.SubscriptionID
id := parse.NewSearchServiceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))

}

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
Copy link
Contributor

Choose a reason for hiding this comment

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

since the user is specifying these, we can remove these and just set the ID instead (which is needed for this to get tracked into the state):

Suggested change
d.Set("resource_group_name", id.ResourceGroup)
d.SetID(id.ID())


The following arguments are supported:

* `name` - (Required) The Name which should be used for this Search Service. Changing this forces a new Search Service to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

for the data source this will already exist, so we can update the language here:

Suggested change
* `name` - (Required) The Name which should be used for this Search Service. Changing this forces a new Search Service to be created.
* `name` - (Required) The Name of the Search Service.

(since this is a Data Source this also doesn't force a new resource


* `name` - (Required) The Name which should be used for this Search Service. Changing this forces a new Search Service to be created.

* `resource_group_name` - (Required) The name of the Resource Group where the Search Service should exist. Changing this forces a new Search Service to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

Suggested change
* `resource_group_name` - (Required) The name of the Resource Group where the Search Service should exist. Changing this forces a new Search Service to be created.
* `resource_group_name` - (Required) The name of the Resource Group where the Search Service exists.

@katbyte
Copy link
Collaborator

katbyte commented Jan 23, 2021

Test is also failing with

------- Stdout: -------
=== RUN   TestAccDataSourceSearchService_basic
=== PAUSE TestAccDataSourceSearchService_basic
=== CONT  TestAccDataSourceSearchService_basic
    testing.go:684: Step 0 error: errors during apply:
        
        Error: Cannot parse Azure ID: parse "": empty url
        
          on /opt/teamcity-agent/temp/buildTmp/tf-test424173270/main.tf line 24:
          (source code not available)
        
        
--- FAIL: TestAccDataSourceSearchService_basic (136.98s)
FAIL

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.

LGTM - thanks for pushing those changes @Brunhil

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Even after committing that change it the test is still failing:

------- Stdout: -------
=== RUN   TestAccDataSourceSearchService_basic
=== PAUSE TestAccDataSourceSearchService_basic
=== CONT  TestAccDataSourceSearchService_basic
    testing.go:684: Step 0 error: Check failed: Check 6/8 error: data.azurerm_search_service.test: Attribute 'identity.0.type' expected to be set
--- FAIL: TestAccDataSourceSearchService_basic (104.58s)
FAIL

@ghost ghost added size/XL and removed size/L labels Jan 28, 2021
@jackbatzner
Copy link
Contributor Author

Turns out I was missing the identity block which I added in the most recent commit. Hopefully things are good now @katbyte ! 🤞

@jackbatzner jackbatzner requested a review from katbyte January 28, 2021 02:56
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Aside from one comment this LGTM 👍

@katbyte katbyte merged commit eb49bad into hashicorp:master Jan 28, 2021
katbyte added a commit that referenced this pull request Jan 28, 2021
@ghost
Copy link

ghost commented Jan 28, 2021

This has been released in version 2.45.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.45.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Feb 27, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 27, 2021
@jackbatzner jackbatzner deleted the data_search_service branch March 2, 2021 02:27
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.

Support for Azure Search Service Data Source
3 participants