Skip to content

Commit

Permalink
fix: get rid of warning - value for undeclared variable
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehan committed Dec 21, 2023
1 parent 932e5a0 commit 67a1bb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
5 changes: 5 additions & 0 deletions lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,9 @@ export class GithubRepositoryFromExistingRepository extends Construct {
repository: this.resource,
});
}

addSecret(name: string) {
const variable = new SecretFromVariable(this, name);
variable.for(this.resource, this.provider);
}
}
49 changes: 25 additions & 24 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type StackShards = {
};

const allProviders: Record<string, string> = JSON.parse(
fs.readFileSync(path.join(__dirname, "provider.json"), "utf8")
fs.readFileSync(path.join(__dirname, "provider.json"), "utf8"),
);

const shardedStacks: StackShards = JSON.parse(
fs.readFileSync(path.join(__dirname, "sharded-stacks.json"), "utf8")
fs.readFileSync(path.join(__dirname, "sharded-stacks.json"), "utf8"),
);

interface GitUrls {
Expand All @@ -60,8 +60,8 @@ function getShardedStackProviders(name: string): Record<string, string> {

return Object.fromEntries(
Object.entries(allProviders).filter(([key]) =>
stackProvidersList.includes(key)
)
stackProvidersList.includes(key),
),
);
}

Expand Down Expand Up @@ -100,13 +100,13 @@ class TerraformCdkProviderStack extends TerraformStack {
this.createRepositoryManagerRepo(
slackWebhook,
githubProvider,
githubTeam
githubTeam,
);
this.createProviderProjectRepo(
slackWebhook,
secrets.npmSecret,
githubProvider,
githubTeam
githubTeam,
);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ class TerraformCdkProviderStack extends TerraformStack {
slackWebhook: TerraformVariable,
npmSecret: SecretFromVariable,
githubProvider: GithubProvider,
githubTeam: DataGithubTeam
githubTeam: DataGithubTeam,
) {
const templateRepository = new GithubRepository(
this,
Expand All @@ -166,7 +166,7 @@ class TerraformCdkProviderStack extends TerraformStack {
team: githubTeam,
webhookUrl: slackWebhook.stringValue,
provider: githubProvider,
}
},
);

npmSecret.for(templateRepository.resource, githubProvider);
Expand All @@ -179,7 +179,7 @@ class TerraformCdkProviderStack extends TerraformStack {
private createRepositoryManagerRepo(
slackWebhook: TerraformVariable,
githubProvider: GithubProvider,
githubTeam: DataGithubTeam
githubTeam: DataGithubTeam,
) {
const selfTokens = [
new SecretFromVariable(this, "tf-cloud-token"),
Expand All @@ -202,13 +202,13 @@ class TerraformCdkProviderStack extends TerraformStack {
private validateProviderNames(providers: Record<string, string>) {
// validate that providers contain only valid names (-go suffix is forbidden)
const goSuffixProviders = Object.keys(providers).filter((key) =>
key.endsWith("-go")
key.endsWith("-go"),
);
if (goSuffixProviders.length > 0) {
Annotations.of(this).addError(
`Providers contain a provider key with a suffix -go which is not allowed due to conflicts with go package repositories. Please remove the -go suffix from these provider keys ${goSuffixProviders.join(
", "
)}`
", ",
)}`,
);
}

Expand All @@ -222,13 +222,13 @@ class TerraformCdkProviderStack extends TerraformStack {

const sanitizedProviderName = providerName.replace(/-/g, "");
return key !== sanitizedProviderName;
}
},
);
if (notMatchingProviders.length > 0) {
Annotations.of(this).addError(
`Provider name and provider key do not match for ${notMatchingProviders.join(
", "
)}. This leads to issues when deploying go packages. Please rename the provider key to match the provider name.`
", ",
)}. This leads to issues when deploying go packages. Please rename the provider key to match the provider name.`,
);
}
}
Expand All @@ -242,7 +242,7 @@ class CustomConstructsStack extends TerraformStack {
name: string;
languages: ("typescript" | "python" | "csharp" | "java" | "go")[];
topics?: string[];
}[]
}[],
) {
super(scope, name);
const githubProvider = new GithubProvider(this, "github-provider-cdktf", {
Expand Down Expand Up @@ -275,10 +275,10 @@ class CustomConstructsStack extends TerraformStack {
language === "typescript"
? "js"
: language === "csharp"
? "dotnet"
: language
? "dotnet"
: language
}`;
})
}),
);

const repo = new GithubRepositoryFromExistingRepository(
Expand All @@ -291,7 +291,7 @@ class CustomConstructsStack extends TerraformStack {
provider: githubProvider,
protectMain: true,
protectMainChecks,
}
},
);

secrets.forGitHub(repo.resource, githubProvider);
Expand Down Expand Up @@ -320,6 +320,7 @@ class CustomConstructsStack extends TerraformStack {
provider: githubProvider,
});
}
repo.addSecret("alert-prs-slack-webhook-url"); // this isn't used, but without it we get a warning on the plan, so just add this to shut TF up
});
}
}
Expand All @@ -337,10 +338,10 @@ const allProviderNames = Object.keys(allProviders);
const shardProviderSet = new Set(allProvidersInShards);
const allProviderSet = new Set(allProviderNames);
const missingProvidersInShards = new Set(
[...allProviderSet].filter((provider) => !shardProviderSet.has(provider))
[...allProviderSet].filter((provider) => !shardProviderSet.has(provider)),
);
const missingProvidersInAllProviders = new Set(
[...shardProviderSet].filter((provider) => !allProviderSet.has(provider))
[...shardProviderSet].filter((provider) => !allProviderSet.has(provider)),
);

if (shardProviderSet.size < allProvidersInShards.length) {
Expand All @@ -351,15 +352,15 @@ if (missingProvidersInShards.size > 0) {
throw new Error(
`One or more providers present in provider.json are missing in sharded-stacks.json: ${[
...missingProvidersInShards,
]}`
]}`,
);
}

if (missingProvidersInAllProviders.size > 0) {
throw new Error(
`One or more providers present in sharded-stacks.json are missing in provider.json: ${[
...missingProvidersInAllProviders,
]}`
]}`,
);
}

Expand Down

0 comments on commit 67a1bb0

Please sign in to comment.