Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to create an IAM policy using hclwrite #595

Open
dgokcin opened this issue Mar 8, 2023 · 0 comments
Open

Question: How to create an IAM policy using hclwrite #595

dgokcin opened this issue Mar 8, 2023 · 0 comments

Comments

@dgokcin
Copy link

dgokcin commented Mar 8, 2023

Hello

We are trying to create terragrunt files programatically with hclwrite and having some difficulties with writing iam policies. What I am trying to achieve is this terragrunt.hcl file for an s3 bucket.

  • How can I create the policy and add it to the inputs as an attribute?
include {
  path = find_in_parent_folders()
}

locals {
  common_vars = yamldecode(file(find_in_parent_folders("common_vars.yaml")))
  name        = "product-images"
}

terraform {
  source = "../../../../common//terragrunt-base/modules/terraform-aws-s3-bucket"
}

inputs = {
  bucket        = "${local.common_vars.namespace}-${local.common_vars.environment}-${local.name}"
  policy        = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
        "Sid": "PublicReadGetObject",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::${local.common_vars.namespace}-${local.common_vars.environment}-${local.name}/*"
    }
  ]
}
EOF
  cors_rule = [
    {
      allowed_headers = ["Content-Type"]
      allowed_methods = ["PUT"]
      allowed_origins = ["http://localhost:*"]
    }
  ]

  server_side_encryption_configuration = {
    rule = {
      apply_server_side_encryption_by_default = {
        sse_algorithm = "AES256"
      }
    }
  }
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant