|
| 1 | +# Software Design Document |
| 2 | + |
| 3 | +Reference: Introspection - An option to take variables in SPK scaffold |
| 4 | +command<br> Authors: Andre Briggs, Yvonne Radsmikham, Nathaniel Rose, Dennis |
| 5 | +Seah |
| 6 | + |
| 7 | +| Revision | Date | Author | Remarks | |
| 8 | +| -------: | ------------ | ----------- | ------------------------------------------------- | |
| 9 | +| 0.1 | Mar-07, 2020 | Dennis Seah | Initial Draft | |
| 10 | +| 0.2 | Mar-09, 2020 | Dennis Seah | Incorporated comments from Nate, Yvonne and Andre | |
| 11 | + |
| 12 | +## 1. Overview |
| 13 | + |
| 14 | +`spk infra scaffold` command create a `definition.yaml` that enables user to |
| 15 | +version, modify and organize terraform deployments. There are many variables in |
| 16 | +this file; and it requires use to edit this file in order to complete it. |
| 17 | + |
| 18 | +We want to reduce this two steps process (running `spk infra scaffold` and edit |
| 19 | +`definition.yaml` file) into a single process by enhancing the existing |
| 20 | +`spk infra scaffold` command. |
| 21 | + |
| 22 | +## 2. Out of Scope |
| 23 | + |
| 24 | +This design shall only target making user experience better by reducing the |
| 25 | +number of steps in scaffolding. |
| 26 | + |
| 27 | +## 3. Design Details |
| 28 | + |
| 29 | +### 3.1 New option --file |
| 30 | + |
| 31 | +In the current release (0.5.6), |
| 32 | +[`spk infra scaffold`](https://catalystcode.github.io/spk/commands/index.html#0.5.6@infra_scaffold) |
| 33 | +has 4 options (`--name`, `--source`, `--version` and `--template`). We shall |
| 34 | +introduce a new option `-f`, `--file` which allows user to specify a file that |
| 35 | +contains values for these variables. |
| 36 | + |
| 37 | +The format of this file is `key=value`. E.g. |
| 38 | + |
| 39 | +``` |
| 40 | +address_space=10.10.0.0/16 |
| 41 | +agent_vm_count=4 |
| 42 | +agent_vm_size=Standard_D2s_v3 |
| 43 | +cluster_name=discovery-service-west |
| 44 | +``` |
| 45 | + |
| 46 | +leading and trailing spaces should be trimmed. E.g. `address_space=10.10.0.0/16` |
| 47 | +is the same as `address_space = 10.10.0.0/16` and `address_space = 10.10.0.0/16` |
| 48 | + |
| 49 | +The command shall not be executed if |
| 50 | + |
| 51 | +1. unknown key(s) are found in the file. E.g. `abc=hello` |
| 52 | +2. incorrect type e.g `agent_vm_count=four` where `agent_vm_count` needs a |
| 53 | + integer value. |
| 54 | + |
| 55 | +This means that pre validations are needed before executing the command. |
| 56 | + |
| 57 | +### 3.2 Interactive option |
| 58 | + |
| 59 | +User can runs `spk infra scaffold --interactive`. In this mode, user shall be |
| 60 | +prompt for |
| 61 | + |
| 62 | +1. Cluster name for scaffolding (value for option `--name`) |
| 63 | +2. Source URL for the repository containing the terraform deployment (value for |
| 64 | + option `--source`) |
| 65 | +3. Version or tag for the repository so a fixed version is referenced (value for |
| 66 | + option `--version`) |
| 67 | +4. Location of the variables.tf for the terraform deployment (value for option |
| 68 | + `--template`) |
| 69 | + |
| 70 | +And a question to each of the variable in `definition.yaml`. User can provide |
| 71 | +answers the questions; or hit \<enter> key to skip them. Validation shall be |
| 72 | +done on each question. |
| 73 | + |
| 74 | +> Description for each variable can be found in |
| 75 | +> [terraform's azure webpage](https://learn.hashicorp.com/terraform/azure/variables_az). |
| 76 | +> We just have to create a map of variable names to their descriptions (that's |
| 77 | +> not hardcoding description in our code). |
| 78 | +
|
| 79 | +Answer to question can be also placeholder like `${SERVICE_PRINCIPAL_PASSWORD}` |
| 80 | +when environment parameter value is used for the variable. |
| 81 | + |
| 82 | +## 4. Dependencies |
| 83 | + |
| 84 | +Open source project, [inquirer](https://www.npmjs.com/package/inquirer). |
| 85 | + |
| 86 | +We do not have list and map variable formats now. In future, we may have them |
| 87 | +and we need to provide proper interactive interfaces for them. |
| 88 | + |
| 89 | +## 5. Risks & Mitigations |
| 90 | + |
| 91 | +Sensitive information is in the input for `--file` option. User has to take |
| 92 | +special case of this file. |
| 93 | + |
| 94 | +## 6. Documentation |
| 95 | + |
| 96 | +Documentation should be done in the |
| 97 | +[`md` file](https://github.com/CatalystCode/spk/blob/master/src/commands/infra/scaffold.md) |
| 98 | +that are associated with `spk infra scaffold` command. |
| 99 | + |
| 100 | +\- end - |
0 commit comments