terraform-linters / tflint-ruleset-terraform

TFLint ruleset for Terraform Language
Mozilla Public License 2.0
61 stars 21 forks source link

terraform_module_pinned_source rule fails on valid git + SSH URL #89

Closed juan-acevedo-ntt closed 1 year ago

juan-acevedo-ntt commented 1 year ago

The url format should be valid according to https://developer.hashicorp.com/terraform/language/modules/sources#generic-git-repository and it has a version pinned. But the linter shows a warning:

Warning: Module source "git::ssh://git@xxx.yyy.com:terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0" is not a valid URL (terraform_module_pinned_source)
  on landing-csz/local-rg-tfstates/main.tf line 33:
  33:   source = "git::ssh://git@xxx.yyy.com:terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0"
Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.2.2/docs/rules/terraform_module_pinned_source.md

The linter works fine when using this other format (that is not the correct one):

source = "ssh://git@xxx.yyy.com:terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0"
wata727 commented 1 year ago

The format of the module source you provided is not valid. In fact, terraform init fails.

$ terraform init
Initializing the backend...
Initializing modules...
╷
│ Error: Invalid module source address
│
│ Module "foo" (declared at main.tf line 1) has invalid source address
│ "git::ssh://git@xxx.yyy.com:terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0": Terraform cannot detect a
│ supported external module source type for
│ ssh://git@xxx.yyy.com:terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0.

So the TFLint warning "module source is not a valid URL" seems correct.

Probably the correct format is:

- git::ssh://git@xxx.yyy.com:terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0
+ git::ssh://git@xxx.yyy.com/terraform/azure/terraform-azurerm-storage.git?ref=zzz/1.3.0