lib/terraforming/resource/s3.rb in terraforming-0.1.4 vs lib/terraforming/resource/s3.rb in terraforming-0.1.5
- old
+ new
@@ -19,26 +19,35 @@
apply_template(@client, "tf/s3")
end
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,
- "id" => bucket.name
+ "force_destroy" => "false",
+ "id" => bucket.name,
+ "policy" => bucket_policy ? bucket_policy.policy.read : "",
}
}
}
resources
end
end
private
+
+ def bucket_policy_of(bucket)
+ @client.get_bucket_policy(bucket: bucket.name)
+ rescue Aws::S3::Errors::NoSuchBucketPolicy
+ nil
+ end
def buckets
@client.list_buckets.buckets
end