Skip to content

Commit

Permalink
Add support for terraform registry submodules
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
tdharris committed Feb 17, 2024
1 parent 407c2a7 commit 6d2c0a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
}
# Submodules
module "" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = "5.33.1"
}
```

#### [Github](https://developer.hashicorp.com/terraform/language/modules/sources#github)
Expand Down
17 changes: 14 additions & 3 deletions src/terraform/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,20 @@ const getTerraformRegistryUri: (moduleSource: string) => vscode.Uri | undefined
}

// Public Registry
if (moduleSource.split("/").length === 3) {
// <hostname>/<namespace>/<name>
return vscode.Uri.parse(`https://registry.terraform.io/modules/${moduleSource}`);
const baseUrl = 'https://registry.terraform.io/modules';
const [namespace, name, provider, ...submodules] = moduleSource.split("/").filter(part => part !== '');

// Submodule
// <hostname>/<namespace>/<name>/<provider>/<submodule>
if (submodules.length > 0) {
const submodulePath = `/submodules/${submodules.join("/").replace("modules/", "")}`;
return vscode.Uri.parse(`${baseUrl}/${namespace}/${name}/${provider}/latest${submodulePath}`);
}

// Module
// <hostname>/<namespace>/<name>
if (namespace && name && provider) {
return vscode.Uri.parse(`${baseUrl}/${moduleSource}`);
}

return;
Expand Down
4 changes: 4 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ suite('Extension Test Suite', () => {
input: "terraform-aws-modules/vpc/aws",
expected: "https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws"
},
{
input: "terraform-aws-modules/iam/aws//modules/iam-assumable-role",
expected: "https://registry.terraform.io/modules/terraform-aws-modules/iam/aws/latest/submodules/iam-assumable-role"
},
{
input: "github.com/hashicorp/example",
expected: "https://github.com/hashicorp/example/tree/HEAD/"
Expand Down

0 comments on commit 6d2c0a3

Please sign in to comment.