diff --git a/terraform/modules/storage/open-data-pvnet-s3/bucket.tf b/terraform/modules/storage/open-data-pvnet-s3/bucket.tf new file mode 100644 index 00000000..1f68a21b --- /dev/null +++ b/terraform/modules/storage/open-data-pvnet-s3/bucket.tf @@ -0,0 +1,11 @@ +# Public S3 bucket + +# Bucket itself +# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket +resource "aws_s3_bucket" "bucket" { + bucket = "ocf-open-data-pvnet" + + tags = { + Name = "Open_Data_PVNet" + } +} diff --git a/terraform/modules/storage/open-data-pvnet-s3/iam.tf b/terraform/modules/storage/open-data-pvnet-s3/iam.tf new file mode 100644 index 00000000..844e61ae --- /dev/null +++ b/terraform/modules/storage/open-data-pvnet-s3/iam.tf @@ -0,0 +1,39 @@ +# Make IAM policy to write to the s3-public bucket + +data "aws_iam_policy_document" "open_data_pvnet_write_policy_description" { + version = "2012-10-17" + statement { + actions = [ + "s3:ListBucket", + "s3:GetObject", + "s3:PutObject", + "s3:DeleteObject" + ] + resources = [aws_s3_bucket.bucket.arn, "${aws_s3_bucket.bucket.arn}/*"] + effect = "Allow" + } +} + +# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy +resource "aws_iam_policy" "open_data_pvnet_write_policy" { + name = "s3-open_data_pvnet_write_policy" + description = "Policy to write to bucket: ${aws_s3_bucket.bucket.bucket}" + + # Terraform's "jsonencode" function converts a + # Terraform expression result to valid JSON syntax. + policy = data.aws_iam_policy_document.open_data_pvnet_write_policy_description.json + +} + + +# resource group +resource "aws_iam_group" "open_data_pvnet_write_group" { + name = "open_data_pvnet_write_group" +} + +# attach policy to group +resource "aws_iam_policy_attachment" "open_data_pvnet_write_policy_attachment" { + name = "s3-write-attachment" + policy_arn = aws_iam_policy.open_data_pvnet_write_policy.arn + groups = [aws_iam_group.open_data_pvnet_write_group.name] +} \ No newline at end of file diff --git a/terraform/nowcasting/development/main.tf b/terraform/nowcasting/development/main.tf index a4535990..a4cc1d08 100644 --- a/terraform/nowcasting/development/main.tf +++ b/terraform/nowcasting/development/main.tf @@ -35,6 +35,7 @@ The componentes ares: 6.3 - PVSite ML bucket 6.4 - PVSite Forecast 6.5 - PVSite Database Clean Up +7.1 - Open Data PVnet Variables used across all modules ======*/ @@ -918,3 +919,9 @@ module "pvsite_database_clean_up" { ] container-command = [] } + + +# 7.1 Open Data PVnet - Public s3 bucket +module "open_data_pvnet_s3" { + source = "../../modules/storage/open-data-pvnet-s3" +} \ No newline at end of file