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_automation_variable_string wrong behavior for variables with '#' in the name #22086

Open
1 task done
kandelk opened this issue Jun 8, 2023 · 3 comments
Open
1 task done

Comments

@kandelk
Copy link

kandelk commented Jun 8, 2023

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.4.6

AzureRM Provider Version

3.59.0

Affected Resource(s)/Data Source(s)

azurerm_automation_variable_string

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.59.0"
    }
  }
}

provider "azurerm" {
  features {}
}

data "azurerm_automation_variable_string" "test_variable" {
  name                    = "my_variable#test"
  automation_account_name = "testaccount"
  resource_group_name     = "test-rg"
}

output "variable_value_wrong" {
  value = data.azurerm_automation_variable_string.test_variable.value
}

Debug Output/Panic Output

data.azurerm_automation_variable_string.test_variable: Reading...
2023-06-08T13:53:53.313+0300 [DEBUG] provider.terraform-provider-azurerm_v3.59.0_x5: AzureRM Request: 
GET /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Automation/automationAccounts/testaccount/variables/my_variable?api-version=2020-01-13-preview HTTP/1.1
[...]
2023-06-08T13:53:58.177+0300 [DEBUG] provider.terraform-provider-azurerm_v3.59.0_x5: AzureRM Response for https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Automation/automationAccounts/testaccount/variables/my_variable?api-version=2020-01-13-preview#test: 
HTTP/2.0 404 Not Found
[...]

{"code":"NotFound","message":"Variable not found."}: timestamp=2023-06-08T13:53:58.177+0300
2023-06-08T13:53:58.227+0300 [INFO]  provider.terraform-provider-azurerm_v3.59.0_x5: Automation String Variable "" does not exist - removing from state: timestamp=2023-06-08T13:53:58.226+0300

Expected Behaviour

The provider should return correct value regardless of variable name

Actual Behaviour

The provider searches for the wrong variable if its name contains '#' (according to Azure specification variable name can contain '#'). Ex. if the variable name is 'my_variable#test', the provider tries to read variable with name 'my_variable'.

Steps to Reproduce

  1. Create automation account 'testaccount'
  2. Add variable 'my_variable#test' with any value
  3. Run terraform apply

Important Factoids

No response

References

No response

@wuxu92
Copy link
Contributor

wuxu92 commented Jun 10, 2023

@kandelk thanks for filing this issue. as the name of a variable resource is part of the URL when create/get the resource, so the # will be parsed as the fragment part of the URL and it makes the provider request a wrong URL, which means it read a varibale name as my_variable instead of my_variable#test.

just for curiouse how did you create a variable name like my_variable#test, because i can't create such variable in Azure Portal neither:

image

@kandelk
Copy link
Author

kandelk commented Jun 12, 2023

@wuxu92 Thanks for your help. I also can't create such variable in the portal.
I created the variable using terraform with azurerm provider version 3.44.1.

This is a code example that works for me:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.44.1"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_automation_variable_string" "test_variable" {
  name                     = "my_variable#test"
  resource_group_name      = "test-rg"
  automation_account_name  = "testaccount"
  value                    = "test_value"
}

@wuxu92
Copy link
Contributor

wuxu92 commented Jun 14, 2023

@kandelk PR #20568 moved to a new SDK version with a different logic from the old Azure SDK. Is this required feature to support # in a variable name, because it's not supported in the Azure Portal either, I guess AzureRM should not keep it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants