From 450f0d9e919aeed5cf0c8d2fa0219540af11c500 Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Thu, 2 May 2024 16:16:35 -0400 Subject: [PATCH] Fixes errors and resource cycling issues for aws.batch.JobDefinition (#3888) Recent changes in hashicorp/terraform-provider-aws#37111 introduced a Diff customizer that leads to errors in the Pulumi version of the provider due to discrepancies in the order in which Diff customizer functions are applied between Pulumi and Terraform. This change fixes the problem by applying the experimental PlanResourceChange flag to the affected resource. Fixes https://github.com/pulumi/pulumi-aws/issues/3887 A regression test is included. See also: https://github.com/pulumi/pulumi-terraform-bridge/issues/1785 --- provider/provider_python_test.go | 24 ++++++++ provider/resources.go | 3 +- .../test-programs/regress-3887/Pulumi.yaml | 5 ++ .../test-programs/regress-3887/__main__.py | 55 +++++++++++++++++++ .../regress-3887/requirements.txt | 2 + .../regress-3887/step-1/__main__.py | 55 +++++++++++++++++++ .../regress-3887/step-2/__main__.py | 55 +++++++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 provider/test-programs/regress-3887/Pulumi.yaml create mode 100644 provider/test-programs/regress-3887/__main__.py create mode 100644 provider/test-programs/regress-3887/requirements.txt create mode 100644 provider/test-programs/regress-3887/step-1/__main__.py create mode 100644 provider/test-programs/regress-3887/step-2/__main__.py diff --git a/provider/provider_python_test.go b/provider/provider_python_test.go index 4d4633fe55e..82022d16e80 100644 --- a/provider/provider_python_test.go +++ b/provider/provider_python_test.go @@ -36,6 +36,30 @@ func TestRegress3196(t *testing.T) { }) } +func TestRegress3887(t *testing.T) { + if testing.Short() { + t.Skipf("Skipping test in -short mode because it needs cloud credentials") + return + } + test := getPythonBaseOptions(t). + With(integration.ProgramTestOptions{ + Quick: true, + SkipRefresh: true, + Dir: filepath.Join("test-programs", "regress-3887"), + EditDirs: []integration.EditDir{ + { + Dir: filepath.Join("test-programs", "regress-3887", "step-1"), + Additive: true, + }, + { + Dir: filepath.Join("test-programs", "regress-3887", "step-2"), + Additive: true, + }, + }, + }) + integration.ProgramTest(t, &test) +} + func TestRegress1504(t *testing.T) { if testing.Short() { t.Skipf("Skipping test in -short mode because it needs cloud credentials") diff --git a/provider/resources.go b/provider/resources.go index 1250741fab9..1f76f8a6be1 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -803,7 +803,8 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo { switch s { case "aws_ssm_document", "aws_wafv2_web_acl", - "aws_launch_template": + "aws_launch_template", + "aws_batch_job_definition": return true default: return false diff --git a/provider/test-programs/regress-3887/Pulumi.yaml b/provider/test-programs/regress-3887/Pulumi.yaml new file mode 100644 index 00000000000..916e25eedbf --- /dev/null +++ b/provider/test-programs/regress-3887/Pulumi.yaml @@ -0,0 +1,5 @@ +name: regress-3887 +runtime: + name: python + options: + virtualenv: venv diff --git a/provider/test-programs/regress-3887/__main__.py b/provider/test-programs/regress-3887/__main__.py new file mode 100644 index 00000000000..ddf975e3016 --- /dev/null +++ b/provider/test-programs/regress-3887/__main__.py @@ -0,0 +1,55 @@ +import json +import pulumi_aws as aws + +test = aws.batch.JobDefinition( + "test", + name="my_test_batch_job_definition", + type="container", + container_properties=json.dumps( + { + "command": [ + "ls", + "-la", + ], + "image": "busybox", + "resourceRequirements": [ + { + "type": "VCPU", + "value": "1", + }, + { + "type": "MEMORY", + "value": "512", + }, + ], + "volumes": [ + { + "host": { + "sourcePath": "/tmp", + }, + "name": "tmp", + } + ], + "environment": [ + { + "name": "VARNAME", + "value": "VARVAL", + } + ], + "mountPoints": [ + { + "sourceVolume": "tmp", + "containerPath": "/tmp", + "readOnly": False, + } + ], + "ulimits": [ + { + "hardLimit": 1024, + "name": "nofile", + "softLimit": 1024, + } + ], + } + ), +) diff --git a/provider/test-programs/regress-3887/requirements.txt b/provider/test-programs/regress-3887/requirements.txt new file mode 100644 index 00000000000..e032db624ae --- /dev/null +++ b/provider/test-programs/regress-3887/requirements.txt @@ -0,0 +1,2 @@ +pulumi>=3.0.0,<4.0.0 +pulumi_aws>=6.0.0,<7.0.0 diff --git a/provider/test-programs/regress-3887/step-1/__main__.py b/provider/test-programs/regress-3887/step-1/__main__.py new file mode 100644 index 00000000000..5dfe7c692ae --- /dev/null +++ b/provider/test-programs/regress-3887/step-1/__main__.py @@ -0,0 +1,55 @@ +import json +import pulumi_aws as aws + +test = aws.batch.JobDefinition( + "test", + name="my_test_batch_job_definition", + type="container", + container_properties=json.dumps( + { + "command": [ + "ls", + "-la", + ], + "image": "busybox", + "resourceRequirements": [ + { + "type": "VCPU", + "value": "2", + }, + { + "type": "MEMORY", + "value": "512", + }, + ], + "volumes": [ + { + "host": { + "sourcePath": "/tmp", + }, + "name": "tmp", + } + ], + "environment": [ + { + "name": "VARNAME", + "value": "VARVAL", + } + ], + "mountPoints": [ + { + "sourceVolume": "tmp", + "containerPath": "/tmp", + "readOnly": False, + } + ], + "ulimits": [ + { + "hardLimit": 1024, + "name": "nofile", + "softLimit": 1024, + } + ], + } + ), +) diff --git a/provider/test-programs/regress-3887/step-2/__main__.py b/provider/test-programs/regress-3887/step-2/__main__.py new file mode 100644 index 00000000000..cf33747f1f7 --- /dev/null +++ b/provider/test-programs/regress-3887/step-2/__main__.py @@ -0,0 +1,55 @@ +import json +import pulumi_aws as aws + +test = aws.batch.JobDefinition( + "test", + name="my_test_batch_job_definition", + type="container", + container_properties=json.dumps( + { + "command": [ + "ls", + "-la", + ], + "image": "busybox", + "resourceRequirements": [ + { + "type": "VCPU", + "value": "3", + }, + { + "type": "MEMORY", + "value": "512", + }, + ], + "volumes": [ + { + "host": { + "sourcePath": "/tmp", + }, + "name": "tmp", + } + ], + "environment": [ + { + "name": "VARNAME", + "value": "VARVAL", + } + ], + "mountPoints": [ + { + "sourceVolume": "tmp", + "containerPath": "/tmp", + "readOnly": False, + } + ], + "ulimits": [ + { + "hardLimit": 1024, + "name": "nofile", + "softLimit": 1024, + } + ], + } + ), +)