hundreds-train-9913
04/02/2025, 5:15 AM@Injectable()
export class PulumiPostgresService {
private stackName = 'dev-databases';
private projectName = 'dev-manager';
async createDatabase(dto:DatabaseConfigDto ) {
try {
const stack = await LocalWorkspace.createOrSelectStack({
stackName: this.stackName,
projectName: this.projectName,
program: this.createPulumiProgram(dto),
});
// Desplegar
const result = await stack.up({ onOutput: console.log });
return { success: true, details: result.summary };
} catch (error) {
console.error('Error:', error);
}
}
private createPulumiProgram(dto: DatabaseConfigDto) {
return async () => {
const provider = new postgresql.Provider('main-provider', {
host: dto.host,
port: dto.port,
username: dto.username,
password: dto.password,
sslmode: dto.sslmode,
superuser: dto.superuser,
});
new postgresql.Database(dto.database.name, {
name: dto.database.name,
}, { provider });
};
}
}
high-painter-73966
04/02/2025, 5:26 PMlittle-cartoon-10569
04/02/2025, 7:20 PMDoes anyone know why this happens?It's because you're using the same value for
dto.database.name
in both cases. That's a lookup into Pulumi's state. If you've run the program once with value "test1", then it'll create a database called "test1". If you run it again with value "test1", it'll update the existing database.hundreds-train-9913
04/02/2025, 8:40 PMhigh-painter-73966
04/02/2025, 8:44 PMhundreds-train-9913
04/02/2025, 8:47 PMlittle-cartoon-10569
04/02/2025, 8:52 PMhigh-painter-73966
04/02/2025, 8:53 PM