IPアドレスのリストを変数で用意して、それをIAMで呼び出す時にこんなエラーが出ます。これを解消するTipsです。
# 変数ファイル IPaddress_list= [A,B,C,D] --- # Terraformコード access_policies = <<POLICY { "Version": "2012-10-17", "Statement": [ { "Action": "es:*", "Principal": "*", "Effect": "Allow", "Resource": "arn:aws:es:ap-northeast-1:${data.aws_caller_identity.self.account_id}:domain/xxx/*", "Condition": { "IpAddress": {"aws:SourceIp": ${var.IPaddress_list} } } } ] } POLICY
Terraform実行後
Error: Invalid template interpolation value on aws_es.tf line 23, in resource "aws_elasticsearch_domain" "example": 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: "IpAddress": {"aws:SourceIp": ${var.IPaddress_list}} 24: 25: 26: 27: 28: |---------------- | var.IPaddress_list is tuple with 21 elements Cannot include the given value in a string template: string required.
解決方法
うまく連結させます。
# Terraformコード access_policies = <<POLICY { "Version": "2012-10-17", "Statement": [ { "Action": "es:*", "Principal": "*", "Effect": "Allow", "Resource": "arn:aws:es:ap-northeast-1:${data.aws_caller_identity.self.account_id}:domain/xxx/*", "Condition": { "IpAddress": {"aws:SourceIp": ["${join("\",\"", var.IPaddress_list)}"] } } } ] } POLICY