Externalize targets configuration
As the number of deployment targets grows, the size of the deployment configuration file might become unwieldy. You can externalize the deployment target configurations outside the deployment configuration file to make the deployment configuration file more manageable. To do this, you need to define the deployment target repository in a takomo.yml file located in your project's root directory.

Load deployment targets from the filesystem

Currently, there is one target repository implementation. It loads deployment target configurations from a specified directory. To enable it, you need to add the following configuration to the takomo.yml file.
takomo.yml
1
deploymentTargets:
2
repository:
3
type: filesystem
4
dir: <path to a directory with the target configurations>
5
inferDeploymentGroupPathFromDirName: <boolean>
6
inferDeploymentTargetNameFromFileName: <boolean>
Copied!
The type property specifies that the target repository of type filesystem should be used to load the external targets configuration. The dir property specifies the file path to the directory from where to load the configurations. The file path can be absolute or relative to the project's root directory. Finally, the inferDeploymentGroupPathFromDirName property instructs Takomo to infer the target's deployment group from the name of the directory where the target's configuration file is located.
Takomo will look for .yml files from the specified directory and its subdirectories. You can name the files as you wish. Each file must contain a valid configuration for one deployment target. The configuration format is the same as if the target's configuration was given in the deployment configuration file. The only difference is that unless you set inferDeploymentGroupPathFromDirName to true, you need to specify the target's deployment group with a deploymentGroupPath property. All deployment groups referred in the external configuration files must be defined in the deployment configuration file, too.

Example

Let's continue with our example and see how to externalize the deployment targets to a separate directory.
First, we specify that we want to load configuration for our deployment targets from a my-targets directory located in our project's root directory.
takomo.yml
1
deploymentTargets:
2
repository:
3
type: filesystem
4
dir: my-targets
Copied!
Next, we extract the configuration for each of our target to separate files located in the my-targets directory.
my-targets/infra.yml
1
deploymentGroupPath: all/shared
2
name: infra
3
deploymentRole: arn:aws:iam::123456789012:role/ExampleAdmin
4
labels: others
Copied!
my-targets/dev-environment.yml
1
deploymentGroupPath: all/application/dev
2
name: dev-environment
3
accountId: "222244446666"
4
labels: app
Copied!
my-targets/sandbox.yml
1
deploymentGroupPath: all/application/dev
2
name: sandbox
3
accountId: "111133335555"
4
labels: others
Copied!
my-targets/prod-environment.yml
1
deploymentGroupPath: all/application/prod
2
name: prod-environment
3
accountId: "333355557777"
4
labels: app
Copied!
As you can see, each deployment target specifies the deployment group where the target belongs to.
After our changes, the deployment configuration file looks like this:
deployment/targets.yml
1
vars:
2
cost-center: 12345
3
budget: 2000
4
5
targetsSchema: budget
6
7
deploymentGroups:
8
all:
9
configSets: security
10
all/shared: {}
11
all/application:
12
configSets: networking
13
targetsSchema: environment
14
deploymentRoleName: deployer
15
all/application/dev: {}
16
all/application/prod: {}
Copied!
And this is how our file system looks like:
1
.
2
├─ templates
3
├─ config-sets
4
│ ├─ networking
5
│ │ ├─ private
6
│ │ │ └─ tgw.yml
7
│ │ └─ public
8
│ │ └─ load-balancer.yml
9
│ └─ security
10
│ ├─ config.yml
11
│ └─ audit.yml
12
├─ deployment
13
│ └─ targets.yml
14
└─ my-targets
15
├─ infra.yml
16
├─ dev-environment.yml
17
├─ sandbox.yml
18
└─ prod-environment.yml
Copied!

Infer deployment group from a directory name

As mentioned earlier, you can use the inferDeploymentGroupPathFromDirName property to instruct Takomo to infer the target's deployment group from the name of the directory where the target's configuration file is located. If you choose to use this option, you need to have a directory structure that mirrors your deployment group hierarchy. As a benefit, you can omit the deploymentGroupPath property from the target files.

Example

Alright, let's convert our example to use the inferDeploymentGroupPathFromDirName property.
takomo.yml
1
deploymentTargets:
2
repository:
3
type: filesystem
4
dir: my-targets
5
inferDeploymentGroupPathFromDirName: true
Copied!
The deployment configuration file deployment/targets.yml stays the same but we need to create a directory structure that mirrors our deployment groups under the my-targets directory and move the target files to correct subdirectories.
1
.
2
├─ templates
3
├─ config-sets
4
│ ├─ networking
5
│ │ ├─ private
6
│ │ │ └─ tgw.yml
7
│ │ └─ public
8
│ │ └─ load-balancer.yml
9
│ └─ security
10
│ ├─ config.yml
11
│ └─ audit.yml
12
├─ deployment
13
│ └─ targets.yml
14
└─ my-targets
15
└─ all
16
├─ shared
17
│ └─ infra.yml
18
└─ application
19
├─ dev
20
│ ├─ dev-environment.yml
21
│ └─ sandbox.yml
22
└─ prod
23
└─ prod-environment.yml
Copied!
We can then remove the deploymentGroupPath property from the target files.

Infer deployment targets' names from names of their config files

You can use the inferDeploymentTargetNameFromFileName property to instruct Takomo to infer targets' names from the names of their configuration files. You can then omit the name property from the target files.
The target name is inferred by removing the .yml file extension from the target's configuration file name.

Example

Let's add inferDeploymentTargetNameFromFileName to our example.
takomo.yml
1
deploymentTargets:
2
repository:
3
type: filesystem
4
dir: my-targets
5
inferDeploymentGroupPathFromDirName: true
6
inferDeploymentTargetNameFromFileName: true
Copied!
Then just remove the name property from configuration files of our targets.
Last modified 2mo ago