-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Done!
regexp.MustCompile(`^[-\w\._\(\)]+$`), | ||
"Time Series Insights Environment name must be 1 - 90 characters long, contain only word characters and underscores.", |
There was a problem hiding this comment.
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.
Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { | ||
_, err := parse.TimeSeriesInsightsEnvironmentID(id) | ||
return err | ||
}), |
There was a problem hiding this comment.
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?
if resource.ID == nil { | ||
return fmt.Errorf("cannot read Time Series Insights Environment %q (Resource Group %q) ID", name, resourceGroup) | ||
} |
There was a problem hiding this comment.
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?
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) | |
} |
if !utils.ResponseWasNotFound(response) { | ||
return fmt.Errorf("deleting Time Series Insights Environment %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) |
There was a problem hiding this comment.
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
if err != nil { | ||
return nil | ||
} | ||
|
||
if resp.StatusCode != http.StatusNotFound { | ||
return fmt.Errorf("Time Series Insights Environment still exists: %q", id.Name) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
{ | ||
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(), |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
azurerm_time_series_insights_environment
azurerm_iot_time_series_insights_standard_environment
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 ... |
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! |
Fixes #3844