Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codepipeline-actions: Github connection, allow Token values #27100

Closed
Nikola-Milovic opened this issue Sep 11, 2023 · 3 comments · Fixed by #27109
Closed

codepipeline-actions: Github connection, allow Token values #27100

Nikola-Milovic opened this issue Sep 11, 2023 · 3 comments · Fixed by #27109
Labels
@aws-cdk/aws-codepipeline-actions bug This issue is a bug. documentation This is a problem with documentation. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@Nikola-Milovic
Copy link
Contributor

Describe the bug

While setting up an AWS CDK pipeline using the pipelines.CodePipelineSource.connection method, I encountered an error indicating that the Step id cannot be unresolved. Specifically, it failed on a tokenized value ${Token[TOKEN.653]}/${Token[TOKEN.656]}, which seems to be originating from the SSM parameters githubOwner and githubRepo.

Expected Behavior

The AWS CDK pipeline should be able to resolve and handle the tokenized values from SSM parameters seamlessly, without throwing an error related to the unresolved Step id.

Current Behavior

When trying to synthesize the pipeline stack, the process fails with the error message:

You are about to destroy the CDK environment to dev, using profile project-dev.
Are you sure? (yes/no): yes
project/deployment/node_modules/aws-cdk-lib/pipelines/lib/blueprint/step.js:1
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Step=void 0;const jsiiDeprecationWarnings=require("../../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../../core"),step_output_1=
require("../helpers-internal/step-output");class Step{static sequence(steps){for(let i=1;i<steps.length;i++)steps[i].addStepDependency(steps[i-1]);return steps}constructor(id){if(this.id=id,this.dependencyFileSets=[],this.isSource=!1,this._dependencies
=new Set,core_1.Token.isUnresolved(id))throw new Error(`Step id cannot be unresolved, got '${id}'`)}get dependencies(){return Array.from(new Set([...this.dependencyFileSets.map(f=>f.producer),...this._dependencies]))}toString(){return`${this.constructo
r.name}(${this.id})`}get primaryOutput(){return this._primaryOutput}addStepDependency(step){try{jsiiDeprecationWarnings.aws_cdk_lib_pipelines_Step(step)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStac
kTrace(error,this.addStepDependency),error}this._dependencies.add(step)}addDependencyFileSet(fs){try{jsiiDeprecationWarnings.aws_cdk_lib_pipelines_FileSet(fs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captu
reStackTrace(error,this.addDependencyFileSet),error}this.dependencyFileSets.push(fs)}configurePrimaryOutput(fs){try{jsiiDeprecationWarnings.aws_cdk_lib_pipelines_FileSet(fs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationErro
r"&&Error.captureStackTrace(error,this.configurePrimaryOutput),error}this._primaryOutput=fs}discoverReferencedOutputs(structure){for(const output of step_output_1.StepOutput.findAll(structure))this._dependencies.add(output.step),step_output_1.StepOutpu
t.recordProducer(output)}get consumedStackOutputs(){return[]}}exports.Step=Step,_a=JSII_RTTI_SYMBOL_1,Step[_a]={fqn:"aws-cdk-lib.pipelines.Step",version:"2.94.0"};

                                             ^
Error: Step id cannot be unresolved, got '${Token[TOKEN.653]}/${Token[TOKEN.656]}'
    at new Step (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/blueprint/step.js:1:550)
    at new CodePipelineSource (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.js:1:483)
    at new CodeStarConnectionSource (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.js:1:5010)
    at Function.connection (project/deployment/node_modules/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.js:1:1766)
    at new MasterPipeline (project/deployment/lib/master-pipeline.ts:29:54)
    at Object.<anonymous> (project/deployment/bin/deployment.ts:33:26)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (project/deployment/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (project/deployment/node_modules/ts-node/src/index.ts:1621:12)

Subprocess exited with error 1

Reproduction Steps

Set up an AWS CDK stack with parameters fetched from SSM.
Use these parameters in the pipelines.CodePipelineSource.connection method to define the source input.
Attempt to synthesize or deploy the stack.

export function getSSMParameter(scope: Construct, key: string): string {
  const value = StringParameter.valueForStringParameter(scope, key);
  if (!value) {
    throw new Error(`Parameter ${key} does not exist in SSM.`);
  }
  return value;
}

    const githubOwner = getSSMParameter(this, ParameterKeys.GithubOwner);
    const githubRepo = getSSMParameter(this, ParameterKeys.GithubRepo);
    const githubConnection = getSSMParameter(this, ParameterKeys.GithubConnectionArn);

    const artifactBucket = new s3.Bucket(this, "ArtifactBucket", {
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });

    const sourceInput = pipelines.CodePipelineSource.connection(
      `${githubOwner}/${githubRepo}`,
      getBranch(props.deployEnv),
      {
        connectionArn: githubConnection,
      },
    );

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.94.0

Framework Version

No response

Node.js Version

18.16.0

OS

Ubuntu 22.04

Language

Typescript

Language Version

Typescript ~5.0.3

Other information

Not really anything too important it was just weird that this wouldnt work.

Especially since a similar pattern can be used for source actions

		const sourceAction =
			new codepipeline_actions.CodeStarConnectionsSourceAction({
				actionName: "GitHubSource",
				output: this.sourceOutput,
				connectionArn: getSSMParameter(this, ParameterKeys.GithubConnectionArn),
				owner: getSSMParameter(this, ParameterKeys.GithubOwner),
				repo: getSSMParameter(this, ParameterKeys.GithubRepo),
				branch: getBranch(props.deployEnv),
			});
@Nikola-Milovic Nikola-Milovic added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 11, 2023
@peterwoodworth peterwoodworth added good first issue Related to contributions. See CONTRIBUTING.md p2 effort/small Small work item – less than a day of effort documentation This is a problem with documentation. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 11, 2023
@peterwoodworth
Copy link
Contributor

We need to be able to parse the value at runtime, this error is explicitly thrown by us if the values supplied are tokens

if (Token.isUnresolved(repoString) || parts.length !== 2) {

We don't call this out in the documentation, we need to add this to the repoString docstring

* @param repoString A string that encodes owner and repository separated by a slash (e.g. 'owner/repo').

@mergify mergify bot closed this as completed in #27109 Sep 13, 2023
mergify bot pushed a commit that referenced this issue Sep 13, 2023
…runtime (#27109)

This PR addresses an issue encountered when setting up an AWS CDK pipeline where unresolved token values for the `repoString` parameter led to a runtime error. The updated docstring now explicitly mentions that the `repoString` must be resolvable at runtime and that unresolved tokens are intended to be a runtime error

Closes #27100.

Thanks to @peterwoodworth for the quick assessment and the proposed solution to the problem.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mikewrighton pushed a commit that referenced this issue Sep 14, 2023
…runtime (#27109)

This PR addresses an issue encountered when setting up an AWS CDK pipeline where unresolved token values for the `repoString` parameter led to a runtime error. The updated docstring now explicitly mentions that the `repoString` must be resolvable at runtime and that unresolved tokens are intended to be a runtime error

Closes #27100.

Thanks to @peterwoodworth for the quick assessment and the proposed solution to the problem.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@igoodwinVolly
Copy link

I can confirm the same thing happens when using the code below to connect to a Bitbucket repo with cloudformation parameters that are tokenized (RepositoryName, Environment, ConnectionArn).

    // Parameters
    const Environment = new cdk.CfnParameter(this, "Environment", {
      type: "String",
      description: "The development environment / repository branch name.",
    })
    const RepositoryName = new cdk.CfnParameter(this, "RepositoryName", {
      type: "String",
      description: "The code source repository name.",
    })
    const RepositoryConnectionArn = new cdk.CfnParameter(this, "RepositoryConnectionArn", {
      type: "String",
      description: "The code source CodeStar connection Arn. The connection must be configured BEFORE deployment.",
    })

    // Resources
    const pipeline = new CodePipeline(this, "Pipeline", {
      pipelineName: `Deployment-Pipeline-${Environment.valueAsString}`,
      synth: new ShellStep("Synth", {
        input: CodePipelineSource.connection(RepositoryName.valueAsString, Environment.valueAsString, {
          connectionArn: RepositoryConnectionArn.valueAsString,
        }),
        commands: ["cdk synth"],
      }),
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline-actions bug This issue is a bug. documentation This is a problem with documentation. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants