It's absolutely possible. eg, I have a module I include in all my projects that takes a region code and a codename for an account, and makes available a bunch of metadata like subnet IDs, VPC IDs, security group IDs, the account ID, etc. (You can also use the aws_caller_identity data source these days to get the account ID, but that gives you the account ID your credentials are associated with, which may or may not be what you actually want:
https://www.terraform.io/docs/providers/aws/d/caller_identity.html) So here's a working snippet in situ with the relevant requirements:
variable "env" { default = "prod" }
module "metadata" {
source = "../modules/aws-metadata"
account = "main"
region = "pdx"
env = "${var.env}"
}
provider "aws" {
region = "${module.metadata.region_name}"
allowed_account_ids = ["${module.metadata.account_id}"]
assume_role { role_arn = "${module.metadata.ops_role_arn}" }
}
data "aws_iam_policy_document" "kinesis" {
statement {
resources = ["arn:aws:kinesis:${module.metadata.region_name}:${module.metadata.account_id}:stream/myapp-${var.env}-*"]
actions = [
"kinesis:AddTagsToStream",
"kinesis:DescribeStream",
"kinesis:PutRecord",
"kinesis:PutRecords",
]
}
}