Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Invalid version constraint when using a module

I'm creating few resources like Alb, security group and I use modules from 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}" 
}

when I do terraform apply/plan I get this error:

Error: Invalid version constraint

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. 

I'm using Terraform v0.12.12

How to fix this?

like image 320
Souad Avatar asked Sep 21 '25 03:09

Souad


1 Answers

You can't use the version constraint with a git hosted module. The version constraint requires a Terraform Registry hosted module.

You can add a tag to the repo and use the ?ref query.

eg:

"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

like image 191
logicaldiagram Avatar answered Sep 22 '25 21:09

logicaldiagram