Skip to content

Commit

Permalink
Function type config.ConfigurationInjector now returns an error
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Feb 14, 2024
1 parent 105ce93 commit 3fad811
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,5 @@ replace golang.org/x/exp => golang.org/x/exp v0.0.0-20231006140011-7918f672742d
replace github.com/hashicorp/terraform-provider-aws => github.com/upbound/terraform-provider-aws v0.0.0-20240129145938-c69f68a59916

replace github.com/hashicorp/terraform-plugin-log => github.com/gdavison/terraform-plugin-log v0.0.0-20230928191232-6c653d8ef8fb

replace github.com/crossplane/upjet => github.com/ulucinar/upbound-upjet v0.0.0-20240214143445-13e9fc05f724
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ 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/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 Expand Up @@ -556,6 +554,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ=
github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w=
github.com/ulucinar/upbound-upjet v0.0.0-20240214143445-13e9fc05f724 h1:qyX60TlNmvOZFIScwBpDWn8yJ/3+gXs/xJA3E9ukz5Q=
github.com/ulucinar/upbound-upjet v0.0.0-20240214143445-13e9fc05f724/go.mod h1:0bHLtnejZ9bDeyXuBb9MSOQLvKo3+aoTeUBO8N0dGSA=
github.com/upbound/terraform-provider-aws v0.0.0-20240129145938-c69f68a59916 h1:W3WAB6utkebXviDpnym5bWaQtqASXeudJ7bu7v9CJA4=
github.com/upbound/terraform-provider-aws v0.0.0-20240129145938-c69f68a59916/go.mod h1:Kb86v3lyFUggXmDTi53PPHLENdWUdD8t3IfjS7rFd+0=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down

0 comments on commit 3fad811

Please sign in to comment.