0

我有两个具有相同输入变量的不同 terraform 模块,但名称和域除外。有没有办法共享输入变量?也许有一个外部文件或类似的东西?

这是我的模块

module "autoscaling_docker_frontend" {
  source = "../../_/autoscaling_docker"

  domain        = "domain-1.com"
  has_keychain  = true
  instance_type = "t3.micro"
  name          = "name-1"

  certificate         = var.certificate
  ami                 = var.ami
  account_id          = var.account_id
  dns_zone_id         = var.dns_zone_id
  environment         = var.environment
  key_name            = var.key_name
  subnets             = var.subnets
  vpc_id              = var.vpc_id
  policies            = var.policies
  region              = var.region
  security_groups_alb = var.security_groups_alb
  security_groups_ec2 = var.security_groups_ec2
}

module "autoscaling_docker_backend" {
  source = "../../_/autoscaling_docker"

  domain        = "domain-2.com"
  has_keychain  = true
  instance_type = "t3.micro"
  name          = "name-2"

  certificate         = var.certificate
  ami                 = var.ami
  account_id          = var.account_id
  dns_zone_id         = var.dns_zone_id
  environment         = var.environment
  key_name            = var.key_name
  subnets             = var.subnets
  vpc_id              = var.vpc_id
  policies            = var.policies
  region              = var.region
  security_groups_alb = var.security_groups_alb
  security_groups_ec2 = var.security_groups_ec2
}

谢谢

4

1 回答 1

0

您的常见变量看起来与网络相关。因此,您可以创建一个专用模块来为您的自动缩放组创建网络环境。

这样,您将首先调用网络模块,然后可以将其所有输出作为输入变量传递给其他模块。

于 2021-10-07T22:30:31.647 回答