|
| 1 | +data "aws_iam_policy_document" "s3_fastly_read_policy_doc_ckan_output" { |
| 2 | + statement { |
| 3 | + sid = "S3FastlyReadBucket" |
| 4 | + actions = ["s3:GetObject"] |
| 5 | + resources = [ |
| 6 | + "arn:aws:s3:::${aws_s3_bucket.ckan-output.id}", |
| 7 | + "arn:aws:s3:::${aws_s3_bucket.ckan-output.id}/*", |
| 8 | + ] |
| 9 | + condition { |
| 10 | + test = "IpAddress" |
| 11 | + variable = "aws:SourceIp" |
| 12 | + values = data.fastly_ip_ranges.fastly.cidr_blocks |
| 13 | + } |
| 14 | + principals { |
| 15 | + type = "AWS" |
| 16 | + identifiers = ["*"] |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +resource "aws_s3_bucket" "ckan-output" { |
| 22 | + bucket = "datagovuk-${var.govuk_environment}-ckan-output" |
| 23 | + tags = { Name = "datagovuk-${var.govuk_environment}-ckan-output" } |
| 24 | +} |
| 25 | + |
| 26 | +resource "aws_s3_bucket_versioning" "ckan_output" { |
| 27 | + |
| 28 | + bucket = aws_s3_bucket.ckan-output.id |
| 29 | + versioning_configuration { status = "Enabled" } |
| 30 | +} |
| 31 | + |
| 32 | +resource "aws_s3_bucket_logging" "ckan_output" { |
| 33 | + count = startswith(var.govuk_environment, "eph-") ? 0 : 1 |
| 34 | + |
| 35 | + bucket = aws_s3_bucket.ckan-output.id |
| 36 | + target_bucket = "govuk-${var.govuk_environment}-aws-logging" |
| 37 | + target_prefix = "s3/datagovuk-${var.govuk_environment}-ckan-output/" |
| 38 | +} |
| 39 | + |
| 40 | +resource "aws_s3_bucket_cors_configuration" "ckan_output" { |
| 41 | + bucket = aws_s3_bucket.ckan-output.id |
| 42 | + cors_rule { |
| 43 | + allowed_methods = ["GET"] |
| 44 | + allowed_origins = var.output_bucket_cors_origins |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +resource "aws_s3_bucket_policy" "govuk_ckan_output_read_policy" { |
| 49 | + bucket = aws_s3_bucket.ckan-output.id |
| 50 | + policy = data.aws_iam_policy_document.s3_fastly_read_policy_doc.json |
| 51 | +} |
| 52 | + |
| 53 | +resource "aws_s3_bucket_public_access_block" "ckan_output" { |
| 54 | + bucket = aws_s3_bucket.ckan-output.id |
| 55 | + |
| 56 | + block_public_acls = false |
| 57 | + block_public_policy = false |
| 58 | + ignore_public_acls = false |
| 59 | + restrict_public_buckets = false |
| 60 | +} |
| 61 | + |
| 62 | +resource "aws_s3_bucket_ownership_controls" "ckan_output" { |
| 63 | + bucket = aws_s3_bucket.ckan-output.id |
| 64 | + |
| 65 | + rule { |
| 66 | + object_ownership = "ObjectWriter" |
| 67 | + } |
| 68 | +} |
0 commit comments