Skip to content

Commit

Permalink
Add support for configuring Terraform resource timeouts both from the…
Browse files Browse the repository at this point in the history
… schema and config.Resource.OperationTimeouts

- The timeouts specified in upjet resource configuration (config.Resource.OperationTimeouts)
  prevails any defaults configured in the Terraform schema.

Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Nov 2, 2023
1 parent 229c273 commit e241dfc
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion pkg/controller/external_nofork.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type noForkExternal struct {
opTracker *AsyncTracker
}

func getExtendedParameters(ctx context.Context, tr resource.Terraformed, externalName string, config *config.Resource, ts terraform.Setup, initParamsMerged bool, kube client.Client) (map[string]any, error) {
func getExtendedParameters(ctx context.Context, tr resource.Terraformed, externalName string, config *config.Resource, ts terraform.Setup, initParamsMerged bool, kube client.Client) (map[string]any, error) { //nolint:gocyclo
params, err := tr.GetMergedParameters(initParamsMerged)
if err != nil {
return nil, errors.Wrap(err, "cannot get merged parameters")
Expand Down Expand Up @@ -143,6 +143,43 @@ func getExtendedParameters(ctx context.Context, tr resource.Terraformed, externa
if _, ok := config.TerraformResource.CoreConfigSchema().Attributes["tags_all"]; ok {
params["tags_all"] = params["tags"]
}
// resource timeouts configuration
if _, ok := config.TerraformResource.CoreConfigSchema().Attributes["timeouts"]; !ok {
timeouts := make(map[string]string)
// first use the timeout overrides specified in
// the Terraform resource schema
if config.TerraformResource.Timeouts != nil {
if config.TerraformResource.Timeouts.Create != nil && *config.TerraformResource.Timeouts.Create != 0 {
timeouts["create"] = config.TerraformResource.Timeouts.Create.String()
}
if config.TerraformResource.Timeouts.Update != nil && *config.TerraformResource.Timeouts.Update != 0 {
timeouts["update"] = config.TerraformResource.Timeouts.Update.String()
}
if config.TerraformResource.Timeouts.Delete != nil && *config.TerraformResource.Timeouts.Delete != 0 {
timeouts["delete"] = config.TerraformResource.Timeouts.Delete.String()
}
if config.TerraformResource.Timeouts.Read != nil && *config.TerraformResource.Timeouts.Read != 0 {
timeouts["read"] = config.TerraformResource.Timeouts.Read.String()
}
}
// then, override any Terraform defaults using any upjet
// resource configuration overrides
if config.OperationTimeouts.Create != 0 {
timeouts["create"] = config.OperationTimeouts.Create.String()
}
if config.OperationTimeouts.Update != 0 {
timeouts["update"] = config.OperationTimeouts.Update.String()
}
if config.OperationTimeouts.Delete != 0 {
timeouts["delete"] = config.OperationTimeouts.Delete.String()
}
if config.OperationTimeouts.Read != 0 {
timeouts["read"] = config.OperationTimeouts.Read.String()
}
if len(timeouts) > 0 {
params["timeouts"] = timeouts
}
}
return params, nil
}

Expand Down

0 comments on commit e241dfc

Please sign in to comment.