Sha256: 4ec129befa4d3bf656b5a9d449c8e77794adf2c8518de7320bf23d0d8387f954

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

module Terraforming
  module Resource
    class S3
      include Terraforming::Util

      def self.tf(client: Aws::S3::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::S3::Client.new, tfstate_base: nil)
        self.new(client).tfstate(tfstate_base)
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/s3")
      end

      def tfstate(tfstate_base)
        resources = buckets.inject({}) do |result, bucket|
          result["aws_s3_bucket.#{module_name_of(bucket)}"] = {
            "type" => "aws_s3_bucket",
            "primary" => {
              "id" => bucket.name,
              "attributes" => {
                "acl" => "private",
                "bucket" => bucket.name,
                "id" => bucket.name
              }
            }
          }

          result
        end

        generate_tfstate(resources, tfstate_base)
      end

      private

      def buckets
        @client.list_buckets.buckets
      end

      def module_name_of(bucket)
        normalize_module_name(bucket.name)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
terraforming-0.1.3 lib/terraforming/resource/s3.rb
terraforming-0.1.2 lib/terraforming/resource/s3.rb
terraforming-0.1.1 lib/terraforming/resource/s3.rb
terraforming-0.1.0 lib/terraforming/resource/s3.rb