Trying to create s3 bucket and restrict to vpc based access. I am using 12.12 version
when I create datasource with aws_vpc (with tag name), I can pass the data value, everything works fine but different accounts have different number of vpcs.
data “aws_vpc” “vpcname” {
filter {
name = “tag:Name”
values = [“vpcname”]
}
when I use aws_vpcs to
data “aws_vpcs” “allvpcs” {
}
Tried diferent ways to list all vpcs in policy
“{tolist(data.aws_vpcs.allvpcs.ids)}"
["{tolist(data.aws_vpcs.allvpcs.ids)}”]
“{data.aws_vpcs.allvpcs.ids}"
["{data.aws_vpcs.allvpcs.ids}”]
60:
61: “aws:sourceVpc”: ["${tolist(data.aws_vpcs.allvpcs.ids)}"]
62:
63:
64:
65:
66:
67:
|----------------
| data.aws_vpcs.allvpcs.ids is set of string with 2 elements
Cannot include the given value in a string template: string required.
values, being plural, expects a list. That is why both of your tests fail and why terraform says it expects a set of string. Every example, including the previous one in this post uses a set/list for values
Thanks that worked… but i cannot use data source(due to multiple tf files and resources, its conflicting), have to try different method as POLICY > option is not able to get all vpcs from data
but i cannot use data source(due to multiple tf files and resources, its conflicting)
I have no idea what that means. You can use as many tf files as you like. Terraform doesn’t care. If you have conflicting resources, do you have duplicate names or something? What you are trying to do is easily possible and building a policy like I showed you easily includes all VPCs like my example showed.
Also, you may believe that Hashicorp has terrible documentation, but all of your code examples are unreadable because you do not style them as preformatted text. And you use smart quotes. If you post more code, please style it correctly.
on mytestvpc.tf line 66, in data “aws_iam_policy_document” “mytestvpc-data-policy”:
66: values = concat(data.aws_vpcs.allvpcs.ids, [“vpc-1”, “vpc-2”, “vpc-3”])
|----------------
| data.aws_vpcs.allvpcs.ids is set of string with 10 elements
Invalid value for “seqs” parameter: all arguments must be lists or tuples; got
set of string.