Skip to content

Commit

Permalink
End-to-end namespace example (#5)
Browse files Browse the repository at this point in the history
* End-to-end namespace example

* logging in await logic and longer timeouts
  • Loading branch information
swgillespie committed Aug 10, 2023
1 parent e507b56 commit e25b688
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions examples/resources/namespace/ca.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-----BEGIN PRIVATE KEY-----
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDAyIIkvb26BJoIsLKzF
tYJVlNoNSXNCUWPK9rIM23FaftoWd/aBNc8rE7qTG9XnT06hZANiAAQs0Ow8MBkk
CjOma8d0LcOyLm38Yid0UlwqpnBoRGxVXqHMAHRIDGJcEpVIlrQ2VUdnTFzPVGS1
iuGhhpwzUuTIXM+om0gUuzsH+LUWWQPUqRQozcNh62molFVfhFIMaHs=
-----END PRIVATE KEY-----
12 changes: 12 additions & 0 deletions examples/resources/namespace/ca.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIByTCCAVCgAwIBAgIRAWHkC+6JUf3s9Tq43mdp2zgwCgYIKoZIzj0EAwMwEzER
MA8GA1UEChMIdGVtcG9yYWwwHhcNMjMwODEwMDAwOTQ1WhcNMjQwODA5MDAxMDQ1
WjATMREwDwYDVQQKEwh0ZW1wb3JhbDB2MBAGByqGSM49AgEGBSuBBAAiA2IABCzQ
7DwwGSQKM6Zrx3Qtw7IubfxiJ3RSXCqmcGhEbFVeocwAdEgMYlwSlUiWtDZVR2dM
XM9UZLWK4aGGnDNS5Mhcz6ibSBS7Owf4tRZZA9SpFCjNw2HraaiUVV+EUgxoe6No
MGYwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFG4N
8lIXqQKxwVs/ixVzdF6XGZm+MCQGA1UdEQQdMBuCGWNsaWVudC5yb290LnRlbXBv
cmFsLlB1VHMwCgYIKoZIzj0EAwMDZwAwZAIwRLfm9S7rKGd30KdQvUMcOcDJlmDw
6/oM6UOJFxLeGcpYbgxQ/bFize+Yx9Q9kNeMAjA7GiFsaipaKtWHy5MCOCas3ZP6
+ttLaXNXss3Z5Wk5vhDQnyE8JR3rPeQ2cHXLiA0=
-----END CERTIFICATE-----
6 changes: 3 additions & 3 deletions examples/resources/namespace/namespace.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ provider "temporalcloud" {
}

resource "temporalcloud_namespace" "swgillespie-dev" {
name = "swgillespie.a2dd6"
region = "us-west-2"
accepted_client_ca = base64encode("not a real cert")
name = "swgillespie"
region = "us-east-1"
accepted_client_ca = base64encode(file("${path.module}/ca.pem"))
retention_days = 30
}
13 changes: 10 additions & 3 deletions internal/provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/temporalio/tcld/app/credentials/apikey"
"github.com/temporalio/tcld/protogen/api/authservice/v1"
"github.com/temporalio/tcld/protogen/api/namespaceservice/v1"
"github.com/temporalio/tcld/protogen/api/request/v1"
"github.com/temporalio/tcld/protogen/api/requestservice/v1"
Expand Down Expand Up @@ -71,13 +72,16 @@ func (c *Client) RequestService() requestservice.RequestServiceClient {
return requestservice.NewRequestServiceClient(c.conn)
}

func (c *Client) AuthService() authservice.AuthServiceClient {
return authservice.NewAuthServiceClient(c.conn)
}

func (c *Client) AwaitResponse(ctx context.Context, requestID string) error {
ctx = tflog.SetField(ctx, "request_id", requestID)
tflog.Debug(ctx, "awaiting response")
svc := c.RequestService()
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

tflog.Debug(ctx, "awaiting response")
for {
select {
case <-ticker.C:
Expand All @@ -88,11 +92,14 @@ func (c *Client) AwaitResponse(ctx context.Context, requestID string) error {
return fmt.Errorf("failed to query request status: %w", err)
}

tflog.Debug(ctx, "responded with state", map[string]any{
"state": status.RequestStatus.State.String(),
})
switch status.RequestStatus.State {
case request.STATE_PENDING:
case request.STATE_IN_PROGRESS:
case request.STATE_UNSPECIFIED:
tflog.Debug(ctx, "retrying in 1 minute", map[string]any{
tflog.Debug(ctx, "retrying in 1 second", map[string]any{
"state": status.RequestStatus.State.String(),
})
continue
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
)

const (
defaultCreateTimeout time.Duration = 1 * time.Minute
defaultDeleteTimeout time.Duration = 1 * time.Minute
defaultCreateTimeout time.Duration = 5 * time.Minute
defaultDeleteTimeout time.Duration = 5 * time.Minute
)

type (
Expand Down Expand Up @@ -98,7 +98,8 @@ func (r *namespaceResource) Schema(ctx context.Context, _ resource.SchemaRequest
Required: true,
},
"accepted_client_ca": schema.StringAttribute{
Required: true,
Required: true,
Sensitive: true,
},
"retention_days": schema.Int64Attribute{
Required: true,
Expand Down

0 comments on commit e25b688

Please sign in to comment.