Terraform 0.11-在资源之间共享复杂属性值
我目前正在使用Terraform编写多个AWS Kinesis数据分析应用程序。两个应用程序共享相同的Kinesis输入流,因此具有相同的模式:Terraform 0.11-在资源之间共享复杂属性值,terraform,terraform-provider-aws,Terraform,Terraform Provider Aws,我目前正在使用Terraform编写多个AWS Kinesis数据分析应用程序。两个应用程序共享相同的Kinesis输入流,因此具有相同的模式: resource "aws_kinesis_analytics_application" "example1" { name = "example1" inputs { # SHARE THIS ATTRIBUTE VALUE WITH example2 schema { record_columns {
resource "aws_kinesis_analytics_application" "example1" {
name = "example1"
inputs {
# SHARE THIS ATTRIBUTE VALUE WITH example2
schema {
record_columns {
mapping = "$.FIELD1"
name = "FIELD1"
sql_type = "VARCHAR(32)"
}
record_columns {
mapping = "$.FIELD2"
name = "FIELD2"
sql_type = "VARCHAR(32)"
}
record_format {
mapping_parameters {
json {
record_row_path = "$"
}
}
}
}
}
outputs {
# other attributes
schema {
record_format_type = "JSON"
}
}
code = "SQL code ...."
}
resource "aws_kinesis_analytics_application" "example2" {
name = "example2"
inputs {
# SHARE THIS ATTRIBUTE VALUE WITH example1
schema {
record_columns {
mapping = "$.FIELD1"
name = "FIELD1"
sql_type = "VARCHAR(32)"
}
record_columns {
mapping = "$.FIELD2"
name = "FIELD2"
sql_type = "VARCHAR(32)"
}
record_format {
mapping_parameters {
json {
record_row_path = "$"
}
}
}
}
}
outputs {
# Other attributes
schema {
record_format_type = "JSON"
}
}
code = "SQL code...."
}
我假设,如果有可用于模式的数据源,这是可能的:
data "aws_kinesis_analytics_application_schema" "example_input" {
record_columns {
mapping = "$.FIELD1"
name = "FIELD1"
sql_type = "VARCHAR(32)"
}
record_columns {
mapping = "$.FIELD2"
name = "FIELD2"
sql_type = "VARCHAR(32)"
}
record_format {
mapping_parameters {
json {
record_row_path = "$"
}
}
}
}
resource "aws_kinesis_analytics_application" "example1" {
name = "example1"
inputs {
# Other attributes
schema = "${data.aws_kinesis_analytics_application_schema.example_input}"
}
outputs {
# other attributes
schema {
record_format_type = "JSON"
}
}
code = "SQL code ...."
}
resource "aws_kinesis_analytics_application" "example2" {
name = "example2"
inputs {
# Other attributes
schema = "${data.aws_kinesis_analytics_application_schema.example_input}"
}
outputs {
# Other attributes
schema {
record_format_type = "JSON"
}
}
code = "SQL code...."
}
但是,没有可用于此资源的此特定属性的数据源。是否可以在不使用数据源的情况下在资源之间共享如此复杂的属性?您可以使用变量:
variable schema {
record_columns = [
{....},
{....}
]
record_format {
mappings_parameters = [
{....}
]
}
}
resource "aws_kinesis_analytics_application" "example1" {
name = "example1"
inputs {
schema = "${var.schema}"
}
outputs {
# other attributes
schema {
record_format_type = "JSON"
}
}
code = "SQL code ...."
}
resource "aws_kinesis_analytics_application" "example2" {
name = "example2"
inputs {
# SHARE THIS ATTRIBUTE VALUE WITH example1
schema = "${var.schema}"
}
outputs {
# Other attributes
schema {
record_format_type = "JSON"
}
}
code = "SQL code...."
}