Class: TerraspacePluginGoogle::Interfaces::Backend
- Inherits:
-
Object
- Object
- TerraspacePluginGoogle::Interfaces::Backend
show all
- Includes:
- Terraspace::Plugin::Backend::Interface, Clients
- Defined in:
- lib/terraspace_plugin_google/interfaces/backend.rb
Instance Method Summary
collapse
Methods included from Clients
#initialize, #resource_manager, #secret_manager_service, #storage
Instance Method Details
#call ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/terraspace_plugin_google/interfaces/backend.rb', line 6
def call
return unless TerraspacePluginGoogle.config.auto_create
bucket = @info["bucket"]
unless bucket logger.error "ERROR: no bucket value provided in your terraform backend config"
exit 1
end
if exist?(bucket)
logger.debug "Bucket already exist: #{bucket}"
else
logger.info "Creating bucket: #{bucket}"
create_bucket(bucket)
end
end
|
#create_bucket(bucket) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/terraspace_plugin_google/interfaces/backend.rb', line 22
def create_bucket(bucket)
c = TerraspacePluginGoogle::Interfaces::Config.instance.config.gcs
storage.create_bucket(bucket) do |b|
b.versioning = c.versioning
end
end
|
#exist?(name) ⇒ Boolean
29
30
31
32
33
34
35
36
|
# File 'lib/terraspace_plugin_google/interfaces/backend.rb', line 29
def exist?(name)
!!storage.bucket(name)
rescue Google::Cloud::PermissionDeniedError => e
logger.error "#{e.class}: #{e.message}"
logger.error "ERROR: Bucket is not available: #{name}".color(:red)
logger.error "Bucket might be owned by someone else or is on another one of your Google accounts."
exit 1
end
|
#logger ⇒ Object
38
39
40
|
# File 'lib/terraspace_plugin_google/interfaces/backend.rb', line 38
def logger
Terraspace.logger
end
|