-
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
azurerm_log_analytics_workspace
- prevent ForceNew when sku
is LACluster
#19608
azurerm_log_analytics_workspace
- prevent ForceNew when sku
is LACluster
#19608
Conversation
0ae37d3
to
2f558ed
Compare
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.
hey @ziyeqf
Thanks for this PR - I've left a comment inline but if we can fix that up then we should be able to take another look here 👍
Thanks!
internal/services/loganalytics/log_analytics_workspace_resource.go
Outdated
Show resolved
Hide resolved
lifecycle { | ||
ignore_changes = [ | ||
sku | ||
] | ||
} | ||
} |
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.
if this worked before this means you are going to affect peoples configurations?
How come this is needed now?
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.
Per the description in #17069, it used to make it not "force new", but still changed. then, due to SDK upgraded, it becomes "force new" again. fix this workaround only to make it not "force new", "ignore_changes" is still needed.
I have no idea what's this acctest status before sdk upgradtion, because it has been skipped on TC...But on current main
branch we can see it fails and the property shows "force replcement"
TF_ACC=1 go test -v ./internal/services/loganalytics -run=TestAccLogAnalyticsLinkedService_withWriteAccessResourceId -timeout=60m [ main][$][🐹 v1.19.4][⏱ 0ms][16:27:09]
=== RUN TestAccLogAnalyticsLinkedService_withWriteAccessResourceId
=== PAUSE TestAccLogAnalyticsLinkedService_withWriteAccessResourceId
=== CONT TestAccLogAnalyticsLinkedService_withWriteAccessResourceId
testcase.go:110: Step 1/2 error: After applying this test step and performing a `terraform refresh`, the plan was not empty.
stdout
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place
-/+ destroy and then create replacement
Terraform will perform the following actions:
# azurerm_log_analytics_linked_service.test will be updated in-place
~ resource "azurerm_log_analytics_linked_service" "test" {
id = "/subscriptions/{SubscriptionId}/resourceGroups/{rgName}providers/Microsoft.OperationalInsights/workspaces/acctestLAW-221216162722060884/linkedServices/Cluster"
name = "Cluster"
~ workspace_id = "/subscriptions/{subscriptionId}/resourceGroups/{rgName}/providers/Microsoft.OperationalInsights/workspaces/acctestLAW-221216162722060884" -> (known after apply)
# (2 unchanged attributes hidden)
}
# azurerm_log_analytics_workspace.test must be replaced
-/+ resource "azurerm_log_analytics_workspace" "test" {
- cmk_for_query_forced = false -> null
~ id = "/subscriptions/{subscriptionId}/resourceGroups/{rgname}/providers/Microsoft.OperationalInsights/workspaces/acctestLAW-221216162722060884" -> (known after apply)
name = "acctestLAW-221216162722060884"
~ primary_shared_key = (sensitive value)
+ reservation_capacity_in_gb_per_day = (known after apply)
~ secondary_shared_key = (sensitive value)
~ sku = "LACluster" -> "PerGB2018" # forces replacement
- tags = {} -> null
~ workspace_id = "XXXXXX" -> (known after apply)
# (7 unchanged attributes hidden)
}
Plan: 1 to add, 1 to change, 1 to destroy.
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.
again, we shouldn't need to ignore changes, its a sign something is wrong with 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.
As this seems to be a separate issue from the one being fixed in this PR, I'm going to remove this until we dedicate some more time to looking into it
Hi @WodansSon, could you please help take a look at this PR. I may misunderstand some codes of the workaround in #17069 |
@@ -221,7 +220,7 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta i | |||
t := d.Get("tags").(map[string]interface{}) | |||
|
|||
if isLACluster { | |||
sku.Name = "lacluster" | |||
sku.Name = workspaces.WorkspaceSkuNameEnumLACluster |
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 believe this maybe a breaking change depending on how the new enum cases the value. In the previous version we used lacluster
. So, if there is an existing resource with the sku lacluster
and the new value in the enum is LACluster
that my cause an issue 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.
We'll need to do a state migration and fix it on read perhapes?
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.
@ziyeqf - Are you able to check if this is an issue (i.e. build one with a released version, then manage it with your updated code) and add the state migration if needed?
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 test steps:
- deploy with latest released version.
- run
terraform plan
and then aForceNew
diff shows.
~ sku = "LACluster" -> "PerGB2018" # forces replacement
- plan with updated code, a diff without
ForceNew
shows.
~ sku = "LACluster" -> "PerGB2018"
- apply with updated code, it worked as expected.
My explain is:
After changed to azure-go-sdk, it has begun to set LACluster
to state file, which was ""
before, then the workaround goes invalid.
For the casing change here, it's only between provider and service, we used to use lacluster
in payload, and LACluster
now. Per the test result I think it should be ok?
Code ref:
terraform-provider-azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go
Lines 382 to 394 in 4ce0783
skuName := "" | |
if props.Sku != nil { | |
sku := *props.Sku | |
for _, v := range workspaces.PossibleValuesForWorkspaceSkuNameEnum() { | |
if strings.EqualFold(v, string(sku.Name)) { | |
skuName = v | |
} | |
} | |
if capacityReservationLevel := sku.CapacityReservationLevel; capacityReservationLevel != nil { | |
d.Set("reservation_capacity_in_gb_per_day", capacityReservationLevel) | |
} | |
} | |
d.Set("sku", skuName) |
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 @ziyeqf - I think you should test with a lacluster
value and check the effect of the change to LACluster
, since this Enum change will likely result in a diff, which is what I think @WodansSon was pointing out? This may need a state migration to update the value to prevent this.
Thanks!
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.
@jackofallops I don't think there will be a config with sku
set to lacluster
, it's now allowed in validateFunc
and will throw error in plan stage. And for state file, it will be set to LACluster
in refresh stage.
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.
@jackofallops I don't think there will be a config with
sku
set tolacluster
, it's not allowed invalidateFunc
and will throw error in plan stage. And for state file, it will be set toLACluster
in refresh stage.
sorry for typo, it's "not" allowed.
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.
previous versions allowed lacluster - we'll need to account for that as we don't know what version someone will be upgrading from so we can't make that asausmption
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.
So.. we need to allow lacluster
in validateFunc
again?
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.
Apologies for the back and forth @ziyeqf. Your implementation here is correct. We are only setting lacluster
during create and update and the api doesn't care about casing. During the read, we are setting sku
to LACluster
so the end user shouldn't encounter any state changes from this PR
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
lifecycle { | ||
ignore_changes = [ | ||
sku | ||
] | ||
} | ||
} |
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.
As this seems to be a separate issue from the one being fixed in this PR, I'm going to remove this until we dedicate some more time to looking into it
@@ -221,7 +220,7 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta i | |||
t := d.Get("tags").(map[string]interface{}) | |||
|
|||
if isLACluster { | |||
sku.Name = "lacluster" | |||
sku.Name = workspaces.WorkspaceSkuNameEnumLACluster |
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.
Apologies for the back and forth @ziyeqf. Your implementation here is correct. We are only setting lacluster
during create and update and the api doesn't care about casing. During the read, we are setting sku
to LACluster
so the end user shouldn't encounter any state changes from this PR
azurerm_log_analytics_workspace
- fix workaround when sku
is LACluster
azurerm_log_analytics_workspace
- prevent ForceNew when sku
is LACluster
This functionality has been released in v3.45.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! |
Hi, isn't this 2 year old bug related and the exact same issue? How come this was only done for the LACluster SKU? |
@JoshWeepie Thanks for pointing that, the mentioned issue is a little different as there is some limits on changing SKU. |
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. |
Since we have updated to
go-azure-sdk
, this workaround needs an update.workaround was invovled in #17069
Test
LogAnalyticsWorkspace
test with a cluster which will set
sku
toLACluster