Skip to content

Commit 3191b0b

Browse files
fix: obs and private endpoints creation for disabled storage network access
1 parent bd711aa commit 3191b0b

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ proxy_url = VALUE
463463
| <a name="input_function_app_storage_account_prefix"></a> [function\_app\_storage\_account\_prefix](#input\_function\_app\_storage\_account\_prefix) | Weka storage account name prefix | `string` | `"weka"` | no |
464464
| <a name="input_function_app_subnet_delegation_cidr"></a> [function\_app\_subnet\_delegation\_cidr](#input\_function\_app\_subnet\_delegation\_cidr) | Subnet delegation enables you to designate a specific subnet for an Azure PaaS service. | `string` | `"10.0.1.0/25"` | no |
465465
| <a name="input_function_app_subnet_delegation_id"></a> [function\_app\_subnet\_delegation\_id](#input\_function\_app\_subnet\_delegation\_id) | Required to specify if subnet\_name were used to specify pre-defined subnets for weka. Function subnet delegation requires an additional subnet, and in the case of pre-defined networking this one also should be pre-defined | `string` | `""` | no |
466-
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"0154dfe987a700e0af9f3921aae63884"` | no |
466+
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"70129b9f8d813e6f87aeed9be4764327"` | no |
467467
| <a name="input_get_weka_io_token"></a> [get\_weka\_io\_token](#input\_get\_weka\_io\_token) | The token to download the Weka release from get.weka.io. | `string` | `""` | no |
468468
| <a name="input_hotspare"></a> [hotspare](#input\_hotspare) | Number of hotspares to set on weka cluster. Refer to https://docs.weka.io/overview/ssd-capacity-management#hot-spare | `number` | `1` | no |
469469
| <a name="input_install_cluster_dpdk"></a> [install\_cluster\_dpdk](#input\_install\_cluster\_dpdk) | Install weka cluster with DPDK | `bool` | `true` | no |

function-app/code/functions/clusterize/clusterize.go

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type ClusterizationParams struct {
4848
KeyVaultUri string
4949
SubnetId string
5050
PrivateDNSZoneId string
51+
// if network access is disabled and private endpoints do not exist, create them with obs
52+
CreateBlobPrivateEndpoint bool
5153

5254
StateParams common.BlobObjParams
5355
InstallDpdk bool
@@ -79,39 +81,52 @@ func GetShutdownScript() string {
7981
return dedent.Dedent(s)
8082
}
8183

82-
func CreateWekaObs(ctx context.Context, p *ClusterizationParams) (err error) {
84+
func PrepareWekaObs(ctx context.Context, p *ClusterizationParams) (err error) {
8385
logger := logging.LoggerFromCtx(ctx)
8486

85-
if p.Obs.NetworkAccess == "Disabled" && p.PrivateDNSZoneId == "" {
86-
ignoredErr := fmt.Errorf("private dns zone id is required for private endpoint creation when public access is disabled")
87+
noExistingObs := p.Obs.AccessKey == ""
88+
89+
if p.Obs.NetworkAccess == "Disabled" && noExistingObs && !p.CreateBlobPrivateEndpoint {
90+
ignoredErr := fmt.Errorf("private endpoint creation is required for obs when public access is disabled")
8791
logger.Error().Err(ignoredErr).Send()
8892

89-
logger.Info().Msg("Skipping OBS creation")
93+
common.ReportMsg(ctx, p.Vm.Name, p.StateParams, "error", ignoredErr.Error())
9094
p.Cluster.SetObs = false
9195
return nil
9296
}
9397

94-
p.Obs.AccessKey, err = common.CreateStorageAccount(
95-
ctx, p.SubscriptionId, p.ResourceGroupName, p.Location, p.Obs,
96-
)
97-
if err != nil {
98-
err = fmt.Errorf("failed to create storage account: %w", err)
99-
logger.Error().Err(err).Send()
100-
return
101-
}
98+
if p.Obs.NetworkAccess == "Disabled" && p.CreateBlobPrivateEndpoint && p.PrivateDNSZoneId == "" {
99+
ignoredErr := fmt.Errorf("private dns zone id is required for private endpoint creation when public access is disabled")
100+
logger.Error().Err(ignoredErr).Send()
102101

103-
if p.Obs.NetworkAccess == "Disabled" {
104-
endpointName := fmt.Sprintf("%s-pe", p.Obs.Name)
105-
logger.Info().Msgf("public access is disabled for the storage account, creating private endpoint %s", endpointName)
102+
common.ReportMsg(ctx, p.Vm.Name, p.StateParams, "error", ignoredErr.Error())
103+
p.Cluster.SetObs = false
104+
return nil
105+
}
106106

107-
err = common.CreateStorageAccountBlobPrivateEndpoint(ctx, p.SubscriptionId, p.ResourceGroupName, p.Location, p.Obs.Name, endpointName, p.SubnetId, p.PrivateDNSZoneId)
107+
if noExistingObs {
108+
p.Obs.AccessKey, err = common.CreateStorageAccount(
109+
ctx, p.SubscriptionId, p.ResourceGroupName, p.Location, p.Obs,
110+
)
108111
if err != nil {
109-
err = fmt.Errorf("failed to create private endpoint: %w", err)
112+
err = fmt.Errorf("failed to create storage account: %w", err)
110113
logger.Error().Err(err).Send()
111114
return
112115
}
113-
}
114116

117+
if p.Obs.NetworkAccess == "Disabled" && p.CreateBlobPrivateEndpoint {
118+
endpointName := fmt.Sprintf("%s-pe", p.Obs.Name)
119+
logger.Info().Msgf("public access is disabled for the storage account, creating private endpoint %s", endpointName)
120+
121+
err = common.CreateStorageAccountBlobPrivateEndpoint(ctx, p.SubscriptionId, p.ResourceGroupName, p.Location, p.Obs.Name, endpointName, p.SubnetId, p.PrivateDNSZoneId)
122+
if err != nil {
123+
err = fmt.Errorf("failed to create private endpoint: %w", err)
124+
logger.Error().Err(err).Send()
125+
return
126+
}
127+
}
128+
}
129+
// create container (if it doesn't exist)
115130
err = common.CreateContainer(ctx, p.Obs.Name, p.Obs.ContainerName)
116131
if err != nil {
117132
err = fmt.Errorf("failed to create container: %w", err)
@@ -127,9 +142,10 @@ func HandleLastClusterVm(ctx context.Context, state protocol.ClusterState, p Clu
127142

128143
vmScaleSetName := common.GetVmScaleSetName(p.Prefix, p.Cluster.ClusterName)
129144

130-
if p.Cluster.SetObs && p.Obs.AccessKey == "" {
131-
err = CreateWekaObs(ctx, &p)
145+
if p.Cluster.SetObs {
146+
err = PrepareWekaObs(ctx, &p)
132147
if err != nil {
148+
logger.Error().Err(err).Send()
133149
return
134150
}
135151
}
@@ -386,6 +402,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
386402
keyVaultUri := os.Getenv("KEY_VAULT_URI")
387403
subnetId := os.Getenv("SUBNET_ID")
388404
blobPrivateDnsZoneId := os.Getenv("BLOB_PRIVATE_DNS_ZONE_ID")
405+
createblobPrivateEndpoint, _ := strconv.ParseBool(os.Getenv("CREATE_BLOB_PRIVATE_ENDPOINT"))
389406
// data protection-related vars
390407
stripeWidth, _ := strconv.Atoi(os.Getenv("STRIPE_WIDTH"))
391408
protectionLevel, _ := strconv.Atoi(os.Getenv("PROTECTION_LEVEL"))
@@ -441,16 +458,17 @@ func Handler(w http.ResponseWriter, r *http.Request) {
441458
}
442459

443460
params := ClusterizationParams{
444-
SubscriptionId: subscriptionId,
445-
ResourceGroupName: resourceGroupName,
446-
Location: location,
447-
Prefix: prefix,
448-
KeyVaultUri: keyVaultUri,
449-
SubnetId: subnetId,
450-
PrivateDNSZoneId: blobPrivateDnsZoneId,
451-
StateParams: common.BlobObjParams{StorageName: stateStorageName, ContainerName: stateContainerName, BlobName: stateBlobName},
452-
Vm: vm,
453-
InstallDpdk: installDpdk,
461+
SubscriptionId: subscriptionId,
462+
ResourceGroupName: resourceGroupName,
463+
Location: location,
464+
Prefix: prefix,
465+
KeyVaultUri: keyVaultUri,
466+
SubnetId: subnetId,
467+
PrivateDNSZoneId: blobPrivateDnsZoneId,
468+
CreateBlobPrivateEndpoint: createblobPrivateEndpoint,
469+
StateParams: common.BlobObjParams{StorageName: stateStorageName, ContainerName: stateContainerName, BlobName: stateBlobName},
470+
Vm: vm,
471+
InstallDpdk: installDpdk,
454472
Cluster: clusterize.ClusterParams{
455473
ClusterizationTarget: clusterizationTarget,
456474
ClusterName: clusterName,

functions.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ locals {
140140
"SUBNET" = local.subnet_range
141141
"SUBNET_ID" = data.azurerm_subnet.subnet.id
142142
"BLOB_PRIVATE_DNS_ZONE_ID" = var.create_storage_account_private_links ? azurerm_private_dns_zone.blob[0].id : local.sa_public_access_disabled ? data.azurerm_private_dns_zone.blob[0].id : ""
143+
"CREATE_BLOB_PRIVATE_ENDPOINT" = var.create_storage_account_private_links && local.sa_public_access_disabled
143144
FUNCTION_APP_NAME = local.function_app_name
144145
PROXY_URL = var.proxy_url
145146
WEKA_HOME_URL = var.weka_home_url

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ variable "function_app_storage_account_container_prefix" {
393393
variable "function_app_version" {
394394
type = string
395395
description = "Function app code version (hash)"
396-
default = "0154dfe987a700e0af9f3921aae63884"
396+
default = "70129b9f8d813e6f87aeed9be4764327"
397397
}
398398

399399
variable "function_app_dist" {

0 commit comments

Comments
 (0)