Skip to content

Commit

Permalink
chore: correction using composeWith instead
Browse files Browse the repository at this point in the history
  • Loading branch information
AntPho committed Dec 24, 2024
1 parent 1f22797 commit 1769c32
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions generators/do-swarm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default class DigitalOceanDockerSwarmGenerator extends PulumiGenerator {
this.resourcesList = [
"do-resources",
"do-swarm-leader",
"cloudflare-dns"
"cloudflare-dns",
"ansible-do"
];
}

Expand All @@ -30,41 +31,25 @@ export default class DigitalOceanDockerSwarmGenerator extends PulumiGenerator {
const message = `Generating IaC code for ${this.displayName}`;
this.log(`${chalk.green(message)}`);

// Iterate through the resources list to copy templates for each resource
// Define the generators
const generators = {
"do-resources": "../do-resources/index.js",
"do-swarm-leader": "../do-swarm-leader/index.js",
"cloudflare-dns": "../cloudflare-dns/index.js",
"ansible-do": "../ansible-do/index.js"
};

// Compose with each resource generator
for (const resource of this.resourcesList) {
this.fs.copyTplAsync(
this.templatePath(`../../${resource}/templates/${resource}`),
this.destinationPath(resource),
{
const generatorPath = generators[resource];
if (generatorPath) {
this.composeWith(generatorPath, {
...this.props,
...this.options,
},
{},
{
globOptions: {
dot: true,
ignore: ["**/Pulumi.stack.yaml"],
},
}
);

if (this.options.createStackConfig) {
this.fs.copyTplAsync(
`${this.templatePath(`../../${resource}/templates/${resource}`)}/Pulumi.stack.yaml`,
`${this.destinationPath(`${resource}`)}/Pulumi.${this.options.environment}.yaml`,
{
...this.props,
...this.options,
}
);
});
} else {
this.log(chalk.red(`No generator found for resource: ${resource}`));
}
}

// Additional copying for the "ansible" templates
this.fs.copyTplAsync(
this.templatePath("../../ansible-do/templates/ansible"),
this.destinationPath(`ansible/${this.options.environment}`),
{ globOptions: { dot: true } }
);
}
}

0 comments on commit 1769c32

Please sign in to comment.