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
70 changes: 39 additions & 31 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,39 +269,12 @@ 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 := flattenAzureRmStorageAccountPrimaryEndpoints(d, props.PrimaryEndpoints, resp.Name, accessKeys[0].Value); 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", "")
}

if endpoints.Queue != nil {
d.Set("secondary_queue_endpoint", endpoints.Queue)
} else {
d.Set("secondary_queue_endpoint", "")
}

if endpoints.Table != nil {
d.Set("secondary_table_endpoint", endpoints.Table)
} else {
d.Set("secondary_table_endpoint", "")
}
if err := flattenAzureRmStorageAccountSecondaryEndpoints(d, props.SecondaryEndpoints, resp.Name, accessKeys[1].Value); err != nil {
return fmt.Errorf("error setting secondary endpoints and hosts for blob, queue, table: %+v", err)
}
}

Expand Down
192 changes: 161 additions & 31 deletions azurerm/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/hashicorp/go-getter/helper/url"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
Expand Down Expand Up @@ -195,37 +196,72 @@ func resourceArmStorageAccount() *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,
Sensitive: true,
Expand Down Expand Up @@ -662,39 +698,12 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
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 := flattenAzureRmStorageAccountPrimaryEndpoints(d, props.PrimaryEndpoints, resp.Name, accessKeys[0].Value); err != nil {
metacpp marked this conversation as resolved.
Show resolved Hide resolved
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", "")
}

if endpoints.Queue != nil {
d.Set("secondary_queue_endpoint", endpoints.Queue)
} else {
d.Set("secondary_queue_endpoint", "")
}

if endpoints.Table != nil {
d.Set("secondary_table_endpoint", endpoints.Table)
} else {
d.Set("secondary_table_endpoint", "")
}
if err := flattenAzureRmStorageAccountSecondaryEndpoints(d, props.SecondaryEndpoints, resp.Name, accessKeys[1].Value); err != nil {
return fmt.Errorf("error setting secondary endpoints and hosts for blob, queue, table: %+v", err)
}

networkRules := props.NetworkRuleSet
Expand Down Expand Up @@ -963,3 +972,124 @@ func flattenAzureRmStorageAccountIdentity(identity *storage.Identity) []interfac

return []interface{}{result}
}

func flattenAzureRmStorageAccountPrimaryEndpoints(d *schema.ResourceData, primary *storage.Endpoints, acctName *string, acctKey *string) error {
metacpp marked this conversation as resolved.
Show resolved Hide resolved
if primary == nil {
metacpp marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("primary endpoints should not be empty")
}

if acctName == nil {
return fmt.Errorf("account name should not be nil")
}

if acctKey == nil {
return fmt.Errorf("account key should not be nil")
}

var blobEndpoint, blobHost, blobConnectionStr string
if v := primary.Blob; v != nil {
blobEndpoint = *v

if u, err := url.Parse(*v); err != nil {
blobHost = u.Host
} else {
return fmt.Errorf("invalid blob endpoint for parsing: %q", *v)
}

blobConnectionStr = fmt.Sprintf("DefaultEndpointsProtocol=https;BlobEndpoint=%s;AccountName=%s;AccountKey=%s", blobEndpoint, *acctName, *acctKey)
}
d.Set("primary_blob_endpoint", blobEndpoint)
d.Set("primary_blob_host", blobHost)
d.Set("primary_blob_connection_string", blobConnectionStr)

var queueEndpoint, queueHost string
if v := primary.Queue; v != nil {
queueEndpoint = *v

if u, err := url.Parse(*v); err != nil {
queueHost = u.Host
metacpp marked this conversation as resolved.
Show resolved Hide resolved
} else {
return fmt.Errorf("invalid queue endpoint for parsing: %q", *v)
}
}
d.Set("primary_queue_endpoint", queueEndpoint)
d.Set("primary_queue_host", queueHost)

var tableEndpoint, tableHost string
if v := primary.Table; v != nil {
tableEndpoint = *v

if u, err := url.Parse(*v); err != nil {
tableHost = u.Host
metacpp marked this conversation as resolved.
Show resolved Hide resolved
} else {
return fmt.Errorf("invalid table endpoint for parsing: %q", *v)
}
}
d.Set("primary_table_endpoint", tableEndpoint)
d.Set("primary_table_host", tableHost)

var fileEndpoint, fileHost string
if v := primary.File; v != nil {
fileEndpoint = *v

if u, err := url.Parse(*v); err != nil {
fileHost = u.Host
metacpp marked this conversation as resolved.
Show resolved Hide resolved
} else {
return fmt.Errorf("invalid file endpoint for parsing: %q", *v)
}
}
d.Set("primary_file_endpoint", fileEndpoint)
d.Set("primary_file_host", fileHost)

return nil
}

func flattenAzureRmStorageAccountSecondaryEndpoints(d *schema.ResourceData, secondary *storage.Endpoints, acctName *string, acctKey *string) error {
if secondary == nil {
metacpp marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("secondary Endpoints should not be empty")
}

var blobEndpoint, blobHost, blobConnectionStr string
if v := secondary.Blob; v != nil {
blobEndpoint = *v

if u, err := url.Parse(*v); err != nil {
blobHost = u.Host
metacpp marked this conversation as resolved.
Show resolved Hide resolved
} else {
return fmt.Errorf("invalid blob endpoint for parsing: %q", *v)
}

blobConnectionStr = fmt.Sprintf("DefaultEndpointsProtocol=https;BlobEndpoint=%s;AccountName=%s;AccountKey=%s", blobEndpoint, *acctName, *acctKey)
}
d.Set("secondary_blob_endpoint", blobEndpoint)
d.Set("secondary_blob_host", blobHost)
d.Set("secondary_blob_connection_string", blobConnectionStr)

var queueEndpoint, queueHost string
if v := secondary.Queue; v != nil {
queueEndpoint = *v

if u, err := url.Parse(*v); err != nil {
queueHost = u.Host
metacpp marked this conversation as resolved.
Show resolved Hide resolved
} else {
return fmt.Errorf("invalid queue endpoint for parsing: %q", *v)
}
}
d.Set("secondary_queue_endpoint", queueEndpoint)
d.Set("secondary_queue_host", queueHost)

var tableEndpoint, tableHost string
if v := secondary.Table; v != nil {
tableEndpoint = *v

if u, err := url.Parse(*v); err != nil {
tableHost = u.Host
metacpp marked this conversation as resolved.
Show resolved Hide resolved
} else {
return fmt.Errorf("invalid table endpoint for parsing: %q", *v)
}
}
d.Set("secondary_table_endpoint", tableEndpoint)
d.Set("secondary_table_host", tableHost)

return nil
}
14 changes: 14 additions & 0 deletions website/docs/d/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,32 @@ output "storage_account_tier" {

* `primary_blob_endpoint` - The endpoint URL for blob storage in the primary location.

* `primary_blob_host` - The `host` or `host:port` for blob storage in the primary location.
metacpp marked this conversation as resolved.
Show resolved Hide resolved

* `secondary_blob_endpoint` - The endpoint URL for blob storage in the secondary location.

* `secondary_blob_host` - The `host` or `host:port` for blob storage in the secondary location.

* `primary_queue_endpoint` - The endpoint URL for queue storage in the primary location.

* `primary_queue_host` - The `host` or `host:port` for queue storage in the primary location.

* `secondary_queue_endpoint` - The endpoint URL for queue storage in the secondary location.

* `secondary_queue_host` - The `host` or `host:port` for queue storage in the secondary location.

* `primary_table_endpoint` - The endpoint URL for table storage in the primary location.

* `primary_table_host` - The `host` or `host:port` for table storage in the primary location.

* `secondary_table_endpoint` - The endpoint URL for table storage in the secondary location.

* `secondary_table_host` - The `host` or `host:port` for table storage in the secondary location.

* `primary_file_endpoint` - The endpoint URL for file storage in the primary location.

* `primary_file_host` - The `host` or `host:port` for file storage in the primary location.

* `primary_access_key` - The primary access key for the Storage Account.

* `secondary_access_key` - The secondary access key for the Storage Account.
Expand Down
Loading