【问题标题】:Error: Invalid version constraint when using a module错误:使用模块时版本约束无效
【发布时间】:2019-11-27 15:26:13
【问题描述】:

我正在创建一些资源,例如 Alb、安全组,并且我使用来自 github 的模块:

module "efs_sg" { 
  source  = "git::https://github.com/terraform-aws-modules/terraform-aws-security-group.git" 
  version = "3.2.0" 

  name        = "${var.default_tags["app"]}-efs" 
  description = "Security group for FE " 
  vpc_id      = data.terraform_remote_state.network.outputs.vpc_id


  computed_ingress_with_source_security_group_id = [ 
    { 
      from_port   = 2049 
      to_port     = 2049 
      protocol    = "tcp" 
      description = "NFS" 
      source_security_group_id = "${module.asg_sg.this_security_group_id}" 
    } 
  ] 
  number_of_computed_ingress_with_source_security_group_id = 1 

  tags      = "${var.default_tags}" 
}

当我执行 terraform 应用/计划时,我收到此错误:

错误:无效的版本约束

Cannot apply a version constraint to module "efs_sg" (at
terraform/dev/eu-west-1/sg.tf:107) because it has a non Registry
URL. 

我正在使用Terraform v0.12.12

如何解决这个问题?

【问题讨论】:

    标签: amazon-web-services terraform terraform-provider-aws


    【解决方案1】:

    您不能将版本约束与 git 托管模块一起使用。版本约束需要 Terraform Registry 托管模块。

    您可以向 repo 添加标签并使用 ?ref 查询。

    例如:

    "git::https://github.com/terraform-aws-modules/terraform-aws-security-group.git?ref=3.2.0"
    

    https://www.terraform.io/docs/modules/sources.html#selecting-a-revision

    【讨论】:

      猜你喜欢
      • 2015-08-01
      • 2019-09-10
      • 2017-07-16
      • 2021-09-18
      • 1970-01-01
      • 2021-10-01
      • 2021-08-18
      • 1970-01-01
      • 2012-11-21
      相关资源
      最近更新 更多