我需要使用 Terraform 在 AWS 上构建多个环境。大多数设置适用于所有环境 - 如何避免代码重复?
resource "aws_elastic_beanstalk_application" "app" {
name = "${var.appName}"
description = ""
}
resource "aws_elastic_beanstalk_environment" "app_env" {
name = "${var.envName}"
application = "${aws_elastic_beanstalk_application.app.name}"
solution_stack_name = "64bit Amazon Linux 2017.09 v2.8.4 running Multi-container Docker 17.09.1-ce (Generic)"
#the same for all envs
setting {
namespace = "aws:ec2:vpc"
name = "VPCId"
value = "vpc-myVpcId"
},
#changes for each env
setting {
namespace = "aws:elasticbeanstalk:application:environment",
name = "SERVICE_NAME",
value = "${var.ServiceName}"
},
resource "aws_elastic_beanstalk_application" "app" {
name = "${var.appName}"
description = ""
}
resource "aws_elastic_beanstalk_environment" "app_env_2" {
name = "${var.envName}"
application = "${aws_elastic_beanstalk_application.app.name}"
solution_stack_name = "64bit Amazon Linux 2017.09 v2.8.4 running Multi-container Docker 17.09.1-ce (Generic)"
#the same for all envs
setting {
namespace = "aws:ec2:vpc"
name = "VPCId"
value = "vpc-myVpcId"
},
#changes for each env
setting {
namespace = "aws:elasticbeanstalk:application:environment",
name = "SERVICE_NAME",
value = "${var.ServiceName_2}"
},
}