Class: PracticeTerraforming::Resource::S3

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/practice_terraforming/resource/s3.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #name_from_tag, #normalize_module_name, #prettify_policy, #template_path

Constructor Details

#initialize(client) ⇒ S3

Returns a new instance of S3.



16
17
18
# File 'lib/practice_terraforming/resource/s3.rb', line 16

def initialize(client)
  @client = client
end

Class Method Details

.tf(client: Aws::S3::Client.new) ⇒ Object



8
9
10
# File 'lib/practice_terraforming/resource/s3.rb', line 8

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

.tfstate(client: Aws::S3::Client.new) ⇒ Object



12
13
14
# File 'lib/practice_terraforming/resource/s3.rb', line 12

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

Instance Method Details

#tfObject



20
21
22
# File 'lib/practice_terraforming/resource/s3.rb', line 20

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

#tfstateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/practice_terraforming/resource/s3.rb', line 24

def tfstate
  buckets.inject({}) do |resources, bucket|
    bucket_policy = bucket_policy_of(bucket)
    resources["aws_s3_bucket.#{module_name_of(bucket)}"] = {
      "type" => "aws_s3_bucket",
      "primary" => {
        "id" => bucket.name,
        "attributes" => {
          "acl" => "private",
          "bucket" => bucket.name,
          "force_destroy" => "false",
          "id" => bucket.name,
          "policy" => bucket_policy ? bucket_policy.policy.read : ""
        }
      }
    }

    resources
  end
end