-
Notifications
You must be signed in to change notification settings - Fork 7
/
waiter.go
50 lines (40 loc) · 1.42 KB
/
waiter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/dns"
"github.com/stackitcloud/stackit-sdk-go/services/dns/wait"
)
func main() {
ctx := context.Background()
// Specify the project ID and DNS name (must be a valid and unique FQDN)
projectId := "PROJECT_ID"
dnsName := "zoneTest.com"
// Create a new API client, that uses default authentication.
dnsClient, err := dns.NewAPIClient()
if err != nil {
fmt.Fprintf(os.Stderr, "[DNS API] Creating API client: %v\n", err)
os.Exit(1)
}
// Create a DNS Zone
createZonePayload := dns.CreateZonePayload{
Name: utils.Ptr("myZone"),
DnsName: utils.Ptr(dnsName),
}
createZoneResp, err := dnsClient.CreateZone(ctx, projectId).CreateZonePayload(createZonePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[DNS API] Error when calling `ZoneApi.CreateZone`: %v\n", err)
os.Exit(1)
}
zoneId := *createZoneResp.Zone.Id
// The following will wait until the DNS zone creation has finished
wres, err := wait.CreateZoneWaitHandler(ctx, dnsClient, projectId, zoneId).SetTimeout(15 * time.Minute).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "[DNS API] Waiting for zone creation: %v\n", err)
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "[DNS API] Zone with id %s created (state: %s)\n", *wres.Zone.Id, *wres.Zone.State) // The state is always successful
}