Sha256: e6b8f6328582a389d01ba9bfaf54c79e67732c0ca64cfe4bdd32151357082924

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

module TerraspacePluginGoogle::Interfaces
  class Backend
    include Terraspace::Plugin::Backend::Interface
    include TerraspacePluginGoogle::Clients

    def call
      return unless TerraspacePluginGoogle.config.auto_create

      bucket = @info["bucket"]
      unless bucket # not bucket provided
        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

    def create_bucket(bucket)
      c = TerraspacePluginGoogle::Interfaces::Config.instance.config.gcs
      storage.create_bucket(bucket) do |b|
        b.versioning = c.versioning
      end
    end

    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

    def logger
      Terraspace.logger
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
terraspace_plugin_google-0.5.0 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.4.2 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.4.1 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.4.0 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.3.5 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.3.4 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.3.3 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.3.2 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.3.1 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.3.0 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.2.2 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.2.1 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.2.0 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.1.1 lib/terraspace_plugin_google/interfaces/backend.rb
terraspace_plugin_google-0.1.0 lib/terraspace_plugin_google/interfaces/backend.rb