-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Data block working inconsistently when 'count' and 'provider' arguments are used together #31181
Comments
Hello, Thanks for this request! This ticket seems very similar to #16967 -- do you think this is essentially the same issue? If so, we can close this as a duplicate and repost your comment on that issue. You might also have some luck asking this question on the community forum where there are more people ready to help. The GitHub issues here are monitored only by a few core maintainers. If this helps, there are also a few similar or adjacent issues that may help. Similar: Adjacent: Thanks! |
hi @crw thanks for your response. I went through the issues you have shared but I think this one is not related to them. Can you please suggest me a way to make this script work for 2 different provider configurations with data block referring the correct provider configuration based on the value passed by the application/user? |
Unfortunately the way terraform is designed, the You might be able to work around this by abusing the behavior of the provider which (I think) will ignore the configuration values if they're null. You can try something like this to make the provider config conditional on the same value as the data source:
A more general solution would have to come from the resolution of one or more of the issues linked above (most directly #19932). Since we already have enhancement requests for more dynamic provider configuration, I'm going to close this out and we can follows the other for updates in the situation. Thanks! |
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. |
Problem description -
We have 2 provider configuration defined in the same script and want to execute a data block with particular provider based on the 'count' conditional expression. While the data block behaves normally when only the 'count' argument is used, when an additional argument of provider is added, it tries to read the provider configuration even if the condition turns out to be false. Question here is, if the condition is false, why the data block needs to execute the provider block?
Terraform Version
Terraform Configuration Files
Note: local.tenant variable gets resolved to "SHS" here.
Debug Output
terraform apply --auto-approve
│ Error: building account: getting authenticated object ID: listing Service Principals: ServicePrincipalsClient.BaseClient.Get(): clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_request","error_description":"AADSTS90002: Tenant 'xxxxx-xxxxx-xxxxx-xxxxx-xxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant.\r\nTrace ID: e36ac19c-09d3-417e-a5e0-aa09e99a3801\r\nCorrelation ID: 07b73f82-8cef-484e-bdf3-fccc382d68e5\r\nTimestamp: 2022-06-02 13:01:53Z","error_codes":[90002],"timestamp":"2022-06-02 13:01:53Z","trace_id":"e36ac19c-09d3-417e-a5e0-aa09e99a3801","correlation_id":"07b73f82-8cef-484e-bdf3-fccc382d68e5","error_uri":"https://login.chinacloudapi.cn/error?code=90002"}
│
│ with provider["registry.terraform.io/hashicorp/azurerm"].china,
│ on main.tf line 34, in provider "azurerm":
│ 34: provider "azurerm" {
Expected Behavior
terraform should have skipped executing the data block with the provider argument.
Actual Behavior
data block is getting executed and provider block is getting called.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: