hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

Starting with 3.0 key vault secrets data resource is attempting to use an invalid URL #16291

Closed monster-cookie closed 2 years ago

monster-cookie commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.1.7

AzureRM Provider Version

3.0.2

Affected Resource(s)/Data Source(s)

azurerm_key_vault_secret

Terraform Configuration Files

data "azurerm_resource_group" "Shared" {
  name = "Shared"
}

data "azurerm_key_vault" "v4secrets-global" {
  name                = "v4secrets-global"
  resource_group_name = data.azurerm_resource_group.Shared.name
}

data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineAdminUsername" {
  name         = "AdminAccounts-MachineAdminUsername"
  key_vault_id = data.azurerm_key_vault.v4secrets-global.id
}

Debug Output/Panic Output

2022-04-07T10:21:54.477-0600 [TRACE] provider.terraform-provider-azurerm_v3.0.2_x5: Called downstream: tf_proto_version=5 tf_provider_addr=provider tf_rpc=ReadDataSource @caller=/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:483 @module=sdk.proto tf_data_source_type=azurerm_key_vault_secret tf_req_id=ca1b7232-f5ef-f5ff-faec-df7da066ef48 timestamp=2022-04-07T10:21:54.476-0600
2022-04-07T10:21:54.477-0600 [TRACE] provider.terraform-provider-azurerm_v3.0.2_x5: Served request: tf_proto_version=5 tf_rpc=ReadDataSource @caller=/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:489 @module=sdk.proto tf_data_source_type=azurerm_key_vault_secret tf_provider_addr=provider tf_req_id=ca1b7232-f5ef-f5ff-faec-df7da066ef48 timestamp=2022-04-07T10:21:54.476-0600
2022-04-07T10:21:54.477-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminUsername: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: e2edb45b-db3e-460a-87be-3ad146675200\r\nCorrelation ID: 8709a1a1-3279-49a8-b91f-39ea398b9b79\r\nTimestamp: 2022-04-07 16:17:53Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:53Z","trace_id":"e2edb45b-db3e-460a-87be-3ad146675200","correlation_id":"8709a1a1-3279-49a8-b91f-39ea398b9b79","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.477-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername": visit complete, with errors
2022-04-07T10:21:54.477-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername": dynamic subgraph encountered errors: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminUsername: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: e2edb45b-db3e-460a-87be-3ad146675200\r\nCorrelation ID: 8709a1a1-3279-49a8-b91f-39ea398b9b79\r\nTimestamp: 2022-04-07 16:17:53Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:53Z","trace_id":"e2edb45b-db3e-460a-87be-3ad146675200","correlation_id":"8709a1a1-3279-49a8-b91f-39ea398b9b79","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.477-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminUsername: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: e2edb45b-db3e-460a-87be-3ad146675200\r\nCorrelation ID: 8709a1a1-3279-49a8-b91f-39ea398b9b79\r\nTimestamp: 2022-04-07 16:17:53Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:53Z","trace_id":"e2edb45b-db3e-460a-87be-3ad146675200","correlation_id":"8709a1a1-3279-49a8-b91f-39ea398b9b79","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.477-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername": visit complete, with errors
2022-04-07T10:21:54.477-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername (expand)": dynamic subgraph encountered errors: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminUsername: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: e2edb45b-db3e-460a-87be-3ad146675200\r\nCorrelation ID: 8709a1a1-3279-49a8-b91f-39ea398b9b79\r\nTimestamp: 2022-04-07 16:17:53Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:53Z","trace_id":"e2edb45b-db3e-460a-87be-3ad146675200","correlation_id":"8709a1a1-3279-49a8-b91f-39ea398b9b79","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.477-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername (expand)" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminUsername: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: e2edb45b-db3e-460a-87be-3ad146675200\r\nCorrelation ID: 8709a1a1-3279-49a8-b91f-39ea398b9b79\r\nTimestamp: 2022-04-07 16:17:53Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:53Z","trace_id":"e2edb45b-db3e-460a-87be-3ad146675200","correlation_id":"8709a1a1-3279-49a8-b91f-39ea398b9b79","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.477-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername (expand)": visit complete, with errors
2022-04-07T10:21:54.658-0600 [TRACE] provider.terraform-provider-azurerm_v3.0.2_x5: Called downstream: tf_proto_version=5 tf_provider_addr=provider tf_req_id=d304fb4f-e876-cbe5-0840-97e946ed0f02 @caller=/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:483 @module=sdk.proto tf_data_source_type=azurerm_key_vault_secret tf_rpc=ReadDataSource timestamp=2022-04-07T10:21:54.658-0600
2022-04-07T10:21:54.658-0600 [TRACE] provider.terraform-provider-azurerm_v3.0.2_x5: Served request: tf_req_id=d304fb4f-e876-cbe5-0840-97e946ed0f02 tf_data_source_type=azurerm_key_vault_secret tf_proto_version=5 tf_provider_addr=provider tf_rpc=ReadDataSource @caller=/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:489 @module=sdk.proto timestamp=2022-04-07T10:21:54.658-0600
2022-04-07T10:21:54.659-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminPassword: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: b8e9d945-2b79-4600-96ae-cbd1b2995c00\r\nCorrelation ID: 2b9fb223-7961-4db1-8c2c-bf5dc0252458\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"b8e9d945-2b79-4600-96ae-cbd1b2995c00","correlation_id":"2b9fb223-7961-4db1-8c2c-bf5dc0252458","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.659-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword": visit complete, with errors
2022-04-07T10:21:54.659-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword": dynamic subgraph encountered errors: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminPassword: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: b8e9d945-2b79-4600-96ae-cbd1b2995c00\r\nCorrelation ID: 2b9fb223-7961-4db1-8c2c-bf5dc0252458\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"b8e9d945-2b79-4600-96ae-cbd1b2995c00","correlation_id":"2b9fb223-7961-4db1-8c2c-bf5dc0252458","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.659-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminPassword: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: b8e9d945-2b79-4600-96ae-cbd1b2995c00\r\nCorrelation ID: 2b9fb223-7961-4db1-8c2c-bf5dc0252458\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"b8e9d945-2b79-4600-96ae-cbd1b2995c00","correlation_id":"2b9fb223-7961-4db1-8c2c-bf5dc0252458","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.659-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword": visit complete, with errors
2022-04-07T10:21:54.659-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword (expand)": dynamic subgraph encountered errors: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminPassword: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: b8e9d945-2b79-4600-96ae-cbd1b2995c00\r\nCorrelation ID: 2b9fb223-7961-4db1-8c2c-bf5dc0252458\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"b8e9d945-2b79-4600-96ae-cbd1b2995c00","correlation_id":"2b9fb223-7961-4db1-8c2c-bf5dc0252458","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.659-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword (expand)" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminPassword: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: b8e9d945-2b79-4600-96ae-cbd1b2995c00\r\nCorrelation ID: 2b9fb223-7961-4db1-8c2c-bf5dc0252458\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"b8e9d945-2b79-4600-96ae-cbd1b2995c00","correlation_id":"2b9fb223-7961-4db1-8c2c-bf5dc0252458","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.659-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword (expand)": visit complete, with errors
2022-04-07T10:21:54.659-0600 [TRACE] dag/walk: upstream of "azurerm_linux_virtual_machine.dnsproxy (expand)" errored, so skipping
2022-04-07T10:21:54.659-0600 [TRACE] dag/walk: upstream of "azurerm_virtual_machine_extension.dnsproxy-extenstion-dependencyagent (expand)" errored, so skipping
2022-04-07T10:21:54.659-0600 [TRACE] dag/walk: upstream of "azurerm_virtual_machine_extension.dnsproxy-extenstion-adlogin (expand)" errored, so skipping
2022-04-07T10:21:54.659-0600 [TRACE] dag/walk: upstream of "azurerm_backup_protected_vm.backups_dnsproxy (expand)" errored, so skipping
2022-04-07T10:21:54.659-0600 [TRACE] dag/walk: upstream of "azurerm_virtual_machine_extension.dnsproxy-extenstion-omsagent (expand)" errored, so skipping
2022-04-07T10:21:54.826-0600 [TRACE] provider.terraform-provider-azurerm_v3.0.2_x5: Called downstream: tf_data_source_type=azurerm_key_vault_secret tf_provider_addr=provider tf_req_id=501f2e90-6358-6c3b-9f53-bddf22291942 @caller=/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:483 @module=sdk.proto tf_proto_version=5 tf_rpc=ReadDataSource timestamp=2022-04-07T10:21:54.826-0600
2022-04-07T10:21:54.826-0600 [TRACE] provider.terraform-provider-azurerm_v3.0.2_x5: Served request: @caller=/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:489 tf_req_id=501f2e90-6358-6c3b-9f53-bddf22291942 tf_rpc=ReadDataSource @module=sdk.proto tf_data_source_type=azurerm_key_vault_secret tf_proto_version=5 tf_provider_addr=provider timestamp=2022-04-07T10:21:54.826-0600
2022-04-07T10:21:54.826-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineSSHPublic: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: efafe097-6965-4a33-b1c8-9b0eb6675200\r\nCorrelation ID: 651a4826-0103-49a9-9856-f75dddee6004\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"efafe097-6965-4a33-b1c8-9b0eb6675200","correlation_id":"651a4826-0103-49a9-9856-f75dddee6004","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.826-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic": visit complete, with errors
2022-04-07T10:21:54.826-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic": dynamic subgraph encountered errors: making Read request on Azure KeyVault Secret AdminAccounts-MachineSSHPublic: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: efafe097-6965-4a33-b1c8-9b0eb6675200\r\nCorrelation ID: 651a4826-0103-49a9-9856-f75dddee6004\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"efafe097-6965-4a33-b1c8-9b0eb6675200","correlation_id":"651a4826-0103-49a9-9856-f75dddee6004","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.826-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineSSHPublic: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: efafe097-6965-4a33-b1c8-9b0eb6675200\r\nCorrelation ID: 651a4826-0103-49a9-9856-f75dddee6004\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"efafe097-6965-4a33-b1c8-9b0eb6675200","correlation_id":"651a4826-0103-49a9-9856-f75dddee6004","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.826-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic": visit complete, with errors
2022-04-07T10:21:54.826-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic (expand)": dynamic subgraph encountered errors: making Read request on Azure KeyVault Secret AdminAccounts-MachineSSHPublic: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: efafe097-6965-4a33-b1c8-9b0eb6675200\r\nCorrelation ID: 651a4826-0103-49a9-9856-f75dddee6004\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"efafe097-6965-4a33-b1c8-9b0eb6675200","correlation_id":"651a4826-0103-49a9-9856-f75dddee6004","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.826-0600 [ERROR] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic (expand)" error: making Read request on Azure KeyVault Secret AdminAccounts-MachineSSHPublic: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: efafe097-6965-4a33-b1c8-9b0eb6675200\r\nCorrelation ID: 651a4826-0103-49a9-9856-f75dddee6004\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"efafe097-6965-4a33-b1c8-9b0eb6675200","correlation_id":"651a4826-0103-49a9-9856-f75dddee6004","error_uri":"https://login.microsoftonline.us/error?code=500011"}
2022-04-07T10:21:54.826-0600 [TRACE] vertex "data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic (expand)": visit complete, with errors
2022-04-07T10:21:54.826-0600 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/hashicorp/azurerm\"] (close)" errored, so skipping
2022-04-07T10:21:54.826-0600 [TRACE] dag/walk: upstream of "root" errored, so skipping
2022-04-07T10:21:54.827-0600 [TRACE] LoadSchemas: retrieving schema for provider type "registry.terraform.io/hashicorp/azurerm"
2022-04-07T10:21:54.830-0600 [INFO]  backend/local: plan operation completed
╷
│ Error: Failed to decode resource from state
│
│ Error decoding "azurerm_backup_protected_vm.backups_dnsproxy" from previous state: unsupported attribute "tags"
╵
╷
│ Error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminUsername: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: e2edb45b-db3e-460a-87be-3ad146675200\r\nCorrelation ID: 8709a1a1-3279-49a8-b91f-39ea398b9b79\r\nTimestamp: 2022-04-07 16:17:53Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:53Z","trace_id":"e2edb45b-db3e-460a-87be-3ad146675200","correlation_id":"8709a1a1-3279-49a8-b91f-39ea398b9b79","error_uri":"https://login.microsoftonline.us/error?code=500011"}
│
│   with data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminUsername,
│   on variables.tf line 145, in data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineAdminUsername":
│  145: data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineAdminUsername" {
│
╵
╷
│ Error: making Read request on Azure KeyVault Secret AdminAccounts-MachineAdminPassword: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: b8e9d945-2b79-4600-96ae-cbd1b2995c00\r\nCorrelation ID: 2b9fb223-7961-4db1-8c2c-bf5dc0252458\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"b8e9d945-2b79-4600-96ae-cbd1b2995c00","correlation_id":"2b9fb223-7961-4db1-8c2c-bf5dc0252458","error_uri":"https://login.microsoftonline.us/error?code=500011"}
│
│   with data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineAdminPassword,
│   on variables.tf line 150, in data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineAdminPassword":
│  150: data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineAdminPassword" {
│
╵
╷
│ Error: making Read request on Azure KeyVault Secret AdminAccounts-MachineSSHPublic: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: obtaining token: clientCredentialsToken: received HTTP status 400 with response: {"error":"invalid_resource","error_description":"AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named [REDACTED-TenantName]. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: efafe097-6965-4a33-b1c8-9b0eb6675200\r\nCorrelation ID: 651a4826-0103-49a9-9856-f75dddee6004\r\nTimestamp: 2022-04-07 16:17:54Z","error_codes":[500011],"timestamp":"2022-04-07 16:17:54Z","trace_id":"efafe097-6965-4a33-b1c8-9b0eb6675200","correlation_id":"651a4826-0103-49a9-9856-f75dddee6004","error_uri":"https://login.microsoftonline.us/error?code=500011"}
│
│   with data.azurerm_key_vault_secret.AZKV-Global-AdminAccounts-MachineSSHPublic,
│   on variables.tf line 155, in data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineSSHPublic":
│  155: data "azurerm_key_vault_secret" "AZKV-Global-AdminAccounts-MachineSSHPublic" {
│
╵

Expected Behaviour

Pull and create variable for the secret

Actual Behaviour

Request fails by trying to access an invalid URL https://vault.microsoftazure.us. This URL is not in our state, definition files, or azure account. It should also be noted that the apply/plan hangs for 10-60 minutes before failing. It should also be noted this exact code works fine with 2.99.0

image

Steps to Reproduce

Run terraform plan or terraform apply

Important Factoids

We are in Azure Government

References

No response

jaydesai-automate commented 2 years ago

In my case, similar behavior. Hangs for 5 mins then spits out an error. This is when you run a Plan. If you slip over to version 2.99.0 It does not give any error.

Error: retrievingcontactfor KeyVault: keyvault.BaseClient#GetCertificateContacts: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded

nbjohnson commented 2 years ago

I also have a similar issue, but not sure if it is the same exact one. On v2.99 my keyvault and secret lookups work fine, but on any v3 my keyvault lookups work fine but any secret lookups from those vaults hang for 5-10 min and timeout with the following error:

Error: making Read request on Azure KeyVault Secret <secret name>: autorest/Client#Do: Preparing request failed: StatusCode=0 -- Original Error: failed to acquire MSAL token

I am using CLI auth.

There was another thread where other people were having keyvault issues and seems some of the problems were fixed but mine weren't and seems like there is still an issue if the above issues are anything to go by: https://github.com/hashicorp/terraform-provider-azurerm/issues/16052

monster-cookie commented 2 years ago

In my case I'm using service principal auth for everything

tombuildsstuff commented 2 years ago

hi @monster-cookie

Thanks for opening this issue.

Taking a look through here this isn't trying to access the URI, it's trying to gain an access token for that URI, which is necessary in order to access the Key Vault within this Environment. As a part of 3.0 we've switched from using ADAL to MSAL, more information on the changes can be found here - https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-migration - and whilst the Key Vault Application should be enabled by default, it'd be worth confirming if it's registered for the Service Principal that you're using here?

The other two comments above are unrelated and are associated with #16052 - so I've marked those as off-topic, but in that case please subscribe to/keep that discussion within that issue so that we're not conflating two different issues here.

Thanks!

monster-cookie commented 2 years ago

@tombuildsstuff my problem with this is the URL https://vault.microsoftazure.us/ isn't in our state, definition files, or azure gov portal. It also doesn't appear to exist in DNS. If its a generic REST API for Azure Gov Vault then its not supported in azure gov yet which is very possible because Azure Gov lags behind Azure Public by 3-6 months and Azure DoD by 1-2 years. The URL that should be being used for those secrets data resources is https://v4secrets-global.vault.usgovcloudapi.net/.

tombuildsstuff commented 2 years ago

@monster-cookie the URI doesn't exist, it's used as the Resource when requesting a Resource Manager Authentication Token from MS Graph to access Key Vault - the returned token can then be used to access whichever key vault is necessary.

As mentioned above, you'd need to confirm if the Service Principal being used has MSAL access to Key Vault (in Azure Active Directory) - but @manicminer should be able to confirm if there's anything extra needed here?

monster-cookie commented 2 years ago

I just went through all the settings for the app and service principal, and it should have full access to the graph APIs. I've been trying to find docs for any special settings/permissions needed for MSAL but mostly it seems to match what ADAL needed. I should not with AzureRM 3.1.0 I now get the certificate error from the other ticket #16052

monster-cookie commented 2 years ago

image

sorry the image didn't upload/link

monster-cookie commented 2 years ago

Here is the updated debug logs for 3.1.0

2022-04-08T11:22:00.196-0600 [ERROR] vertex "azurerm_key_vault.v4secrets-global" error: retrieving contact for KeyVault: keyvault.BaseClient#GetCertificateContacts: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded 2022-04-08T11:22:00.196-0600 [TRACE] vertex "azurerm_key_vault.v4secrets-global": visit complete, with errors 2022-04-08T11:22:00.197-0600 [TRACE] vertex "azurerm_key_vault.v4secrets-global": dynamic subgraph encountered errors: retrieving contact for KeyVault: keyvault.BaseClient#GetCertificateContacts: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded 2022-04-08T11:22:00.197-0600 [ERROR] vertex "azurerm_key_vault.v4secrets-global" error: retrieving contact for KeyVault: keyvault.BaseClient#GetCertificateContacts: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded 2022-04-08T11:22:00.197-0600 [TRACE] vertex "azurerm_key_vault.v4secrets-global": visit complete, with errors 2022-04-08T11:22:00.197-0600 [TRACE] vertex "azurerm_key_vault.v4secrets-global (expand)": dynamic subgraph encountered errors: retrieving contact for KeyVault: keyvault.BaseClient#GetCertificateContacts: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded 2022-04-08T11:22:00.197-0600 [ERROR] vertex "azurerm_key_vault.v4secrets-global (expand)" error: retrieving contact for KeyVault: keyvault.BaseClient#GetCertificateContacts: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded 2022-04-08T11:22:00.197-0600 [TRACE] vertex "azurerm_key_vault.v4secrets-global (expand)": visit complete, with errors 2022-04-08T11:22:00.197-0600 [TRACE] dag/walk: upstream of "azurerm_monitor_diagnostic_setting.v4secrets-global-log-diags (expand)" errored, so skipping

adamday2 commented 2 years ago

We're running into the same issue on Azure Government, running from an Azure AD account, no SPs involved.

As a point of reference, that resource URI also does not work for us with the Azure CLI. When I try to retrieve an access token for https://vault.microsoftazure.us, I get the same error as noted in the original post:

az account get-access-token --resource https://vault.microsoftazure.us

AADSTS500011: The resource principal named https://vault.microsoftazure.us was not found in the tenant named <tenant name here>. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.

But I can successfully retrieve a token from https://vault.azure.net

az account get-access-token --resource https://vault.azure.net

{
  "accessToken": "<token here>",
  "expiresOn": -
  "subscription": -
  "tenant": -
  "tokenType": "Bearer"
}
az cloud show | grep name
  "name": "AzureUSGovernment",

Is there any possibility that the vault uri is not region-specific?

monster-cookie commented 2 years ago

You can get a token from https://vault.usgovcloudapi.net also which matches the normal azure gov api end point replacements

{ "accessToken": "[REDACTED]", "expiresOn": "2022-04-08 12:42:43.000000", "subscription": "12160f2c-3952-419c-a854-c8d76d988909", "tenant": "0b50b1fa-3c16-4c29-a5cb-d4bb4d1db625", "tokenType": "Bearer" }

adamday2 commented 2 years ago

This seems like it could very likely be an issue with the underlying endpoint reference. I'm not very familiar with this codebase, but I think its relying on https://github.com/manicminer/hamilton/blob/main/environments/endpoints.go#L36

If that's the case, the URI appears to be a copy/paste from Germany, with a suffix change, so it seems quite possible that this is just an incorrect endpoint being referenced for gov: https://github.com/manicminer/hamilton/commit/948b9fe8eab9a755d28697bd4396d1fe6945354e

nbjohnson commented 2 years ago

Is there any update on this issue? The above post might be the issue: https://github.com/manicminer/hamilton/blob/main/environments/endpoints.go#L36

As that repository is imported: https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/clients/builder.go#L16 and it looks like our environments are built on those endpoints: https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/clients/builder.go#L61

The usgov keyvault api endpoint listed in that repo exactly matches the endpoint that doesn't seem to work, so I think that is what needs to be updated to https://vault.usgovcloudapi.net/

manicminer commented 2 years ago

@monster-cookie, @adamday2 Thanks for the report and investigation. You are correct, the App ID URI for Vault in USGovernment is incorrect in the hamilton/environments package. We'll have a fix out for this in the next release - apologies it didn't make it into this week's release.

monster-cookie commented 2 years ago

Cool thanks for the work in getting it ready. I look forward to testing when it releases.

github-actions[bot] commented 2 years ago

This functionality has been released in v3.3.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!

monster-cookie commented 2 years ago

I can confirm this is working for me in azure gov now

github-actions[bot] commented 2 years ago

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.