在Terraform中,AWS IAM策略资源中的条件语法可以使用以下方式书写:
resource "aws_iam_policy" "example_policy" {
name = "example"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "example_statement"
Effect = "Allow"
Action = [
"s3:Get*",
]
Resource = "arn:aws:s3:::example_bucket/*"
Condition = {
NumericLessThan = {
"s3:max-keys" : "1000"
}
Bool = {
"aws:MultiFactorAuthPresent" : "true"
}
}
},
]
})
}
在上面的示例中,Condition
块定义了两个条件:NumericLessThan
和Bool
。NumericLessThan
条件检查S3桶中的对象数是否少于1000,Bool
条件检查是否启用了AWS多因素身份验证。您可以根据需要添加,更新或删除其他条件。