Class: TerraspacePluginAzurerm::Interfaces::Backend::StorageAccount
- Inherits:
-
Base
- Object
- Base
- TerraspacePluginAzurerm::Interfaces::Backend::StorageAccount
show all
- Extended by:
- Memoist
- Defined in:
- lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb
Instance Method Summary
collapse
Methods inherited from Base
#azure_info, #config, #initialize, #logger
Instance Method Details
#blob_service_properties ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 58
def blob_service_properties
sa = config.storage_account
container_delete_retention_policy = {
days: sa.container_delete_retention_policy.days || sa.delete_retention_policy.days,
enabled: sa.container_delete_retention_policy.enabled || sa.delete_retention_policy.enabled,
}
delete_retention_policy = {
days: sa.blob_delete_retention_policy.days || sa.delete_retention_policy.days,
enabled: sa.blob_delete_retention_policy.enabled || sa.delete_retention_policy.enabled,
}
{
containerDeleteRetentionPolicy: container_delete_retention_policy,
deleteRetentionPolicy: delete_retention_policy,
isVersioningEnabled: sa.is_versioning_enabled,
}
end
|
#create ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 5
def create
if exist?
logger.debug "Storage Account #{@storage_account_name} already exists"
save_storage_account if config.storage_account.update_existing
set_blob_service_properties if config.storage_account.configure_data_protection_for_existing
else
save_storage_account
set_blob_service_properties
end
end
|
#exist? ⇒ Boolean
16
17
18
19
20
|
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 16
def exist?
result = storage_account.check_name_availability(name: @storage_account_name)
validate!(result)
!result.name_available
end
|
#save_storage_account ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 35
def save_storage_account
action = exist? ? "Updating" : "Creating"
logger.info "#{action} Storage Account #{@storage_account_name}..."
storage_account.create(
name: @storage_account_name,
location: config.location || azure_info.location, sku: {
name: config.storage_account.sku.name,
tier: config.storage_account.sku.tier,
},
properties: {
allowBlobPublicAccess: config.storage_account.allow_blob_public_access,
minimumTlsVersion: config.storage_account.minimum_tls_version,
},
kind: "StorageV2",
tags: config.tags,
)
end
|
#set_blob_service_properties ⇒ Object
54
55
56
|
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 54
def set_blob_service_properties
blob_service.set_properties(blob_service_properties)
end
|
#validate!(result) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 22
def validate!(result)
return true if result.name_available
case result.reason
when "AccountNameInvalid"
logger.error "ERROR: Failed to create storage account, reason: #{result.reason}".color(:red)
logger.error "Provided storage_account_name: #{@storage_account_name}"
exit 1
else
false
end
end
|