adamant-solstice-35288
12/04/2024, 5:19 PMsyncEnv.yml
as explained in the `README.md`:
imports:
- case-traders/cms
values:
sync:
githubSecrets:
- name: CMS_GITHUB_TOKEN
value: ${CMS_GITHUB_TOKEN}
- name: CMS_REPO
value: ${CMS_REPO}
- name: CMS_REPO_OWNER
value: ${CMS_REPO_OWNER}
- name: CMS_USERNAME
value: ${CMS_USERNAME}
- name: CMS_PASSWORD
value: ${CMS_PASSWORD}
when I try pulumi up
I get the following error
Type Name Status Info
pulumi:pulumi:Stack esc-sync-github-secrets-dev **failed** 1 error
+ └─ pulumiservice:index:Environment env **creating failed** 1 error
Diagnostics:
pulumi:pulumi:Stack (esc-sync-github-secrets-dev):
error: update failed
pulumiservice:index:Environment (env):
error: failed to check environment due to error: [0]
Diags: unknown property "CMS_GITHUB_TOKEN"
unknown property "CMS_REPO"
unknown property "CMS_REPO_OWNER"
unknown property "CMS_USERNAME"
unknown property "CMS_PASSWORD"
[Pulumi Copilot] Would you like help with these diagnostics?
<https://app.pulumi.com/case-traders/esc-sync-github-secrets/dev/updates/2?explainFailure>
Resources:
2 unchanged
Duration: 3s
red-match-15116
12/04/2024, 5:27 PMgithubSecrets
is an object. In your code, githubSecrets
is an array of objects.adamant-solstice-35288
12/04/2024, 5:40 PMtarget/index.ts
import * as pulumi from "@pulumi/pulumi";
import * as github from "@pulumi/github";
import * as fs from "fs";
const config = new pulumi.Config();
const repository = config.require("repository");
const secretsFile = "sync.json";
const secretsConfig = JSON.parse(fs.readFileSync(secretsFile, "utf8"));
if (!Array.isArray(secretsConfig.githubSecrets)) {
throw new Error("Invalid secrets configuration. Expected a list of secrets under `githubSecrets`.");
}
const secrets = secretsConfig.githubSecrets.map((secret:Record<string, string>) => {
if (!secret.name || !secret.value) {
throw new Error(`Invalid secret entry: ${JSON.stringify(secret)}`);
}
return new github.ActionsSecret(`githubSecret-${secret.name}`, {
repository,
secretName: secret.name,
plaintextValue: secret.value,
});
});
export const secretNames = secrets.map((secret) => secret.secretName);
but it still gives the same errorred-match-15116
12/04/2024, 5:41 PMindex.ts
specifically, here's where it assumes githubSecrets
is an object:
https://github.com/pulumi/esc-examples/blob/main/sync/github-secrets/index.ts#L43-L48adamant-solstice-35288
12/04/2024, 5:42 PMindex.ts
file I find this
operationContext: {
preRunCommands: [
"pulumi login",
pulumi
.interpolate`pulumi config env add ${projectName}/${env.name} -s ${fullyQualifiedStackName} --yes`,
pulumi
.interpolate`pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets.value > sync.json`,
pulumi
.interpolate`pulumi config set -s ${fullyQualifiedStackName} secretName $(pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets.name)`,
],
},
adamant-solstice-35288
12/04/2024, 5:43 PMred-match-15116
12/04/2024, 5:43 PMgithubSecrets
array as a secret config and then parse it in target/index.ts
adamant-solstice-35288
12/04/2024, 5:43 PMopen
pulumi
.interpolate`pulumi config set -s ${fullyQualifiedStackName} secretName $(pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets.name)`,
adamant-solstice-35288
12/04/2024, 5:44 PMpulumi
.interpolate`pulumi config set -s ${fullyQualifiedStackName} secretName $(pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets.name)`,
`red-match-15116
12/04/2024, 5:45 PMsecretName
on the target stack to whatever the name of your secret is.adamant-solstice-35288
12/04/2024, 5:47 PMpulumi
.interpolate`pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets > sync.json`,
adamant-solstice-35288
12/04/2024, 5:47 PMerror: update failed
pulumiservice:index:Environment (env):
error: failed to check environment due to error: [0]
Diags: unknown property "CMS_GITHUB_TOKEN"
unknown property "CMS_REPO"
unknown property "CMS_REPO_OWNER"
unknown property "CMS_USERNAME"
unknown property "CMS_PASSWORD"
adamant-solstice-35288
12/04/2024, 5:48 PMadamant-solstice-35288
12/04/2024, 5:48 PMname : "dev"
organization: "case-traders"
project : "case-traders"
yaml : (yaml) {
imports: [
[0]: "case-traders/cms"
]
values : {
sync: {
githubSecrets: [
[0]: {
name : "CMS_GITHUB_TOKEN"
value: "${CMS_GITHUB_TOKEN}"
}
[1]: {
name : "CMS_REPO"
value: "${CMS_REPO}"
}
[2]: {
name : "CMS_REPO_OWNER"
value: "${CMS_REPO_OWNER}"
}
[3]: {
name : "CMS_USERNAME"
value: "${CMS_USERNAME}"
}
[4]: {
name : "CMS_PASSWORD"
value: "${CMS_PASSWORD}"
}
]
}
}
}
adamant-solstice-35288
12/04/2024, 5:49 PMred-match-15116
12/04/2024, 5:52 PMpulumi.interpolate`pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets.value > sync.json`
writes the value of the secret to sync.json
And this line:
pulumi.interpolate`pulumi config set -s ${fullyQualifiedStackName} secretName $(pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets.name)`
creates a configuration key called secretName
and sets it to the name of the secret.
And then in target/index.ts it takes that secret name and value and pushes it to github.red-match-15116
12/04/2024, 5:52 PMred-match-15116
12/04/2024, 5:53 PMindex.ts
to this:
preRunCommands: [
"pulumi login",
pulumi.interpolate`pulumi config env add ${projectName}/${env.name} -s ${fullyQualifiedStackName} --yes`,
pulumi.interpolate`pulumi env open ${fullyQualifiedEnvName} sync.githubSecrets > sync.json`,
],
adamant-solstice-35288
12/04/2024, 5:54 PMred-match-15116
12/04/2024, 5:54 PMadamant-solstice-35288
12/04/2024, 5:55 PMred-match-15116
12/04/2024, 5:58 PMadamant-solstice-35288
12/04/2024, 5:59 PMred-match-15116
12/04/2024, 6:00 PMtarget/index.ts
to something like this:
import * as pulumi from "@pulumi/pulumi";
import * as github from "@pulumi/github";
import * as fs from "fs";
const config = new pulumi.Config();
const repository = config.require("repository");
const json = fs.readFileSync("sync.json", "utf8");
const secrets = JSON.parse(json);
for (const {name, value} of secrets) {
const secret = new github.ActionsSecret(`githubSecret-${name}`, {
repository,
secretName: name,
plaintextValue: value,
});
}
red-match-15116
12/04/2024, 6:03 PMadamant-solstice-35288
12/04/2024, 6:16 PMsync:
githubSecrets:
- name: CMS_GITHUB_TOKEN
value: {CMS_GITHUB_TOKEN}
- name: CMS_REPO
value: {CMS_REPO}
removing it solved the issue 😅