-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch lambda to allow imports (#3420)
Should address #2392 We regressed in our handling of imported lambdas in 5.28, when we picked up upstream https://github.com/hashicorp/terraform-provider-aws/releases/tag/v4.51.0 with https://github.com/hashicorp/terraform-provider-aws/pull/28963/files, which introduces the `ExactlyOneOf` constraints in the lambda resource. This PR reverts the upstream `ExactlyOneOf` constraints and replaces them with the previously applied `ConflictsWith`. This in turn allows imports of lambdas via `pulumi import` and the `import` resource option to work properly. I've added a GRPC test for a lambda imported via `pulumi import` as well as an integration test for a lambda imported via the `import` resource option and a test which checks that we still fail to create lambdas without any code-related properties (which should be the only case that now passes the validation step which previously didn't). Note that this slightly worsens the behaviour in the case when none of the code-related properties are specified. Previously that'd tirgger a failure during `Check` and print a sensible error message but now we will fail during `Create` with the following much less legible error: ``` aws:lambda:Function (testLambda): error: 1 error occurred: * creating Lambda Function (testLambda-e9e5e22): operation error Lambda: CreateFunction, https response error StatusCode: 400, RequestID: 88b5f9d7-42d6-4a3b-becc-96cdf954f596, api error ValidationException: 2 validation errors detected: Value '' at 'code.s3Key' failed to satisfy constraint: Member must have length greater than or equal to 1; Value '' at 'code.s3Bucket' failed to satisfy constraint: Member must have length greater than or equal to 3 ``` I don't see a sensible way around it though and I think the change is still worthwhile. Summary of effects: | | <5.28 | 5.28-6.22 | This PR | | :------------- | :-------: | :----:| :-------:| | pulumi import | works? | doesn't work | works| | import option | works |doesn't work | works| | no code lambda| errors during update?| errors during validation | errors during update | | other lambdas| works| works | works |
- Loading branch information
1 parent
32a25bf
commit d80e951
Showing
12 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: lambda-import-ts | ||
runtime: nodejs | ||
description: A minimal AWS TypeScript Pulumi program | ||
config: | ||
pulumi:tags: | ||
value: | ||
pulumi:template: aws-typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as archive from "@pulumi/archive"; | ||
import * as aws from "@pulumi/aws"; | ||
|
||
const config = new pulumi.Config(); | ||
const imported_lambda_name = config.get("lambda_name"); | ||
const imported_lambda_role = config.get("lambda_role"); | ||
|
||
const runtime = config.get("runtime"); | ||
|
||
const assumeRole = aws.iam.getPolicyDocument({ | ||
statements: [{ | ||
effect: "Allow", | ||
principals: [{ | ||
type: "Service", | ||
identifiers: ["lambda.amazonaws.com"], | ||
}], | ||
actions: ["sts:AssumeRole"], | ||
}], | ||
}); | ||
const iamForLambda = new aws.iam.Role("iamForLambda", {assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json)}); | ||
const lambda = archive.getFile({ | ||
type: "zip", | ||
sourceFile: "lambda.js", | ||
outputPath: "lambda_function_payload.zip", | ||
}); | ||
|
||
const testLambda = new aws.lambda.Function("testLambda", { | ||
name: imported_lambda_name, | ||
code: imported_lambda_name ? undefined : new pulumi.asset.FileArchive("lambda_function_payload.zip"), | ||
role: imported_lambda_role || iamForLambda.arn, | ||
handler: "index.test", | ||
runtime: runtime || "nodejs18.x", | ||
environment: { | ||
variables: { | ||
foo: "bar", | ||
}, | ||
}, | ||
}, imported_lambda_name ? { | ||
import: imported_lambda_name, ignoreChanges: ["code", "filename", "s3_bucket", "source_code_hash", "image_uri"] | ||
} : undefined); | ||
|
||
export const lambda_name = testLambda.name; | ||
export const lambda_role = testLambda.role; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("hi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "lambda-import-ts", | ||
"main": "index.ts", | ||
"devDependencies": { | ||
"@types/node": "^18" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/aws": "5.28.0", | ||
"@pulumi/awsx": "^2.0.2", | ||
"@pulumi/archive": "^0.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: no-code-lambda | ||
runtime: yaml | ||
description: A minimal AWS Pulumi YAML program | ||
config: | ||
pulumi:tags: | ||
value: | ||
pulumi:template: aws-yaml | ||
resources: | ||
iamForLambda: | ||
type: aws:iam:Role | ||
properties: | ||
assumeRolePolicy: ${assumeRole.json} | ||
testLambda: | ||
type: aws:lambda:Function | ||
properties: | ||
role: ${iamForLambda.arn} | ||
handler: index.test | ||
runtime: nodejs18.x | ||
environment: | ||
variables: | ||
foo: bar | ||
variables: | ||
assumeRole: | ||
fn::invoke: | ||
Function: aws:iam:getPolicyDocument | ||
Arguments: | ||
statements: | ||
- effect: Allow | ||
principals: | ||
- type: Service | ||
identifiers: | ||
- lambda.amazonaws.com | ||
actions: | ||
- sts:AssumeRole |
Oops, something went wrong.