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

Resources with Space in the name generate bad TF #259

Closed
emilwester-optimizely opened this issue Oct 12, 2022 · 3 comments · Fixed by hashicorp/terraform-provider-azurerm#25559 or #517
Labels
question Further information is requested upstream-provider

Comments

@emilwester-optimizely
Copy link

Some resources in azure have space in them. This generates bad TF and errors when doing terraform apply

TF code:

resource "azurerm_monitor_smart_detector_alert_rule" "res-486" {
  description         = "Failure Anomalies notifies you of an unusual rise in the rate of failed HTTP requests or dependency calls."
  detector_type       = "FailureAnomaliesDetector"
  frequency           = "PT1M"
  name                = "Failure Anomalies - REMOVED"
  resource_group_name = "REMOVED"
  scope_resource_ids  = ["/subscriptions/REMOVED/resourcegroups/REMOVED/providers/microsoft.insights/components/REMOVED"]
  severity            = "Sev3"
  action_group {
    ids = ["/subscriptions/REMOVED/resourcegroups/REMOVED/providers/microsoft.insights/actiongroups/application insights smart detection"]
  }
  depends_on = [
    azurerm_resource_group.res-0,
  ]
}

TF apply response:

Error: ID was missing the `actionGroups` element
│ 
│   with azurerm_monitor_smart_detector_alert_rule.res-486,
│   on main.tf line 837, in resource "azurerm_monitor_smart_detector_alert_rule" "res-486":
│  837:     ids = ["/subscriptions/REMOVED/resourcegroups/REMOVED/providers/microsoft.insights/actiongroups/application insights smart detection"]

I have tried replacing the space with + and %20 but it still fails.

this is related to:
Azure/azure-cli#12885
but there is a workaround in comment:
Azure/azure-cli#12885 (comment)

Can we implement a similar workaround until fixed?

@magodo
Copy link
Collaborator

magodo commented Oct 13, 2022

@emilwester-optimizely Thank you for submitting this! The issue is not caused by the empty space in the resource name, but the casing of the element in the ids array. The only change needed to make this work is to modify the actiongroups to actionGroups.

The reason why this happens is because the provider has some special handling for this property: https://github.com/hashicorp/terraform-provider-azurerm/blob/04eaea00a40d28f447c55e084ef1aef47139d1b0/internal/services/monitor/monitor_smart_detector_alert_rule_resource.go#L108. This makes all the characters to be lowercased. However, when the provider read this in, it requires it to be case sensitive, which result into the error you saw.

Currently, aztfy doesn't tune these property-level issues, for the sake of maintainability.

@magodo magodo added question Further information is requested upstream-provider labels Oct 13, 2022
@harshitjain5june
Copy link

any update on this issue? as I still faced this same issue while using aztfexport

@magodo
Copy link
Collaborator

magodo commented Apr 10, 2024

@harshitjain5june Upstream PR submitted to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested upstream-provider
Projects
None yet
3 participants