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

S3 Bucket Policy Creation with Principal Fails #632

Closed
Fabii547 opened this issue Aug 6, 2024 · 2 comments · Fixed by #634
Closed

S3 Bucket Policy Creation with Principal Fails #632

Fabii547 opened this issue Aug 6, 2024 · 2 comments · Fixed by #634
Assignees
Labels
bug Something isn't working

Comments

@Fabii547
Copy link
Contributor

Fabii547 commented Aug 6, 2024

Description

Creating a bucket policy as described here and here with a principal does not work because it cannot be parsed into a string array.

See below for an example Terraform code and the error output.

Expected behavior

Environment

Terraform version:

1.5.7

Provider version:

6.5.0

OS:

not relevant

Configuration Files

resource "ionoscloud_s3_bucket" "example" {
  name   = "example"
  region = "eu-central-3"
}

resource "ionoscloud_s3_bucket_policy" "example" {
  bucket = ionoscloud_s3_bucket.example.name
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Sid    = "Delegate certain actions to another user",
        Effect = "Allow",
        Principal = {
          AWS = [
            "arn:aws:iam:::user/CONTRACT_USER_ID1"
          ]
        }
        Action = ["s3:*"]
        Resource = [
          "arn:aws:s3:::${ionoscloud_s3_bucket.example.name}",
          "arn:aws:s3:::${ionoscloud_s3_bucket.example.name}/*"
        ]
      }
    ]
  })
}

Error and Debug Output

╷
│ Error: Normalized JSON Unmarshal Error
│ 
│   with ionoscloud_s3_bucket_policy.example,
│   on bucket.tf line 14, in resource "ionoscloud_s3_bucket_policy" "example":
│   14: resource "ionoscloud_s3_bucket_policy" "example" {
│ 
│ json: cannot unmarshal object into Go struct field
│ bucketPolicyStatement.Statement.Principal of type []string
╵
@cristiGuranIonos
Copy link
Collaborator

cristiGuranIonos commented Aug 6, 2024

Problem in our docs. this should work:

resource "ionoscloud_s3_bucket_policy" "example" {
  bucket = ionoscloud_s3_bucket.example.name
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Sid    = "Delegate certain actions to another user",
        Effect = "Allow",
        Principal = [
            "arn:aws:iam:::user/CONTRACT_USER_ID1"
        ]
        Action = ["s3:*"]
        Resource = [
          "arn:aws:s3:::${ionoscloud_s3_bucket.example.name}",
          "arn:aws:s3:::${ionoscloud_s3_bucket.example.name}/*"
        ]
      }
    ]
  })
}

@Fabii547
Copy link
Contributor Author

Fabii547 commented Aug 6, 2024

Thanks, this works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants