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

azurerm_log_analytics_linked_storage_account - data_storage_type - case validation #16234

Closed
1 task done
Marcus-James-Adams opened this issue Apr 4, 2022 · 9 comments · Fixed by #18116
Closed
1 task done
Labels

Comments

@Marcus-James-Adams
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

1.1.7

AzureRM Provider Version

3.0.2

Affected Resource(s)/Data Source(s)

azurerm_log_analytics_linked_storage_account

Terraform Configuration Files

resource "azurerm_log_analytics_linked_storage_account" "main" {
  data_source_type      = "customlogs"
  resource_group_name   = data.terraform_remote_state.tf_monitoring.outputs.resource_group_name
  workspace_resource_id = data.terraform_remote_state.tf_monitoring.outputs.core_azurerm_log_analytics_workspace_id
  storage_account_ids   = [azurerm_storage_account.main.id]
}

Debug Output/Panic Output

On reapply only you get

  # azurerm_log_analytics_linked_storage_account.main must be replaced
-/+ resource "azurerm_log_analytics_linked_storage_account" "main" {
      ~ data_source_type      = "CustomLogs" -> "customlogs" # forces replacement
      ~ id                    = "xxxxxxxxxxxxxxxxxx" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

Expected Behaviour

Plans and applies ok every time

Actual Behaviour

Plans and applies ok the first time without issue
but on subsequent plans and applies gives the above output.
It looks like the case of data_source_type is being changed by the API upon apply

If you change the code to be

resource "azurerm_log_analytics_linked_storage_account" "main" {
  data_source_type      = "CustomLogs"
  resource_group_name   = data.terraform_remote_state.tf_monitoring.outputs.resource_group_name
  workspace_resource_id = data.terraform_remote_state.tf_monitoring.outputs.core_azurerm_log_analytics_workspace_id
  storage_account_ids   = [azurerm_storage_account.main.id]
}

You get the following validation error

Error: expected data_source_type to be one of [customlogs azurewatson query alerts ingestion], got CustomLogs

Steps to Reproduce

No response

Important Factoids

No response

References

No response

@github-actions github-actions bot removed the bug label Apr 4, 2022
katbyte pushed a commit that referenced this issue Apr 14, 2022
… Account Type` (#16313)

When setting the value for the property data_source_type, the value should be DataSourceType under the LinkedStorageAccountsProperties, instead of the name

Fix the issue:#16234
@w0rldart
Copy link

Do we know whether this is a Terraform or Azure API issue?

@capusta
Copy link

capusta commented Aug 15, 2022

this is still happening on provider version 3.16

  # module.backend.azurerm_log_analytics_linked_storage_account.whatevs must be replaced
-/+ resource "azurerm_log_analytics_linked_storage_account" "prisma-analytics-or-whatevs" {
      ~ data_source_type      = "CustomLogs" -> "customlogs" # forces replacement
      ~ id                    = "/subscriptions/<myprod>/resourceGroups/<myprod>/providers/Microsoft.OperationalInsights/workspaces/<myprod>/linkedStorageAccounts/customlogs" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

and of course the obligatory:

 t version
Terraform v0.14.11
+ provider registry.terraform.io/hashicorp/azuread v2.26.1
+ provider registry.terraform.io/hashicorp/azurerm v3.16.0
+ provider registry.terraform.io/hashicorp/tls v4.0.1

I understand this is an older version of terraform binary

@teowa
Copy link
Contributor

teowa commented Aug 23, 2022

Hi @w0rldart and @capusta , thanks for the comment.
Seems this issue should be fixed in PR #16313, and the config should set as below using lower case:

data_source_type      = "customlogs"

if there is still diff ("CustomLogs" -> "customlogs") shown after Terraform plan, you can try to use Terraform refresh to refresh the state, and then run Terraform plan. If you still have the issue after doing the refresh, feel free to reply here.

@w0rldart
Copy link

Thank you for your reply @teowa, but besides updating the Terraform provider version to 3.19.1, and running terraform refresh && terraform apply, I still face this issue.

@teowa
Copy link
Contributor

teowa commented Aug 24, 2022

@w0rldart thanks for the update. Seems I cannot repro your issue by creating a new linkedStorageAccount resource with the latest azurerm provider 3.19.1 or the old 3.1.0 with Terraform config in this link . Looks like service has changed API behaviour. Could you please try calling the REST API to GET the linkedStorageAccounts you have created before, here is a tutorial of calling Azure REST API.

GET https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.OperationalInsights/workspaces/{workspace_name}/linkedStorageAccounts/customlogs?api-version=2020-08-01

And please check if the dataSourceType is in lower case. If the property is still the Camel format like CustomLogs, it should be a service API bug.

@woo-Erupt
Copy link

woo-Erupt commented Aug 24, 2022

@teowa since I have the same issue, I checked via the API. I'm running 3.19.1 as well. I get the following

`> curl -X GET -H "Authorization: Bearer $tk" -H "Content-Type:application/json" -H "Accept:application/json" https://management.azure.com//subscriptions/1234*****/resourceGroups/test-e3a644d5/providers/Microsoft.OperationalInsights/workspaces/test-law/linkedStorageAccounts/customlogs\?api-version\=2020-08-01

{"properties":{"dataSourceType":"CustomLogs","storageAccountIds":["/subscriptions/1234*****/resourceGroups/test-e3a644d5/providers/Microsoft.Storage/storageAccounts/satest00"]},"location":"northcentralus","id":"/subscriptions/1234*****/resourceGroups/test-e3a644d5/providers/Microsoft.OperationalInsights/workspaces/test-law/linkedstorageaccounts/CustomLogs","name":"CustomLogs","type":"Microsoft.OperationalInsights/workspaces/linkedstorageaccounts"}%`

@capusta
Copy link

capusta commented Aug 24, 2022

Hi

data_source_type      = "customlogs"

if there is still diff ("CustomLogs" -> "customlogs") shown after Terraform plan, you can try to use Terraform refresh to refresh the state, and then run Terraform plan. If you still have the issue after doing the refresh, feel free to reply here.

still having the same issue :( I have done a refresh.

  # module.backend.azurerm_log_analytics_linked_storage_account.mything must be replaced
-/+ resource "azurerm_log_analytics_linked_storage_account" "mything" {
      ~ data_source_type      = "CustomLogs" -> "customlogs" # forces replacement
      ~ id                    = "/subscriptions/<clip>
        # (3 unchanged attributes hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Warning: Resource targeting is in effect
<clip>
Terraform specifically suggests to use it as part of an error message.


------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

% t version
Terraform v0.14.11
+ provider registry.terraform.io/hashicorp/azuread v1.5.1
+ provider registry.terraform.io/hashicorp/azurerm v3.19.1
+ provider registry.terraform.io/hashicorp/random v3.3.2
+ provider registry.terraform.io/hashicorp/tls v4.0.1

Your version of Terraform is out of date! The latest version
is 1.2.8. You can update by downloading from https://www.terraform.io/downloads.html

@teowa
Copy link
Contributor

teowa commented Sep 7, 2022

The issue is releated to service API issue Azure/azure-rest-api-specs#20619, cases sensitivity differs with locations.

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
6 participants