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

Hardcoded blob.core.windows.net makes azurerm not work in China (proably Germany and Government environments too) #11136

Closed
nicocesar opened this issue Jan 10, 2017 · 6 comments · Fixed by #11159

Comments

@nicocesar
Copy link

nicocesar commented Jan 10, 2017

Terraform Version

Terraform v0.8.4-dev (6bafd4c+CHANGES)

(modified version with patch published in #11131)

Affected Resource(s)

resource_azure_instance
resource_azure_data_disk

Terraform Configuration Files

https://www.dropbox.com/s/ij7u77i37mvwbb1/invalid_character_error.zip?dl=0
(same as #11131)

Debug Output

2017/01/11 14:09:10 [DEBUG] apply: azurerm_storage_container.vhds: executing Apply
azurerm_storage_container.vhds: Creating...
  container_access_type: "" => "private"
  name:                  "" => "vhds"
  properties.%:          "" => "<computed>"
  resource_group_name:   "" => "d8kp5"
  storage_account_name:  "" => "curoversed8kp5"
2017/01/11 14:09:10 [DEBUG] plugin: terraform: azurerm-provider (internal) 2017/01/11 14:09:10 [DEBUG] AzureRM Request:
2017/01/11 14:09:10 [DEBUG] plugin: terraform: POST /subscriptions/c1d7e503-faf6-4a7e-829a-bc27898c09ac/resourceGroups/d8kp5/providers/Microsoft.Storage/storageAccounts/curoversed8kp5/listKeys?api-version=2016-01-01 HTTP/1.1
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Host: management.chinacloudapi.cn
2017/01/11 14:09:10 [DEBUG] plugin: terraform: User-Agent: HashiCorp-Terraform-v0.8.4-dev
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Content-Length: 0
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Authorization: Bearer e..w
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Accept-Encoding: gzip
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 
2017/01/11 14:09:10 [DEBUG] plugin: terraform: azurerm-provider (internal) 2017/01/11 14:09:10 [DEBUG] AzureRM Response for https://management.chinacloudapi.cn/subscriptions/c..c/resourceGroups/d8kp5/providers/Microsoft.Storage/storageAccounts/curoversed8kp5/listKeys?api-version=2016-01-01:
2017/01/11 14:09:10 [DEBUG] plugin: terraform: HTTP/1.1 200 OK
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Transfer-Encoding: chunked
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Cache-Control: no-cache
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Content-Type: application/json
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Date: Wed, 11 Jan 2017 14:09:10 GMT
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Expires: -1
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Pragma: no-cache
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Server: Microsoft-Azure-Storage-Resource-Provider/1.0
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Server: Microsoft-HTTPAPI/2.0
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Strict-Transport-Security: max-age=31536000; includeSubDomains
2017/01/11 14:09:10 [DEBUG] plugin: terraform: Vary: Accept-Encoding
2017/01/11 14:09:10 [DEBUG] plugin: terraform: X-Ms-Correlation-Request-Id: 2407d66b-7331-49d7-8b00-7e7027992956
2017/01/11 14:09:10 [DEBUG] plugin: terraform: X-Ms-Ratelimit-Remaining-Subscription-Writes: 1196
2017/01/11 14:09:10 [DEBUG] plugin: terraform: X-Ms-Request-Id: 2407..956
2017/01/11 14:09:10 [DEBUG] plugin: terraform: X-Ms-Routing-Request-Id: CHINAEAST:20170111T140910Z:240..956
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 121
2017/01/11 14:09:10 [DEBUG] plugin: terraform: {"keys":...}
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 0
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 
2017/01/11 14:09:10 [DEBUG] plugin: terraform: 
2017/01/11 14:09:10 [DEBUG] plugin: terraform: azurerm-provider (internal) 2017/01/11 14:09:10 [INFO] Creating container "vhds" in storage account "curoversed8kp5".
2017/01/11 14:09:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/11 14:09:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/11 14:09:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/11 14:09:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/11 14:09:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/11 14:09:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/11 14:09:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* azurerm_storage_container.vhds: Error creating container "vhds" in storage account "curoversed8kp5": Put https://curoversed8kp5.blob.core.windows.net/vhds?restype=container: dial tcp: lookup curoversed8kp5.blob.core.windows.net on 172.16.0.23:53: no such host
2017/01/11 14:09:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* azurerm_storage_container.vhds: Error creating container "vhds" in storage account "curoversed8kp5": Put https://curoversed8kp5.blob.core.windows.net/vhds?restype=container: dial tcp: lookup curoversed8kp5.blob.core.windows.net on 172.16.0.23:53: no such host


Error applying plan:

1 error(s) occurred:

* azurerm_storage_container.vhds: Error creating container "vhds" in storage account "curoversed8kp5": Put https://curoversed8kp5.blob.core.windows.net/vhds?restype=container: dial tcp: lookup curoversed8kp5.blob.core.windows.net on 172.16.0.23:53: no such host

Expected Behavior

create a disk in the corresponding endpoint for china

Actual Behavior

how is azurerm_storage_account.storage.primary_blob_endpoint being used? I'm getting blob.core.windows.net But actually is blob.core.chinacloudapi.cn:

azure account env show AzureChinaCloud
(..)
data: storageEndpointSuffix: .core.chinacloudapi.cn

Steps to Reproduce

terraform apply -state mystate.tfstate -var-file invalid_character_error.tfvars -target=azurerm_virtual_machine.api

Important Factoids

builtin/providers/azurerm/resource_arm_virtual_machine.go:      // VHD URI is in the form: https://storageAccountName.blob.core.windows.net/containerName/blobName
builtin/providers/azure/resource_azure_instance.go:     osDiskBlobStorageURL  = "http://%s.blob.core.windows.net/" + storageContainterName + "/" + osDiskBlobNameFormat
builtin/providers/azure/resource_azure_data_disk.go:const dataDiskBlobStorageURL = "http://%s.blob.core.windows.net/disks/%s.vhd"

@nicocesar
Copy link
Author

besides that seems like the external library has some other things hardcoded https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L24

@nicocesar
Copy link
Author

this patch solved my problem.

diff --git a/vendor/github.com/Azure/azure-sdk-for-go/storage/client.go b/vendor/github.com/Azure/azure-sdk-for-go/storage/client.go
index 7752851..5967400 100644
--- a/vendor/github.com/Azure/azure-sdk-for-go/storage/client.go
+++ b/vendor/github.com/Azure/azure-sdk-for-go/storage/client.go
@@ -21,7 +21,7 @@ import (
 const (
        // DefaultBaseURL is the domain name used for storage requests when a
        // default client is created.
-       DefaultBaseURL = "core.windows.net"
+       DefaultBaseURL = "core.chinacloudapi.cn"
 
        // DefaultAPIVersion is the  Azure Storage API version string used when a
        // basic client is created.

but again, looks like azure-sdk-for-go isn't multi-environment ready

@pmcatominey
Copy link
Contributor

@nicocesar seems that I missed the storage service clients when adding multi-environment support, the SDK exposes a method for overriding the service url, I'll have a look at this soon.

@nicocesar
Copy link
Author

@pmcatominey is this related to the NewBasicClient created here : https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L124-L132 ?

@pmcatominey
Copy link
Contributor

@nicocesar yep, we'll need to switch to the NewClient method below and pass in the correct service url which we get from the environment

@ghost
Copy link

ghost commented Apr 18, 2020

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.

@hashicorp hashicorp locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants