name: Cloudsoft AMP S3 Bucket

services:
  - name: S3 Bucket Terraform Template
    type: terraform
    brooklyn.config:
      shell.env:
        AWS_ACCESS_KEY_ID:      $brooklyn:external("exercise-secrets", "aws-access-key-id")
        AWS_SECRET_ACCESS_KEY:  $brooklyn:external("exercise-secrets", "aws-secret-access-key")
      tf_var.bucket_name:       cloudsoft-amp-exercises-store-YOUR_NAME_HERE
      tf.configuration.contents: |
        
        provider "aws" {
          region = "eu-west-1"
        }
        
        variable "bucket_name" {
          description = "Name of bucket to create"
          type        = string
        }
        
        variable "tags" {
          description = "Set of tags to be applied to all supported resources"
          type        = map(string)
          default     = {}
        }
        
        resource "aws_s3_bucket" "store" {
          bucket = var.bucket_name
        
          tags = merge({
            "Purpose" = "For use with Cloudsoft AMP Demo"
          }, var.tags)
        }
        
        resource "aws_s3_bucket_ownership_controls" "store-allow-acl" {
          bucket = aws_s3_bucket.store.id
          rule {
            object_ownership = "BucketOwnerPreferred"
          }
        }
        
        resource "aws_s3_bucket_acl" "store-private" {
          depends_on = [aws_s3_bucket_ownership_controls.store-allow-acl]
          bucket = aws_s3_bucket.store.id
          acl    = "private"
        }
        
        output "bucket_domain_name" {
          value = aws_s3_bucket.store.bucket_domain_name
        }

