Skip to content

Commit 5faf23d

Browse files
authored
Wait improvements (#161)
1 parent 65a1177 commit 5faf23d

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

iterative/aws/provider.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"net"
87
"regexp"
98
"sort"
109
"strconv"
@@ -16,8 +15,6 @@ import (
1615
"github.com/aws/aws-sdk-go/service/ec2"
1716
"github.com/aws/aws-sdk-go/service/sts"
1817
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19-
20-
"terraform-provider-iterative/iterative/utils"
2118
)
2219

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

441438
return fmt.Errorf("Not able to decode: %s", err.Error())
442439
}
443-
444-
func ResourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
445-
return utils.RunCommand("journalctl --no-pager", 10*time.Second, net.JoinHostPort(d.Get("instance_ip").(string), "22"), "ubuntu", d.Get("ssh_private").(string))
446-
}

iterative/azure/provider.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"net"
87
"os"
98
"strings"
109
"time"
@@ -17,8 +16,6 @@ import (
1716
"github.com/Azure/go-autorest/autorest/to"
1817

1918
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20-
21-
"terraform-provider-iterative/iterative/utils"
2219
)
2320

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

397394
return "", errors.New("AZURE_SUBSCRIPTION_ID is not present")
398395
}
399-
400-
func ResourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
401-
return utils.RunCommand("journalctl --no-pager", 10*time.Second, net.JoinHostPort(d.Get("instance_ip").(string), "22"), "ubuntu", d.Get("ssh_private").(string))
402-
}

iterative/resource_machine.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"fmt"
7+
"net"
78
"time"
89

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

237238
func resourceMachineLogs(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
238239
switch cloud := d.Get("cloud").(string); cloud {
239-
case "aws":
240-
return aws.ResourceMachineLogs(ctx, d, m)
241-
case "azure":
242-
return azure.ResourceMachineLogs(ctx, d, m)
243240
case "kubernetes":
244241
return kubernetes.ResourceMachineLogs(ctx, d, m)
245242
default:
246-
return "", fmt.Errorf("Unknown cloud: %s", cloud)
243+
return utils.RunCommand("journalctl --no-pager",
244+
2*time.Second,
245+
net.JoinHostPort(d.Get("instance_ip").(string), "22"),
246+
"ubuntu",
247+
d.Get("ssh_private").(string))
247248
}
248249
}

iterative/resource_runner.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"fmt"
99
"log"
10+
"net"
1011
"os"
1112
"strconv"
1213
"text/template"
@@ -210,7 +211,17 @@ func resourceRunnerCreate(ctx context.Context, d *schema.ResourceData, m interfa
210211
var logError error
211212
var logEvents string
212213
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
213-
logEvents, logError = resourceMachineLogs(ctx, d, m)
214+
switch cloud := d.Get("cloud").(string); cloud {
215+
case "kubernetes":
216+
logEvents, logError = resourceMachineLogs(ctx, d, m)
217+
default:
218+
logEvents, logError = utils.RunCommand("journalctl --unit cml --no-pager",
219+
2*time.Second,
220+
net.JoinHostPort(d.Get("instance_ip").(string), "22"),
221+
"ubuntu",
222+
d.Get("ssh_private").(string))
223+
}
224+
214225
log.Printf("[DEBUG] Collected log events: %#v", logEvents)
215226
log.Printf("[DEBUG] Connection errors: %#v", logError)
216227

0 commit comments

Comments
 (0)