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 Resource: azurerm_iot_time_series_insights_access_policy #7202

Merged
merged 7 commits into from Jun 9, 2020

Conversation

mbfrahry
Copy link
Member

@mbfrahry mbfrahry commented Jun 4, 2020

--- PASS: TestAccAzureRMIoTTimeSeriesInsightsAccessPolicy_basic (140.50s)
--- PASS: TestAccAzureRMIoTTimeSeriesInsightsAccessPolicy_update (178.49s)

@mbfrahry mbfrahry requested a review from a team June 4, 2020 02:57
Copy link
Contributor

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

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

Hi @mbfrahry thanks for this PR! This PR overall looks very good, and I have left some comment inline, please have a look, thanks!

ForceNew: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[-\w\._\(\)]+$`),
"IoT Time Series Insights Access Policy name must contain only word characters, periods, underscores, and parentheses.",
Copy link
Contributor

Choose a reason for hiding this comment

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

The regex also says hyphens are allowed, could we please also update the message accordingly? Or please confirm whether the hyphens are allowed?

ForceNew: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[-\w\._\(\)]+$`),
"IoT Time Series Insights Environment name must contain only word characters, periods, underscores, and parentheses.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
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 an object id, could we add a validation of IsUUID?
And I suppose maybe principal_id is sufficient, since there are a lot of principal_ids in the identity blocks of other resources.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going based off the docs in Azure and the API accepts any string. I'd like to keep it matching with what the API accepts over forcing our own rules.

Comment on lines +183 to +185
if !utils.ResponseWasNotFound(response) {
return fmt.Errorf("deleting IoT Time Series Insights Access Policy %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not escape 404 errors here. Whether the SDK gives non-nil errors is defined here in the response section of the swagger. For the listed status codes, SDK will not return non-nil errors for them (in this case, they are 200 and 204). And all other status codes, the SDK will return non-nil errors using the error schema defined here.

This means in this case, 404 will always be an error and indicates something is wrong. If this resource does not exist, and we still want to delete this, the service should return 204 for this.

One of the scenario 404 was returned in deletion should be we are deleting this resource, but the resource group does not exist. I believe in this case the service would return 404. But in this case I believe we should call out and throw errors.
What do you think?

Comment on lines 89 to 91
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: Time Series Insights Access Policy %q (resource group: %q) does not exist", id.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.

Could we please move this if statement should move into the above if err != nil statement? Because when the service returns 404, the err will always be non-nil, this means this piece of code is actually unreachable.

Comment on lines +112 to +118
if err != nil {
return nil
}

if resp.StatusCode != http.StatusNotFound {
return fmt.Errorf("time Series Insights Access Policy still exists: %q", id.Name)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we should guarantee that this function only returns nil when the response code is 404 and return non-nil errors for all the other cases.

Azure IoT Time Series Insights Access Policy can be imported using the `resource id`, e.g.

```shell
terraform import azurerm_iot_time_series_access_policy.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.TimeSeriesInsights/environments/environment1/accessPolicies/example
Copy link
Contributor

Choose a reason for hiding this comment

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

In the parsing function, we are poping out the name segment using accesspolicies(small p). Therefore could we either modify this example or check if the parsing function is working properly using the small p?

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 two comments LgTM 👍


"resource_group_name": azure.SchemaResourceGroupName(),

"environment_name": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this might be more clear is time_series_environment_name?

Comment on lines 119 to 120
_, err := client.CreateOrUpdate(ctx, resourceGroup, environmentName, name, policy)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

these lines cna be combines

Suggested change
_, err := client.CreateOrUpdate(ctx, resourceGroup, environmentName, name, policy)
if err != nil {
if _, err := client.CreateOrUpdate(ctx, resourceGroup, environmentName, name, policy); err != nil {

@mbfrahry mbfrahry merged commit 273d3bf into master Jun 9, 2020
@mbfrahry mbfrahry deleted the f-tsi-access-policy branch June 9, 2020 15:06
mbfrahry added a commit that referenced this pull request Jun 9, 2020
@ghost
Copy link

ghost commented Jun 11, 2020

This has been released in version 2.14.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.14.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Jul 10, 2020

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 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Jul 10, 2020
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.

None yet

3 participants