Class: Convection::Model::Template::Resource::S3BucketPolicy

Inherits:
Convection::Model::Template::Resource show all
Extended by:
Forwardable
Defined in:
lib/convection/model/template/resource/aws_s3_bucket_policy.rb

Overview

Examples:

s3_bucket_policy 'BucketPolicy' do
  bucket "my-bucket"

  allow do
    principal :AWS => '*'
    s3_resource "my-bucket", '*'
    action 's3:GetObject'
  end
end

See Also:

Instance Attribute Summary collapse

Attributes inherited from Convection::Model::Template::Resource

#exist, #name, #parent, #properties, #resource_attributes, #template

Instance Method Summary collapse

Methods inherited from Convection::Model::Template::Resource

#as_attribute, attach_method, #deletion_policy, #depends_on, properties, property, #property, #reference, type, #type, #with_output

Methods included from Mixin::Conditional

#condition, #render_condition

Methods included from DSL::Template::Resource

#_terraform_module_dir_to_flag, #_terraform_module_flag_to_dir, attach_resource, attach_resource_collection, resource_collection_dsl_methods, resource_dsl_methods

Methods included from DSL::Helpers

#camel_case, included, method_name, #screaming_snake_case, #snake_case

Methods included from DSL::IntrinsicFunctions

#base64, #find_in_map, #fn_and, #fn_equals, #fn_if, #fn_import_value, #fn_not, #fn_or, #fn_ref, #fn_sub, #get_att, #get_azs, included, #join, mixers, #select

Constructor Details

#initialize(*args) ⇒ S3BucketPolicy

Returns a new instance of S3BucketPolicy.



28
29
30
31
# File 'lib/convection/model/template/resource/aws_s3_bucket_policy.rb', line 28

def initialize(*args)
  super
  @document = Model::Mixin::Policy.new(:name => false, :template => @template)
end

Instance Attribute Details

#documentObject (readonly)

, ‘PolicyDocument’



23
24
25
# File 'lib/convection/model/template/resource/aws_s3_bucket_policy.rb', line 23

def document
  @document
end

Instance Method Details

#bucketObject #bucket(value) ⇒ Object

Overloads:

  • #bucketObject

    Returns the value of the ‘Bucket’ CloudFormation property.

  • #bucket(value) ⇒ Object

    Sets the ‘Bucket’ CloudFormation property.

    Parameters:

    • value

      the value to set the ‘Bucket’ CloudFormation property to.



22
# File 'lib/convection/model/template/resource/aws_s3_bucket_policy.rb', line 22

property :bucket, 'Bucket'

#renderObject



55
56
57
58
59
# File 'lib/convection/model/template/resource/aws_s3_bucket_policy.rb', line 55

def render
  super.tap do |r|
    document.render(r['Properties'])
  end
end

#terraform_import_commandsObject



33
34
35
36
37
38
39
# File 'lib/convection/model/template/resource/aws_s3_bucket_policy.rb', line 33

def terraform_import_commands(*)
  commands = ['# Run the following commands to import your infrastructure into terraform management.', '# ensure :module_path is set correctly', '']
  commands << '# Import s3 bucket and s3 bucket policy: '
  # commands << "terraform import #{module_prefix}aws_s3_bucket.#{name.underscore} #{stack.resources[name].physical_resource_id}"
  commands << ''
  commands
end

#to_hcl_jsonObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/convection/model/template/resource/aws_s3_bucket_policy.rb', line 41

def to_hcl_json(*)
  policy_json = resources[name] && resources[name].document.document.to_json.gsub(stack.resources[name].physical_resource_id, bucket)
  policy_resource = {
    name.underscore => {
      bucket: bucket,
      policy: policy_json
    }
  }

  data = [{ aws_region: { current: { current: true } } }]
  vars = [{ cloud: { description: 'The cloud name for this resource.' } }]
  { resource: { aws_s3_bucket_policy: policy_resource }, data: data, variable: vars }.to_json
end