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

Function type config.ConfigurationInjector now returns an error #1150

Merged
merged 3 commits into from
Feb 14, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export SUBPACKAGES := $(SUBPACKAGES)
KIND_VERSION = v0.21.0
UP_VERSION = v0.20.0
UP_CHANNEL = stable
UPTEST_VERSION = v0.8.0
UPTEST_VERSION = v0.11.0
KUSTOMIZE_VERSION = v5.3.0
YQ_VERSION = v4.40.5

Expand Down
3 changes: 2 additions & 1 deletion config/cloudformation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import "github.com/crossplane/upjet/pkg/config"
// Configure adds configurations for the cloudformation group.
func Configure(p *config.Provider) {
p.AddResourceConfigurator("aws_cloudformation_stack_set_instance", func(r *config.Resource) {
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) {
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) error {
params["region"] = jsonMap["region"]
return nil
}
})
}
6 changes: 4 additions & 2 deletions config/ec2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ func Configure(p *config.Provider) {
"source_security_group_id",
},
}
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) {
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) error {
// TODO: Has better be implemented via defaulting.
if _, ok := jsonMap["self"]; !ok {
params["self"] = false
}
return nil
}
})

Expand Down Expand Up @@ -423,12 +424,13 @@ func Configure(p *config.Provider) {
r.References["source_ami_id"] = config.Reference{
Type: "AMI",
}
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) {
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) error {
params["ebs_block_device"] = []any{}
// TODO: Has better be implemented via defaulting.
if _, ok := jsonMap["encrypted"]; !ok {
params["encrypted"] = false
}
return nil
}
r.TerraformCustomDiff = func(diff *terraform.InstanceDiff, _ *terraform.InstanceState, _ *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if diff != nil && diff.Attributes != nil {
Expand Down
6 changes: 4 additions & 2 deletions config/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ func Configure(p *config.Provider) {
"logging", "object_lock_configuration", "policy", "replication_configuration", "request_payer",
"server_side_encryption_configuration", "versioning", "website", "arn")
r.MetaResource.ExternalName = registry.RandRFC1123Subdomain
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) {
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) error {
params["region"] = jsonMap["region"]
// TODO: added to prevent extra reconciliations due to
// late-initialization or drift. Has better be implemented
// via defaulting.
if _, ok := jsonMap["forceDestroy"]; !ok {
params["force_destroy"] = false
}
return nil
}
})

Expand All @@ -73,11 +74,12 @@ func Configure(p *config.Provider) {
r.LateInitializer = config.LateInitializer{
IgnoredFields: []string{"etag", "kms_key_id"},
}
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) {
r.TerraformConfigurationInjector = func(jsonMap map[string]any, params map[string]any) error {
// TODO: Has better be implemented via defaulting.
if _, ok := jsonMap["acl"]; !ok {
params["acl"] = "private"
}
return nil
}
})

Expand Down
3 changes: 2 additions & 1 deletion config/secretsmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func Configure(p *config.Provider) { //nolint:gocyclo
// aws_secretsmanager_secret_policy.
config.MoveToStatus(r.TerraformResource, "policy")
// TODO: we had better do this for all resources...
r.TerraformConfigurationInjector = func(_ map[string]any, params map[string]any) {
r.TerraformConfigurationInjector = func(_ map[string]any, params map[string]any) error {
params["name_prefix"] = ""
return nil
}
r.TerraformCustomDiff = func(diff *terraform.InstanceDiff, state *terraform.InstanceState, config *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
// skip diff customization on create
Expand Down
1 change: 1 addition & 0 deletions examples/s3/v1beta1/object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: Object
metadata:
annotations:
meta.upbound.io/example-id: s3/v1beta1/object
uptest.upbound.io/disable-import: "true"
labels:
testing.upbound.io/example-name: object
name: example-object
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/aws/smithy-go v1.19.0
github.com/crossplane/crossplane-runtime v1.15.0-rc.0.0.20231215091746-d23a82b3a2f5
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79
github.com/crossplane/upjet v1.1.0
github.com/crossplane/upjet v1.2.0-rc.0.0.20240214173902-780c97fac125
github.com/go-ini/ini v1.46.0
github.com/google/go-cmp v0.6.0
github.com/hashicorp/terraform-json v0.18.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ github.com/crossplane/crossplane-runtime v1.15.0-rc.0.0.20231215091746-d23a82b3a
github.com/crossplane/crossplane-runtime v1.15.0-rc.0.0.20231215091746-d23a82b3a2f5/go.mod h1:pgt7PaTvvOQz3jILyxbCaeleU9MrAqKaNoPJavhGBgM=
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79 h1:HigXs5tEQxWz0fcj8hzbU2UAZgEM7wPe0XRFOsrtF8Y=
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79/go.mod h1:+e4OaFlOcmr0JvINHl/yvEYBrZawzTgj6pQumOH1SS0=
github.com/crossplane/upjet v1.1.0 h1:jfdag6qaF1/5mvlDT/8LdTc/vq1Iq0ASnmk3yV86I9U=
github.com/crossplane/upjet v1.1.0/go.mod h1:0bHLtnejZ9bDeyXuBb9MSOQLvKo3+aoTeUBO8N0dGSA=
github.com/crossplane/upjet v1.2.0-rc.0.0.20240214173902-780c97fac125 h1:2ueKn/H9L4LW6tkt0C5+5Ryf4hX0mxiIIucaF/Xr668=
github.com/crossplane/upjet v1.2.0-rc.0.0.20240214173902-780c97fac125/go.mod h1:0bHLtnejZ9bDeyXuBb9MSOQLvKo3+aoTeUBO8N0dGSA=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/dave/jennifer v1.4.1 h1:XyqG6cn5RQsTj3qlWQTKlRGAyrTcsk1kUmWdZBzRjDw=
Expand Down
Loading