Class: TerraspacePluginAzurerm::Interfaces::Backend::StorageAccount

Inherits:
Base
  • Object
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

Constructor Details

This class inherits a constructor from TerraspacePluginAzurerm::Interfaces::Backend::Base

Instance Method Details

#blob_service_propertiesObject



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.
  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,
  }
  # blobs
  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,
  }
  # final props
  {
    containerDeleteRetentionPolicy: container_delete_retention_policy,
    deleteRetentionPolicy: delete_retention_policy,
    isVersioningEnabled: sa.is_versioning_enabled,
  }
end

#createObject



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"
     if config..update_existing
    set_blob_service_properties if config..configure_data_protection_for_existing
  else
    
    set_blob_service_properties
  end
end

#exist?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb', line 16

def exist?
  result = .check_name_availability(name: @storage_account_name)
  validate!(result)
  !result.name_available
end

#save_storage_accountObject



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 
  action = exist? ? "Updating" : "Creating"
  logger.info "#{action} Storage Account #{@storage_account_name}..."
  .create(
    name: @storage_account_name,
    location: config.location || azure_info.location, # IE: eastus
    sku: {
      name: config..sku.name,
      tier: config..sku.tier,
    },
    properties: {
      allowBlobPublicAccess: config..allow_blob_public_access,
      minimumTlsVersion: config..minimum_tls_version,
    },
    kind: "StorageV2",
    tags: config.tags,
  )
end

#set_blob_service_propertiesObject



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