Skip to content

Commit

Permalink
Fix v6 job queue migration (#3091)
Browse files Browse the repository at this point in the history
Fixes #3075

The problem was that the tf migration didn't migrate the ARN property of
the job queue resource.

Looks like this isn't a problem for tf programs, likely because tf does
a refresh during update.

This PR adds a patch and an upgrade test for this.

---------

Co-authored-by: Anton Tayanovskyy <[email protected]>
  • Loading branch information
VenelinMartinov and t0yv0 authored Dec 5, 2023
1 parent c092200 commit 5029829
Show file tree
Hide file tree
Showing 8 changed files with 910 additions and 0 deletions.
12 changes: 12 additions & 0 deletions patches/0032-Fix-job-queue-sdkv2-migration.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/internal/service/batch/job_queue_schema.go b/internal/service/batch/job_queue_schema.go
index bd19814922..11cf093ece 100644
--- a/internal/service/batch/job_queue_schema.go
+++ b/internal/service/batch/job_queue_schema.go
@@ -92,6 +92,7 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, req resource.Upgrad
}

jobQueueDataV2 := resourceJobQueueData{
+ ARN: jobQueueDataV0.ARN,
ComputeEnvironments: jobQueueDataV0.ComputeEnvironments,
ID: jobQueueDataV0.ID,
Name: jobQueueDataV0.Name,
34 changes: 34 additions & 0 deletions provider/provider_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
package provider

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/pulumi/providertest"
"github.com/stretchr/testify/assert"
)

func TestLambdaLayerNew(t *testing.T) {
Expand All @@ -33,6 +35,29 @@ func TestRoute53(t *testing.T) {
nodeTest(t, filepath.Join("..", "examples", "route53"))
}

func TestJobQueue(t *testing.T) {
simpleNodeTest(t, filepath.Join("test-programs", "job-queue"),
providertest.WithSkippedUpgradeTestMode(providertest.UpgradeTestMode_Quick, "Prefer PreviewOnly"),
providertest.WithDiffValidation(func(t *testing.T, d providertest.Diffs) {
for _, diff := range d {
if diff.URN.Name() != "testQueue" {
continue
}
assert.Emptyf(t, diff.Replaces, "Unexpected replace plan for testQueue")
for _, changedProp := range diff.Diffs {
// Ignoring benign update from nil to empty-map tags.
if changedProp == "tags" {
continue
}
if changedProp == "tagsAll" {
continue
}
assert.Fail(t, fmt.Sprintf("Unexpected update for testQueue: %s", changedProp))
}
}
}))
}

func nodeTest(t *testing.T, dir string, opts ...providertest.Option) {
envRegion := getEnvRegion(t)
opts = append(opts,
Expand All @@ -42,6 +67,15 @@ func nodeTest(t *testing.T, dir string, opts ...providertest.Option) {
test(t, dir, opts...)
}

// This version of nodeTest does not aws:region INVALID_REGION manipulation.
func simpleNodeTest(t *testing.T, dir string, opts ...providertest.Option) {
envRegion := getEnvRegion(t)
opts = append(opts,
providertest.WithConfig("aws:region", envRegion),
)
test(t, dir, opts...)
}

func getEnvRegion(t *testing.T) string {
envRegion := os.Getenv("AWS_REGION")
if envRegion == "" {
Expand Down
3 changes: 3 additions & 0 deletions provider/test-programs/job-queue/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: job-queue
description: Job Queue
runtime: nodejs
82 changes: 82 additions & 0 deletions provider/test-programs/job-queue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as aws from "@pulumi/aws";

const ec2AssumeRole = aws.iam.getPolicyDocument({
statements: [{
actions: ["sts:AssumeRole"],
effect: "Allow",
principals: [{
identifiers: ["ec2.amazonaws.com"],
type: "Service",
}],
}],
});

const ecsInstanceRole = new aws.iam.Role("ecsInstanceRoleRole", {
assumeRolePolicy: ec2AssumeRole.then(policy => policy.json),
});

const ecsPolicyAttachment = new aws.iam.RolePolicyAttachment("ecsInstanceRoleRolePolicyAttachment", {
role: ecsInstanceRole.name,
policyArn: "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role",
});

const ecsInstanceProfile = new aws.iam.InstanceProfile("ecsInstanceRoleInstanceProfile", {
role: ecsInstanceRole.name,
});

const batchAssumeRole = aws.iam.getPolicyDocument({
statements: [{
actions: ["sts:AssumeRole"],
effect: "Allow",
principals: [{
identifiers: ["batch.amazonaws.com"],
type: "Service",
}],
}],
});

const batchRole = new aws.iam.Role("awsBatchServiceRoleRole", {
assumeRolePolicy: batchAssumeRole.then(policy => policy.json),
});

const batchPolicyAttachment = new aws.iam.RolePolicyAttachment("awsBatchServiceRoleRolePolicyAttachment", {
role: batchRole.name,
policyArn: "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole",
});

const sg = new aws.ec2.SecurityGroup("sampleSecurityGroup", {
egress: [{
cidrBlocks: ["0.0.0.0/0"],
fromPort: 0,
protocol: "-1",
toPort: 0,
}],
});

const vpc = new aws.ec2.Vpc("sampleVpc", { cidrBlock: "10.1.0.0/16" });

const subnet = new aws.ec2.Subnet("sampleSubnet", {
cidrBlock: "10.1.1.0/24",
vpcId: vpc.id,
});

const computeEnvironment = new aws.batch.ComputeEnvironment("sampleComputeEnvironment", {
computeResources: {
instanceRole: ecsInstanceProfile.arn,
instanceTypes: ["c4.large"],
maxVcpus: 16,
minVcpus: 0,
securityGroupIds: [sg.id],
subnets: [subnet.id],
type: "EC2",
},
serviceRole: batchRole.arn,
type: "MANAGED",
});


const jobQueue = new aws.batch.JobQueue("testQueue", {
computeEnvironments: [computeEnvironment.arn],
priority: 1,
state: "ENABLED",
});
15 changes: 15 additions & 0 deletions provider/test-programs/job-queue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "job-queue",
"version": "0.1.0",
"license": "Apache-2.0",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@pulumi/pulumi": "^3.0.0",
"@pulumi/aws": "^5.0.0"
},
"devDependencies": {
"@types/node": "^8.0.0"
}
}
18 changes: 18 additions & 0 deletions provider/test-programs/job-queue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}
Loading

0 comments on commit 5029829

Please sign in to comment.