ahzhezhe / terraform-generator

Generate Terraform configurations with Node.js.
ISC License
98 stars 19 forks source link

Repeated blocks #8

Closed gvisca closed 4 years ago

gvisca commented 4 years ago

Describe the bug I would like to create an s3 bucket with multiple cors blocks

resource "aws_s3_bucket" "my-bucket" {
  bucket = "my-bucket"
  cors_rule {
    allowed_headers = [
      "Authorization",
    ]
    allowed_methods = [
      "GET",
    ]
    allowed_origins = [
      "*",
    ]
    expose_headers  = []
    max_age_seconds = 3000
  }
  cors_rule {
    allowed_headers = [
      "*",
    ]
    allowed_methods = [
      "PUT",
    ]
    allowed_origins = [
      "*",
    ]
    expose_headers  = []
    max_age_seconds = 0
  }

To reproduce

tfg.resource("aws_s3_bucket", "my-bucket", {
    bucket: "my-bucket",

    cors_rule: {
        allowed_headers: ["*"],
        allowed_methods: ["PUT"],
        allowed_origins: ["*"],
        expose_headers: [],
        max_age_seconds: 0,
    },
    cors_rule: {
        allowed_headers: ["Authorization"],
        allowed_methods: ["GET"],
        allowed_origins: ["*"],
        expose_headers: [],
        max_age_seconds: 3000,
    }
})

Expected behavior This only creates 1 block

Additional context

ahzhezhe commented 4 years ago

What you wrote is not even a valid Javascript.

Put them in array:


tfg.resource('aws_s3_bucket', 'my-bucket', {
  bucket: 'my-bucket',
  cors_rule: [
    {
      allowed_headers: ['*'],
      allowed_methods: ['PUT'],
      allowed_origins: ['*'],
      expose_headers: [],
      max_age_seconds: 0
    },
    {
      allowed_headers: ['Authorization'],
      allowed_methods: ['GET'],
      allowed_origins: ['*'],
      expose_headers: [],
      max_age_seconds: 3000
    }
  ]
});
`
gvisca commented 4 years ago

Of course 🤣 I didn't find a way to make it work and it's sooooo simple

Thanks a lot for the tool, I love it !