Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from NathanielRose/nate.patch.relative-paths
Browse files Browse the repository at this point in the history
Fix for relative path support for private repos
  • Loading branch information
NathanielRose authored Apr 14, 2020
2 parents 24c4379 + 886c1c9 commit 996e6b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
"required": false
}
],
"markdown": "## Description\n\nCreates a \"generated\" deployment folder with the completed Terraform files based\non definitions provided from a scaffolded project.\n\nIt will do the following:\n\n- Check if a provided project folder contains a `definition.yaml`\n- Verify the configuration of parent and leaf definitions.\n- Check if the terraform template `source` provided has a valid remote\n repository.\n- Clone and cache the master version of the provided `source` repository locally\n in `~/.spk/templates`\n > Cached repositories will be converted through regex for spk to hash. (i.e. a\n > `source` template of `https://github.com/microsoft/bedrock` will be cached\n > into a folder called `_microsoft_bedrock_git`)\n- Create a \"generated\" directory for Terrform deployments (alongside the\n scaffolded project directory)\n- Copy the appropriate Terraform templates to the \"generated\" directory\n- Create a `spk.tfvars` in the generated directory based on the variables\n provided in `definition.yaml` files of the parent and leaf directories.\n\n## Example\n\nAssuming you have the following setup:\n\n```\nfabrikam\n |- definition.yaml\n |- east/\n |- definition.yaml\n |- central/\n |- definition.yaml\n```\n\nWhen executing the following command **in the `fabrikam` directory**:\n\n```\nspk infra generate --project east\n```\n\nThe following hiearchy of directories will be generated _alongside_ the targeted\ndirectory. In addition, the appropriate versioned Terraform templates will be\ncopied over to the leaf directory with a `spk.tfvars`, which contains the\nvariables accumulated from parent **and** leaf definition.yaml files, where if a\nvariable exists in both parent and leaf definition, the **leaf definitions will\ntake precedence**.\n\n```\nfabrikam\n |- definition.yaml\n |- east/\n |- definition.yaml\n |- central/\n |- definition.yaml\nfabrikam-generated\n |- east\n |- main.tf\n |- variables.tf\n |- spk.tfvars (concatenation of variables from fabrikam/definition.yaml (parent) and fabrikam/east/definition.yaml (leaf))\n```\n\nYou can also have a \"single-tree\" generation by executing `spk infra generate`\ninside a directory without specifying a project folder. For example, if you had\nthe following tree structure:\n\n```\nfabrikam\n |- definition.yaml\n```\n\nand executed `spk infra generate` inside the `fabrikam` directory, this will\ngenerate the following:\n\n```\nfabrikam-generated\n |- main.tf\n |- variables.tf\n |- spk.tfvars\n```\n"
"markdown": "## Description\n\nCreates a \"generated\" deployment folder with the completed Terraform files based\non definitions provided from a scaffolded project.\n\nIt will do the following:\n\n- Check if a provided project folder contains a `definition.yaml`\n- Verify the configuration of parent and leaf definitions.\n- Check if the terraform template `source` provided has a valid remote\n repository.\n- Clone and cache the master version of the provided `source` repository locally\n in `~/.spk/templates`\n > Cached repositories will be converted through regex for spk to hash. (i.e. a\n > `source` template of `https://github.com/microsoft/bedrock` will be cached\n > into a folder called `_microsoft_bedrock_git`)\n- Create a \"generated\" directory for Terrform deployments (alongside the\n scaffolded project directory)\n- Copy the appropriate Terraform templates to the \"generated\" directory\n- Check the Terraform module source values and convert them into a generic git\n url based on the `definition.yaml`'s `source`, `version` and `template` path.\n- Create a `spk.tfvars` in the generated directory based on the variables\n provided in `definition.yaml` files of the parent and leaf directories.\n\n## Example\n\nAssuming you have the following setup:\n\n```\nfabrikam\n |- definition.yaml\n |- east/\n |- definition.yaml\n |- central/\n |- definition.yaml\n```\n\nWhen executing the following command **in the `fabrikam` directory**:\n\n```\nspk infra generate --project east\n```\n\nThe following hiearchy of directories will be generated _alongside_ the targeted\ndirectory. In addition, the appropriate versioned Terraform templates will be\ncopied over to the leaf directory with a `spk.tfvars`, which contains the\nvariables accumulated from parent **and** leaf definition.yaml files, where if a\nvariable exists in both parent and leaf definition, the **leaf definitions will\ntake precedence**.\n\n```\nfabrikam\n |- definition.yaml\n |- east/\n |- definition.yaml\n |- central/\n |- definition.yaml\nfabrikam-generated\n |- east\n |- main.tf\n |- variables.tf\n |- spk.tfvars (concatenation of variables from fabrikam/definition.yaml (parent) and fabrikam/east/definition.yaml (leaf))\n```\n\nYou can also have a \"single-tree\" generation by executing `spk infra generate`\ninside a directory without specifying a project folder. For example, if you had\nthe following tree structure:\n\n```\nfabrikam\n |- definition.yaml\n```\n\nand executed `spk infra generate` inside the `fabrikam` directory, this will\ngenerate the following:\n\n```\nfabrikam-generated\n |- main.tf\n |- variables.tf\n |- spk.tfvars\n```\n"
},
"infra scaffold": {
"command": "scaffold",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/infra/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ It will do the following:
- Create a "generated" directory for Terrform deployments (alongside the
scaffolded project directory)
- Copy the appropriate Terraform templates to the "generated" directory
- Check the Terraform module source values and convert them into a generic git
url based on the `definition.yaml`'s `source`, `version` and `template` path.
- Create a `spk.tfvars` in the generated directory based on the variables
provided in `definition.yaml` files of the parent and leaf directories.

Expand Down
2 changes: 1 addition & 1 deletion src/commands/infra/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const mockSourceInfo = {
};

const modifedSourceModuleData = `"aks-gitops" {
source = "github.com/microsoft/bedrock.git?ref=v0.0.1//cluster/azure/aks-gitops/"
source = "git::https://github.com/microsoft/bedrock.git//cluster/azure/aks-gitops/?ref=v0.0.1"
acr_enabled = var.acr_enabled
agent_vm_count = var.agent_vm_count
};
Expand Down
13 changes: 9 additions & 4 deletions src/commands/infra/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,15 @@ export const moduleSourceModify = async (
splitLine[3].replace(/["']/g, "")
)
);
// Concatenate the Git URL with munged data
const gitSource = fileSource.source
.replace(/(^\w+:|^)\/\//g, "")
.concat("?ref=", fileSource.version, "//", repoModulePath);
// Concatenate the Git URL with munged data using a generic git repository format
const gitSource =
"git::" +
fileSource.source.concat(
"//",
repoModulePath,
"?ref=",
fileSource.version
);
// Replace the line
line = line.replace(moduleSource, gitSource);
}
Expand Down

0 comments on commit 996e6b8

Please sign in to comment.