Closed garthk closed 4 years ago
It's not quite #21588 because I'm not within cooee of a module output.
Figured out it's to do with the gymnastics I'm having to pull to add an extra statement to an assume_role_policy
only if an input variable is set:
locals {
assume_by_lambda = {
Sid = "AssumeByLambda"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
Action = "sts:AssumeRole"
Condition = {
NotIpAddress = {
"aws:SourceIp" = "127.0.0.1/32"
}
}
}
assume_by_account = {
Sid = "AssumeByIAMInSameAccount"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
}
Action = "sts:AssumeRole"
Condition = {
Bool = {
"aws:MultiFactorAuthPresent" = "true"
}
}
}
assume_role_policy = {
Version = "2012-10-17"
Statement = var.account_may_assume ? [local.assume_by_lambda, local.assume_by_account] : [local.assume_by_lambda]
}
}
resource "aws_iam_role" "lambda" {
name = var.name
assume_role_policy = jsonencode(local.assume_role_policy)
}
If I remove the dummy Condition
from assume_by_lambda
, I get:
Error: Inconsistent conditional result types
on ../modules/mymodule/main.tf line 32, in locals:
32: Statement = var.account_may_assume ? [local.assume_by_lambda, local.assume_by_account] : [local.assume_by_lambda]
|----------------
| local.assume_by_account is object with 5 attributes
| local.assume_by_lambda is object with 4 attributes
If I set Condition = null
and account_may_assume
is true
, I get the crash above.
I believe this is actually the same issue as was reproduced in https://github.com/hashicorp/terraform/issues/21588#issuecomment-592149310 because the error message is the same and it also occurs in github.com/zclconf/go-cty/cty.ListVal
. Since that issue has an easier reproduction case that I believe is the same underlying bug, I'm going to close this in favor of that one. @garthk if you are really confident this is a different one please email me at ddreier@hashicorp.com and I'm happy to re-open this and then we can re-test once the other one is fixed.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Terraform Version
Terraform v0.12.21
Terraform Configuration Files, Debug Output, Crash Output
I regret I can't post these in public and lack the time right now to redact them.
Expected Behavior
It would have been nice if
terraform apply
had succeeded.Actual Behavior
Steps to Reproduce
terraform apply