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

Add host attribute for endpoints of blob, table, queue, and file. #2792

Merged
merged 8 commits into from
Feb 28, 2019
78 changes: 49 additions & 29 deletions azurerm/data_source_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,72 @@ func dataSourceArmStorageAccount() *schema.Resource {
Computed: true,
},

"primary_blob_host": {
Type: schema.TypeString,
Computed: true,
},

"secondary_blob_endpoint": {
Type: schema.TypeString,
Computed: true,
},

"secondary_blob_host": {
Type: schema.TypeString,
Computed: true,
},

"primary_queue_endpoint": {
Type: schema.TypeString,
Computed: true,
},

"primary_queue_host": {
Type: schema.TypeString,
Computed: true,
},

"secondary_queue_endpoint": {
Type: schema.TypeString,
Computed: true,
},

"secondary_queue_host": {
Type: schema.TypeString,
Computed: true,
},

"primary_table_endpoint": {
Type: schema.TypeString,
Computed: true,
},

"primary_table_host": {
Type: schema.TypeString,
Computed: true,
},

"secondary_table_endpoint": {
Type: schema.TypeString,
Computed: true,
},

"secondary_table_host": {
Type: schema.TypeString,
Computed: true,
},

// NOTE: The API does not appear to expose a secondary file endpoint
"primary_file_endpoint": {
Type: schema.TypeString,
Computed: true,
},

"primary_file_host": {
Type: schema.TypeString,
Computed: true,
},

"primary_access_key": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -234,40 +269,25 @@ func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) e
d.Set("secondary_connection_string", scs)
}

if endpoints := props.PrimaryEndpoints; endpoints != nil {
d.Set("primary_blob_endpoint", endpoints.Blob)
d.Set("primary_queue_endpoint", endpoints.Queue)
d.Set("primary_table_endpoint", endpoints.Table)
d.Set("primary_file_endpoint", endpoints.File)

pscs := fmt.Sprintf("DefaultEndpointsProtocol=https;BlobEndpoint=%s;AccountName=%s;AccountKey=%s",
*endpoints.Blob, *resp.Name, *accessKeys[0].Value)
d.Set("primary_blob_connection_string", pscs)
if err := flattenAndSetAzureRmStorageAccountPrimaryEndpoints(d, props.PrimaryEndpoints); err != nil {
return fmt.Errorf("error setting primary endpoints and hosts for blob, queue, table and file: %+v", err)
}

if endpoints := props.SecondaryEndpoints; endpoints != nil {
if blob := endpoints.Blob; blob != nil {
d.Set("secondary_blob_endpoint", blob)
sscs := fmt.Sprintf("DefaultEndpointsProtocol=https;BlobEndpoint=%s;AccountName=%s;AccountKey=%s",
*blob, *resp.Name, *accessKeys[1].Value)
d.Set("secondary_blob_connection_string", sscs)
} else {
d.Set("secondary_blob_endpoint", "")
d.Set("secondary_blob_connection_string", "")
}
var primaryBlobConnectStr string
if v := props.PrimaryEndpoints; v != nil {
primaryBlobConnectStr = getBlobConnectionString(v.Blob, resp.Name, accessKeys[0].Value)
}
d.Set("primary_blob_connection_string", primaryBlobConnectStr)

if endpoints.Queue != nil {
d.Set("secondary_queue_endpoint", endpoints.Queue)
} else {
d.Set("secondary_queue_endpoint", "")
}
if err := flattenAndSetAzureRmStorageAccountSecondaryEndpoints(d, props.SecondaryEndpoints); err != nil {
return fmt.Errorf("error setting secondary endpoints and hosts for blob, queue, table: %+v", err)
}

if endpoints.Table != nil {
d.Set("secondary_table_endpoint", endpoints.Table)
} else {
d.Set("secondary_table_endpoint", "")
}
var secondaryBlobConnectStr string
if v := props.SecondaryEndpoints; v != nil {
secondaryBlobConnectStr = getBlobConnectionString(v.Blob, resp.Name, accessKeys[1].Value)
}
d.Set("secondary_blob_connection_string", secondaryBlobConnectStr)
}

d.Set("primary_access_key", accessKeys[0].Value)
Expand Down
Loading