Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Uncomment tfcli Builder code
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Aug 23, 2021
1 parent 15b5d98 commit d316670
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/process/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (pi *Info) GetCmd() *exec.Cmd {
}

func (pi *Info) Kill() error {
if pi.cmd == nil || pi.cmd.Process == nil {
if pi.cmd == nil || pi.cmd.Process == nil || (pi.cmd.ProcessState != nil && pi.cmd.ProcessState.Exited()) {
return nil
}
return errors.Wrap(pi.cmd.Process.Kill(), errKill)
Expand Down
32 changes: 14 additions & 18 deletions pkg/terraform/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/crossplane-contrib/terrajet/pkg/conversion"
"github.com/crossplane-contrib/terrajet/pkg/meta"
"github.com/crossplane-contrib/terrajet/pkg/terraform/resource"
"github.com/crossplane-contrib/terrajet/pkg/tfcli"
)

const (
Expand Down Expand Up @@ -67,30 +68,25 @@ func (c *connector) Connect(ctx context.Context, mg xpresource.Managed) (managed
return nil, errors.New(errUnexpectedObject)
}

// TODO(hasan): create and pass the implementation of tfcli builder once available
/*
pc, err := c.providerConfig(ctx, c.kube, mg)
if err != nil {
return nil, errors.Wrap(err, "cannot get provider config")
}
tfcb := tfcli.NewClientBuilder().
WithLogger(c.logger).
WithResourceName(tr.GetName()).
WithHandle(string(tr.GetUID())).
WithProviderConfiguration(pc).
WithResourceType(tr.GetTerraformResourceType())
tfcli, err := conversion.BuildClientForResource(tfcb, tr)
*/

tfcli, err := conversion.BuildClientForResource(ctx, nil, tr)
pc, err := c.providerConfig(ctx, c.kube, mg)
if err != nil {
return nil, errors.Wrap(err, "cannot get provider config")
}
tfcb := tfcli.NewClientBuilder().
WithLogger(c.logger).
WithResourceName(tr.GetName()).
WithHandle(string(tr.GetUID())).
WithProviderConfiguration(pc).
WithResourceType(tr.GetTerraformResourceType())

tfCli, err := conversion.BuildClientForResource(ctx, tfcb, tr)
if err != nil {
return nil, errors.Wrap(err, "cannot build tf client for resource")
}

return &external{
kube: c.kube,
tf: conversion.NewCli(tfcli),
tf: conversion.NewCli(tfCli),
log: c.logger,
record: event.NewNopRecorder(),
}, nil
Expand Down
5 changes: 4 additions & 1 deletion pkg/tfcli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func (c *client) init(ctx context.Context) error {
err := c.closeOnError(ctx, func() error {
var err error
initLockExists, err = c.initConfiguration(types.OperationInit, true)
if errors.Is(err, cliErrors.OperationInProgressError{}) && initLockExists {
if (err == nil || errors.Is(err, cliErrors.OperationInProgressError{})) && initLockExists {
if err == nil || cliErrors.IsOperationInProgress(err, types.OperationInit) {
return c.removeStateStore()
}
return nil
}
return err
Expand Down

0 comments on commit d316670

Please sign in to comment.