-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix migrating batch.ComputeEnvironment from v5 to v6 of the provider (#…
…4019) Although the upstream schema of batch.ComputeEnvironment did not change between v5 and v6 of pulumi-aws, the Pulumi schema did, and computeResources.ec2Configuration is now an array. Prior to this change pulumi-aws v6 was not able to read the states written by the v5 of the provider correctly, if those states did involve a non-nil computeResources.ec2Configuration. In some of the recent bridge work this also interacted poorly with the new PlanResourceChange machinery causing panics. The change makes the provider automatically apply `x -> [x]` conversions to computeResources.ec2Configuration state. Fixes #4015
- Loading branch information
Showing
5 changed files
with
100 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package batch | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens" | ||
) | ||
|
||
func ComputeEnvironment(token tokens.Type) *info.Resource { | ||
return &info.Resource{ | ||
Tok: token, | ||
TransformFromState: func(ctx context.Context, pm resource.PropertyMap) (resource.PropertyMap, error) { | ||
// computeResources.ec2Configurations should be a list | ||
// older versions of the provider like 5.42.0 used to write it out as an object | ||
r := pm.Copy() | ||
cr, ok := r["computeResources"] | ||
if !ok || !cr.IsObject() { | ||
return pm, nil | ||
} | ||
ec2c, ok := cr.ObjectValue()["ec2Configuration"] | ||
if !ok || !ec2c.IsObject() { | ||
return pm, nil | ||
} | ||
replacement := resource.NewArrayProperty([]resource.PropertyValue{ec2c}) | ||
tfbridge.GetLogger(ctx).Debug(fmt.Sprintf( | ||
"batch.ComputeEnvironment is wrapping old computeResources.ec2Configurations state in an array")) | ||
cr.ObjectValue()["ec2Configuration"] = replacement | ||
r["computeResources"] = cr | ||
return r, nil | ||
}, | ||
} | ||
} |
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,36 @@ | ||
package batch | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/unstable/logging" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestComputeEnvironmentTransformFromState(t *testing.T) { | ||
ctx := context.Background() | ||
ctx = logging.InitLogging(ctx, logging.LogOptions{}) | ||
pm := resource.PropertyMap{ | ||
"computeResources": resource.NewObjectProperty(resource.PropertyMap{ | ||
"ec2Configuration": resource.NewObjectProperty(resource.PropertyMap{ | ||
"imageIdOverride": resource.NewStringProperty(""), | ||
"imageType": resource.NewStringProperty("ECS_AL2"), | ||
}), | ||
}), | ||
} | ||
expect := resource.PropertyMap{ | ||
"computeResources": resource.NewObjectProperty(resource.PropertyMap{ | ||
"ec2Configuration": resource.NewArrayProperty([]resource.PropertyValue{ | ||
resource.NewObjectProperty(resource.PropertyMap{ | ||
"imageIdOverride": resource.NewStringProperty(""), | ||
"imageType": resource.NewStringProperty("ECS_AL2"), | ||
}), | ||
}), | ||
}), | ||
} | ||
actual, err := ComputeEnvironment("").TransformFromState(ctx, pm) | ||
require.NoError(t, err) | ||
require.Equal(t, expect, actual) | ||
} |
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