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_standard_environment #7012

Merged
merged 10 commits into from May 21, 2020

Conversation

mbfrahry
Copy link
Member

@mbfrahry mbfrahry commented May 19, 2020

--- PASS: TestAccAzureRMTimeSeriesInsightsEnvironment_basic (139.73s)
--- PASS: TestAccAzureRMTimeSeriesInsightsEnvironment_complete (301.78s)

Fixes #3844

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!

Mostly this looks really good 👍 , aside from some comments I left inline.

func TimeSeriesInsightsEnvironmentID(input string) (*TimeSeriesInsightsEnvironmentId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse Time Series Insights Environment ID %q: %+v", input, err)
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 modify this error message a bit to make it to look less like a log rather than an error message?

Suggested change
return nil, fmt.Errorf("[ERROR] Unable to parse Time Series Insights Environment ID %q: %+v", input, err)
return nil, fmt.Errorf("parsing Time Series Insights Environment ID %q: %+v", input, err)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Done!

Comment on lines 49 to 50
regexp.MustCompile(`^[-\w\._\(\)]+$`),
"Time Series Insights Environment name must be 1 - 90 characters long, contain only word characters and underscores.",
Copy link
Contributor

Choose a reason for hiding this comment

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

This regex does not really match the error message below. For instance this regex does not have a constraint of length, and the regex also allows braces. Which one is expected? We should at least modify one of these.

Comment on lines 31 to 34
Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error {
_, err := parse.TimeSeriesInsightsEnvironmentID(id)
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.

Based on the content below, this resource is a polymorphic one. Since different types of this resource share the same ID, could we add a bit more validation here to ensure the user is importing the ID to the right resource?

Comment on lines 185 to 187
if resource.ID == nil {
return fmt.Errorf("cannot read Time Series Insights Environment %q (Resource Group %q) ID", name, 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 add a check to ensure the ID is not nil and not empty?

Suggested change
if resource.ID == nil {
return fmt.Errorf("cannot read Time Series Insights Environment %q (Resource Group %q) ID", name, resourceGroup)
}
if resource.ID == nil || *resource.ID == "" {
return fmt.Errorf("cannot read Time Series Insights Environment %q (Resource Group %q) ID", name, resourceGroup)
}

Comment on lines 252 to 253
if !utils.ResponseWasNotFound(response) {
return fmt.Errorf("deleting Time Series Insights Environment %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 suppose if the service returns 404 when you are deleting the resource, it is still something wrong happening. Typically if you are attempting to delete a non-existing resource, the service should return 204

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

if resp.StatusCode != http.StatusNotFound {
return fmt.Errorf("Time Series Insights Environment 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.

This reads really weird. If the resource does not exist, the error would be non-nil, and this check would return nil immediately. But if something is wrong (for instance 429 returned), the error would be also non-nil. In this case, this case would regard this as "the resource does not exist" and return nil.

On the other hand, the if resp.StatusCode != http.StatusNotFound would never succeed. Get function would only return nil error when it gets the resource successfully (in other word 200), in this case the status code would never be 404.
This behaviour is also defined in the swagger here

Copy link
Contributor

Choose a reason for hiding this comment

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

And to be honest, a lot of the existing tests have this kind of check destroy functions, which I suppose it is not so correct. What do you think?

Comment on lines 43 to 63
{
Config: testAccAzureRMTimeSeriesInsightsEnvironment_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMTimeSeriesInsightsEnvironmentExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMTimeSeriesInsightsEnvironment_complete(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMTimeSeriesInsightsEnvironmentExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMTimeSeriesInsightsEnvironment_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMTimeSeriesInsightsEnvironmentExists(data.ResourceName),
),
},
data.ImportStep(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this update test really help? Because in the schema, the tags are defined as ForceNew, and the config for basic does not have a tag, complete config has a tag. Therefore this update would always be a replacement rather than a in-place update.


* `partition_key` - (Optional) The name of the event property which will be used to partition data.

* `tags` - (Optional) A mapping of tags to assign to the resource.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the tags ForceNew as defined in the schema? If it is, we should change this description accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

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

My fault here! Tags now updates without recreating the resource

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.

LGTM 👍

@mbfrahry mbfrahry merged commit 4267a85 into master May 21, 2020
@mbfrahry mbfrahry deleted the f-tsi-environments branch May 21, 2020 22:34
@mbfrahry mbfrahry changed the title New Resource: azurerm_time_series_insights_environment New Resource: azurerm_iot_time_series_insights_standard_environment May 21, 2020
mbfrahry added a commit that referenced this pull request May 21, 2020
@ghost
Copy link

ghost commented May 22, 2020

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

@ghost
Copy link

ghost commented Jun 21, 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 Jun 21, 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.

Support for Microsoft.TimeSeriesInsights
3 participants