Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume EC2 Instance panic fix and address perpetual diff #1625

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions config/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/upjet/pkg/config"
"github.com/crossplane/upjet/pkg/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -142,3 +143,31 @@ func RemovePolicyVersion(p string) (string, error) {
r, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(m)
return string(r), errors.Wrap(err, "failed to marshal the policy map as JSON")
}

// RemoveDiffIfEmpty removes supplied keys from Terraform diffs, if old and new
// values for the key are empty (""). It is probably safe to delete all such
// keys in the diff. Until we decide to do so, we'll specify the keys, to be on
// the safe side.
func RemoveDiffIfEmpty(keys []string) config.CustomDiff { //nolint:gocyclo // The implementation is pretty straightforward as of this writing.
return func(diff *terraform.InstanceDiff, state *terraform.InstanceState, config *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
// Skip diff customization on create
if state == nil || state.Empty() {
return diff, nil
}
if config == nil {
return nil, errors.New("resource config cannot be nil")
}
// Skip no diff or destroy diffs
if diff == nil || diff.Empty() || diff.Destroy || diff.Attributes == nil {
return diff, nil
}

for _, key := range keys {
if diff.Attributes[key] != nil && diff.Attributes[key].Old == "" && diff.Attributes[key].New == "" {
delete(diff.Attributes, key)
}
}

return diff, nil
}
}
3 changes: 3 additions & 0 deletions config/ec2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func Configure(p *config.Provider) { //nolint:gocyclo
"cpu_threads_per_core",
},
}
r.TerraformCustomDiff = common.RemoveDiffIfEmpty([]string{
"volume_tags.%",
})
config.MoveToStatus(r.TerraformResource, "security_groups")
})
p.AddResourceConfigurator("aws_eip", func(r *config.Resource) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,4 @@ require (
// copied from the Terraform provider
replace github.com/hashicorp/terraform-plugin-log => github.com/gdavison/terraform-plugin-log v0.0.0-20230928191232-6c653d8ef8fb

replace github.com/hashicorp/terraform-provider-aws => github.com/upbound/terraform-provider-aws v0.0.0-20241203141151-997a60ec5360
replace github.com/hashicorp/terraform-provider-aws => github.com/upbound/terraform-provider-aws v0.0.0-20250102143213-c0eb96154778
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ=
github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w=
github.com/upbound/terraform-provider-aws v0.0.0-20241203141151-997a60ec5360 h1:HLrTYw0kB74C7JMNM5dUe0h7V2nzvdSMzciWmsJCUvQ=
github.com/upbound/terraform-provider-aws v0.0.0-20241203141151-997a60ec5360/go.mod h1:7l6VnUvAF/LY5jcEABkfHuK8gAkOODwTT1TcGpy+tl0=
github.com/upbound/terraform-provider-aws v0.0.0-20250102143213-c0eb96154778 h1:RxW17Zn9BdCvSSeB7LGOZCoJJYO1d4VDvrdPmSRP5G8=
github.com/upbound/terraform-provider-aws v0.0.0-20250102143213-c0eb96154778/go.mod h1:7l6VnUvAF/LY5jcEABkfHuK8gAkOODwTT1TcGpy+tl0=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
Loading