Skip to content

Commit

Permalink
Wait improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGOrtega committed Jul 9, 2021
1 parent 65a1177 commit 05aa3a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
7 changes: 0 additions & 7 deletions iterative/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"net"
"regexp"
"sort"
"strconv"
Expand All @@ -16,8 +15,6 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"terraform-provider-iterative/iterative/utils"
)

//ResourceMachineCreate creates AWS instance
Expand Down Expand Up @@ -440,7 +437,3 @@ func decodeAWSError(region string, err error) error {

return fmt.Errorf("Not able to decode: %s", err.Error())
}

func ResourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
return utils.RunCommand("journalctl --no-pager", 10*time.Second, net.JoinHostPort(d.Get("instance_ip").(string), "22"), "ubuntu", d.Get("ssh_private").(string))
}
7 changes: 0 additions & 7 deletions iterative/azure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"net"
"os"
"strings"
"time"
Expand All @@ -17,8 +16,6 @@ import (
"github.com/Azure/go-autorest/autorest/to"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"terraform-provider-iterative/iterative/utils"
)

//ResourceMachineCreate creates AWS instance
Expand Down Expand Up @@ -396,7 +393,3 @@ func subscriptionID() (string, error) {

return "", errors.New("AZURE_SUBSCRIPTION_ID is not present")
}

func ResourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
return utils.RunCommand("journalctl --no-pager", 10*time.Second, net.JoinHostPort(d.Get("instance_ip").(string), "22"), "ubuntu", d.Get("ssh_private").(string))
}
11 changes: 6 additions & 5 deletions iterative/resource_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"fmt"
"net"
"time"

"terraform-provider-iterative/iterative/aws"
Expand Down Expand Up @@ -236,13 +237,13 @@ func resourceMachineRead(ctx context.Context, d *schema.ResourceData, m interfac

func resourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
switch cloud := d.Get("cloud").(string); cloud {
case "aws":
return aws.ResourceMachineLogs(ctx, d, m)
case "azure":
return azure.ResourceMachineLogs(ctx, d, m)
case "kubernetes":
return kubernetes.ResourceMachineLogs(ctx, d, m)
default:
return "", fmt.Errorf("Unknown cloud: %s", cloud)
return utils.RunCommand("journalctl --no-pager",
2*time.Second,
net.JoinHostPort(d.Get("instance_ip").(string), "22"),
"ubuntu",
d.Get("ssh_private").(string))
}
}
13 changes: 12 additions & 1 deletion iterative/resource_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"log"
"net"
"os"
"strconv"
"text/template"
Expand Down Expand Up @@ -210,7 +211,17 @@ func resourceRunnerCreate(ctx context.Context, d *schema.ResourceData, m interfa
var logError error
var logEvents string
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
logEvents, logError = resourceMachineLogs(ctx, d, m)
switch cloud := d.Get("cloud").(string); cloud {
case "kubernetes":
logEvents, logError = resourceMachineLogs(ctx, d, m)
default:
logEvents, logError = utils.RunCommand("journalctl --unit cml --no-pager",
2*time.Second,
net.JoinHostPort(d.Get("instance_ip").(string), "22"),
"ubuntu",
d.Get("ssh_private").(string))
}

log.Printf("[DEBUG] Collected log events: %#v", logEvents)
log.Printf("[DEBUG] Connection errors: %#v", logError)

Expand Down

0 comments on commit 05aa3a3

Please sign in to comment.