Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Fix example programs, bring the tests back to green #4159

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion scripts/programs/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ else
fi

pushd "$programs_dir"
found_first_program=false

for dir in */; do
project="$(basename $dir)"

# Optionally test only selected examples by setting an ONLY_TEST="<example-path>"
# environment variable (e.g., ONLY_TEST="awsx-ecr-repository").
if [[ ! -z "$ONLY_TEST" && "$dir" != "$ONLY_TEST"* ]]; then
if [[ ! -z "$ONLY_TEST" && "$project" != "$ONLY_TEST"* ]]; then
continue
fi

# Optionally test only from the specified example forward by setting ONLY_TEST_FROM="<example-path>".
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor enhancement to make it easier to run the tests locally (so you don't have to sit through all of them again after making a fix).

if [[ ! -z "$ONLY_TEST_FROM" ]]; then
if [[ "$project" == "$ONLY_TEST_FROM"* && "$found_first_program" == false ]]; then
found_first_program=true
fi

if [ "$found_first_program" == false ]; then
continue
fi
fi

# Skip programs we know don't compile.

# API Gateway authorizer parameter `providerArns` is mistyped.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module aws-ec2-sg-nginx-server-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
4 changes: 3 additions & 1 deletion themes/default/static/programs/aws-eks-cluster-go/go.mod.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module aws-eks-cluster-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package myproject;

import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketPolicy;
import com.pulumi.aws.s3.inputs.BucketPolicyPolicyArgs;
import java.util.Map;
import com.pulumi.aws.s3.BucketPolicyArgs;
import static com.pulumi.codegen.internal.Serialization.*;

public class App {
public static void main(String[] args) {
Pulumi.run(ctx -> {
var bucket = new Bucket("myBucket");

var bucketArn = bucket.arn();
var policyDocument = bucketArn.apply(arn -> String.format("""
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "lambda.amazonaws.com"},
"Action": ["s3:PutObject", "s3:PutObjectAcl"],
"Resource": "%s/*"
}]
}""", arn));
var policyDocument = bucket.arn().applyValue(arn -> serializeJson(
Copy link
Contributor Author

@cnunciato cnunciato Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary because Java 11 doesn't support multiline strings specified in this way. We use serializeJson elsewhere for this, so I went with that for consistency.

jsonObject(
jsonProperty("Version", "2012-10-17"),
jsonProperty("Statement", jsonArray(jsonObject(
jsonProperty("Effect", "Allow"),
jsonProperty("Action", jsonArray("s3:PutObject", "s3:PutObjectAcl")),
jsonProperty("Principal", jsonObject(
jsonProperty("Service", "lambda.amazonaws.com")
)),
jsonProperty("Resource", arn + "/*")
)))
)
));

var bucketPolicy = new BucketPolicy("myBucketPolicy", BucketPolicyArgs.builder()
.bucket(bucket.id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@
s3_bucket = aws.s3.Bucket("myBucket")

# IAM Policy Document that allows the Lambda service to write to the S3 bucket
s3_bucket_policy_document = s3_bucket.arn.apply(lambda arn: json.dumps({
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "lambda.amazonaws.com"},
"Action": ["s3:PutObject", "s3:PutObjectAcl"],
"Resource": f"{arn}/*"
}]
}))
s3_bucket_policy_document = s3_bucket.arn.apply(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are just the result of running black on it.

lambda arn: json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"Service": "lambda.amazonaws.com"},
"Action": ["s3:PutObject", "s3:PutObjectAcl"],
"Resource": f"{arn}/*",
}
],
}
)
)

# Attach the policy to the bucket
s3_bucket_policy = aws.s3.BucketPolicy("myBucketPolicy",
s3_bucket_policy = aws.s3.BucketPolicy(
"myBucketPolicy",
bucket=s3_bucket.id,
policy=s3_bucket_policy_document,
)

# Export the names and ARNs of the created resources
pulumi.export('bucket_name', s3_bucket.id)
pulumi.export('bucket_arn', s3_bucket.arn)
pulumi.export("bucket_name", s3_bucket.id)
pulumi.export("bucket_arn", s3_bucket.arn)
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ resources:
properties:
bucket: ${myBucket.id}
policy:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
Action:
- "s3:PutObject"
- "s3:PutObjectAcl"
Resource:
Fn::Sub: "${myBucket.arn}/*"
fn::toJSON:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was failing as well on a YAML-related syntax error.

Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
Action:
- "s3:PutObject"
- "s3:PutObjectAcl"
Resource: "${myBucket.arn}/*"

outputs:
bucket_name:
value: ${myBucket.id}
bucket_arn:
value: ${myBucket.arn}
bucket_name: ${myBucket.id}
Copy link
Contributor Author

@cnunciato cnunciato Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export value wrappers here, so since the other examples don't use them, we can remove them.

bucket_arn: ${myBucket.arn}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module myproject

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-load-balanced-ec2-instances-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-load-balanced-fargate-nginx-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-load-balanced-fargate-nginx-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
4 changes: 3 additions & 1 deletion themes/default/static/programs/awsx-vpc-azs-go/go.mod.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-azs-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
4 changes: 3 additions & 1 deletion themes/default/static/programs/awsx-vpc-cidr-go/go.mod.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-cidr-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-default-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-fargate-service-yaml

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
4 changes: 3 additions & 1 deletion themes/default/static/programs/awsx-vpc-go/go.mod.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-nat-gateways-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-security-groups-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
4 changes: 3 additions & 1 deletion themes/default/static/programs/awsx-vpc-sg-ec2-go/go.mod.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-sg-ec2-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module awsx-vpc-subnets-go

go 1.20
go 1.21

toolchain go1.21.9

require (
github.com/pulumi/pulumi-awsx/sdk/v2 v2.4.0
Expand Down
Loading