For the below question (Q10 in Functions and Conditional Expressions), the provided solution is throwing an error. Please check.
We have now, updated the `main.tf` in this configuration directory and added a new resource block to create a `S3` bucket called `sonic-media` .
Create an additional resource called `upload_sonic_media` to upload the files listed in the variable called `media` to this bucket.
Use the following specifications:
1. Use the `for_each` meta-argument to upload all the elements of the `media` variable.
2. bucket: Use reference expression to the bucket `sonic-media` .
3. source: Each element in the variable called `media` .
4. key: Should be the name of the files being uploaded (minus the `/root` ). For an example, `eggman.jpg, shadow.jpg` e.t.c.
Do not alter the variables!
When ready, run `terraform apply` to create the bucket and upload the items.
Provided Solution
resource "aws_iam_user" "cloud" {
name = split(":",var.cloud_users)[count.index]
count = length(split(":",var.cloud_users))
}
resource "aws_s3_bucket" "sonic_media" {
bucket = var.bucket
}
resource "aws_s3_bucket_object" "upload_sonic_media" {
bucket = aws_s3_bucket.sonic_media.id
key = substr(each.value, 7, 20)
source = each.value
for_each = var.media
}
Error
Terraform Plan shows changes to be applied! Make sure the configuration is up-to-date and applied!