Skip to content

Commit 76d4a8b

Browse files
authored
Nexus endpoint data source (#324)
* Nexus endpoint data source * Fix region * Fix folder name * Mark description as Computed
1 parent 4944ac4 commit 76d4a8b

File tree

10 files changed

+782
-0
lines changed

10 files changed

+782
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "temporalcloud_nexus_endpoint Data Source - terraform-provider-temporalcloud"
4+
subcategory: ""
5+
description: |-
6+
Fetches details about a Nexus Endpoint.
7+
---
8+
9+
# temporalcloud_nexus_endpoint (Data Source)
10+
11+
Fetches details about a Nexus Endpoint.
12+
13+
## Example Usage
14+
15+
```terraform
16+
terraform {
17+
required_providers {
18+
temporalcloud = {
19+
source = "temporalio/temporalcloud"
20+
}
21+
}
22+
}
23+
24+
provider "temporalcloud" {
25+
26+
}
27+
28+
resource "temporalcloud_namespace" "target_namespace" {
29+
name = "terraform-target-namespace"
30+
regions = ["aws-us-west-2"]
31+
api_key_auth = true
32+
retention_days = 14
33+
timeouts {
34+
create = "10m"
35+
delete = "10m"
36+
}
37+
}
38+
39+
resource "temporalcloud_namespace" "caller_namespace" {
40+
name = "terraform-caller-namespace"
41+
regions = ["aws-us-east-1"]
42+
api_key_auth = true
43+
retention_days = 14
44+
timeouts {
45+
create = "10m"
46+
delete = "10m"
47+
}
48+
}
49+
50+
resource "temporalcloud_namespace" "caller_namespace_2" {
51+
name = "terraform-caller-namespace-2"
52+
regions = ["gcp-us-central1"]
53+
api_key_auth = true
54+
retention_days = 14
55+
timeouts {
56+
create = "10m"
57+
delete = "10m"
58+
}
59+
}
60+
61+
resource "temporalcloud_nexus_endpoint" "nexus_endpoint" {
62+
name = "terraform-nexus-endpoint"
63+
description = <<-EOT
64+
Service Name:
65+
my-hello-service
66+
Operation Names:
67+
echo
68+
say-hello
69+
70+
Input / Output arguments are in the following repository:
71+
https://github.com/temporalio/samples-go/blob/main/nexus/service/api.go
72+
EOT
73+
worker_target = {
74+
namespace_id = temporalcloud_namespace.target_namespace.id
75+
task_queue = "terraform-task-queue"
76+
}
77+
allowed_caller_namespaces = [
78+
temporalcloud_namespace.caller_namespace.id,
79+
temporalcloud_namespace.caller_namespace_2.id,
80+
]
81+
}
82+
83+
data "temporalcloud_nexus_endpoint" "example" {
84+
id = temporalcloud_nexus_endpoint.nexus_endpoint
85+
}
86+
87+
output "nexus_endpoint" {
88+
value = data.temporalcloud_nexus_endpoint.example
89+
}
90+
```
91+
92+
<!-- schema generated by tfplugindocs -->
93+
## Schema
94+
95+
### Required
96+
97+
- `id` (String) The unique identifier of the Nexus Endpoint.
98+
99+
### Optional
100+
101+
- `description` (String, Sensitive) The description of the Nexus Endpoint.
102+
103+
### Read-Only
104+
105+
- `allowed_caller_namespaces` (Set of String) Namespace Id(s) that are allowed to call this Endpoint.
106+
- `created_at` (String) The creation time of the Nexus Endpoint.
107+
- `name` (String) The name of the endpoint. Unique within an account and match `^[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9]$`
108+
- `state` (String) The current state of the Nexus Endpoint.
109+
- `updated_at` (String) The last update time of the Nexus Endpoint.
110+
- `worker_target` (Attributes) The target spec for routing nexus requests to a specific cloud namespace worker. (see [below for nested schema](#nestedatt--worker_target))
111+
112+
<a id="nestedatt--worker_target"></a>
113+
### Nested Schema for `worker_target`
114+
115+
Read-Only:
116+
117+
- `namespace_id` (String) The target cloud namespace to route requests to. Namespace is in same account as the endpoint.
118+
- `task_queue` (String) The task queue on the cloud namespace to route requests to.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "temporalcloud_nexus_endpoints Data Source - terraform-provider-temporalcloud"
4+
subcategory: ""
5+
description: |-
6+
Fetches details about all Nexus Endpoints.
7+
---
8+
9+
# temporalcloud_nexus_endpoints (Data Source)
10+
11+
Fetches details about all Nexus Endpoints.
12+
13+
## Example Usage
14+
15+
```terraform
16+
terraform {
17+
required_providers {
18+
temporalcloud = {
19+
source = "temporalio/temporalcloud"
20+
}
21+
}
22+
}
23+
24+
provider "temporalcloud" {
25+
26+
}
27+
28+
data "temporalcloud_nexus_endpoints" "my_nexus_endpoints" {}
29+
30+
output "nexus_endpoints" {
31+
value = data.temporalcloud_nexus_endpoints.my_nexus_endpoints.nexus_endpoints
32+
sensitive = true
33+
}
34+
```
35+
36+
<!-- schema generated by tfplugindocs -->
37+
## Schema
38+
39+
### Read-Only
40+
41+
- `id` (String) The unique identifier of the Nexus Endpoints data source.
42+
- `nexus_endpoints` (Attributes List) The list of Nexus Endpoints. (see [below for nested schema](#nestedatt--nexus_endpoints))
43+
44+
<a id="nestedatt--nexus_endpoints"></a>
45+
### Nested Schema for `nexus_endpoints`
46+
47+
Optional:
48+
49+
- `description` (String, Sensitive) The description of the Nexus Endpoint.
50+
51+
Read-Only:
52+
53+
- `allowed_caller_namespaces` (Set of String) Namespace Id(s) that are allowed to call this Endpoint.
54+
- `created_at` (String) The creation time of the Nexus Endpoint.
55+
- `id` (String) The unique identifier of the Nexus Endpoint.
56+
- `name` (String) The name of the endpoint. Unique within an account and match `^[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9]$`
57+
- `state` (String) The current state of the Nexus Endpoint.
58+
- `updated_at` (String) The last update time of the Nexus Endpoint.
59+
- `worker_target` (Attributes) The target spec for routing nexus requests to a specific cloud namespace worker. (see [below for nested schema](#nestedatt--nexus_endpoints--worker_target))
60+
61+
<a id="nestedatt--nexus_endpoints--worker_target"></a>
62+
### Nested Schema for `nexus_endpoints.worker_target`
63+
64+
Read-Only:
65+
66+
- `namespace_id` (String) The target cloud namespace to route requests to. Namespace is in same account as the endpoint.
67+
- `task_queue` (String) The task queue on the cloud namespace to route requests to.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
terraform {
2+
required_providers {
3+
temporalcloud = {
4+
source = "temporalio/temporalcloud"
5+
}
6+
}
7+
}
8+
9+
provider "temporalcloud" {
10+
11+
}
12+
13+
resource "temporalcloud_namespace" "target_namespace" {
14+
name = "terraform-target-namespace"
15+
regions = ["aws-us-west-2"]
16+
api_key_auth = true
17+
retention_days = 14
18+
timeouts {
19+
create = "10m"
20+
delete = "10m"
21+
}
22+
}
23+
24+
resource "temporalcloud_namespace" "caller_namespace" {
25+
name = "terraform-caller-namespace"
26+
regions = ["aws-us-east-1"]
27+
api_key_auth = true
28+
retention_days = 14
29+
timeouts {
30+
create = "10m"
31+
delete = "10m"
32+
}
33+
}
34+
35+
resource "temporalcloud_namespace" "caller_namespace_2" {
36+
name = "terraform-caller-namespace-2"
37+
regions = ["gcp-us-central1"]
38+
api_key_auth = true
39+
retention_days = 14
40+
timeouts {
41+
create = "10m"
42+
delete = "10m"
43+
}
44+
}
45+
46+
resource "temporalcloud_nexus_endpoint" "nexus_endpoint" {
47+
name = "terraform-nexus-endpoint"
48+
description = <<-EOT
49+
Service Name:
50+
my-hello-service
51+
Operation Names:
52+
echo
53+
say-hello
54+
55+
Input / Output arguments are in the following repository:
56+
https://github.com/temporalio/samples-go/blob/main/nexus/service/api.go
57+
EOT
58+
worker_target = {
59+
namespace_id = temporalcloud_namespace.target_namespace.id
60+
task_queue = "terraform-task-queue"
61+
}
62+
allowed_caller_namespaces = [
63+
temporalcloud_namespace.caller_namespace.id,
64+
temporalcloud_namespace.caller_namespace_2.id,
65+
]
66+
}
67+
68+
data "temporalcloud_nexus_endpoint" "example" {
69+
id = temporalcloud_nexus_endpoint.nexus_endpoint
70+
}
71+
72+
output "nexus_endpoint" {
73+
value = data.temporalcloud_nexus_endpoint.example
74+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_providers {
3+
temporalcloud = {
4+
source = "temporalio/temporalcloud"
5+
}
6+
}
7+
}
8+
9+
provider "temporalcloud" {
10+
11+
}
12+
13+
data "temporalcloud_nexus_endpoints" "my_nexus_endpoints" {}
14+
15+
output "nexus_endpoints" {
16+
value = data.temporalcloud_nexus_endpoints.my_nexus_endpoints.nexus_endpoints
17+
sensitive = true
18+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/datasource"
7+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
8+
"github.com/temporalio/terraform-provider-temporalcloud/internal/client"
9+
10+
cloudservicev1 "go.temporal.io/cloud-sdk/api/cloudservice/v1"
11+
)
12+
13+
type (
14+
nexusEndpointDataSource struct {
15+
client *client.Client
16+
}
17+
)
18+
19+
var (
20+
_ datasource.DataSource = (*nexusEndpointDataSource)(nil)
21+
_ datasource.DataSourceWithConfigure = (*nexusEndpointDataSource)(nil)
22+
)
23+
24+
func NewNexusEndpointDataSource() datasource.DataSource {
25+
return &nexusEndpointDataSource{}
26+
}
27+
28+
func (d *nexusEndpointDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
29+
resp.TypeName = req.ProviderTypeName + "_nexus_endpoint"
30+
}
31+
32+
func (d *nexusEndpointDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
33+
if req.ProviderData == nil {
34+
return
35+
}
36+
37+
cloudClient, ok := req.ProviderData.(*client.Client)
38+
if !ok {
39+
resp.Diagnostics.AddError(
40+
"Unexpected Data Source Configure Type",
41+
"Expected *client.Client, got: %T. Please report this issue to the provider developers.",
42+
)
43+
return
44+
}
45+
46+
d.client = cloudClient
47+
}
48+
49+
func (d *nexusEndpointDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
50+
resp.Schema = schema.Schema{
51+
Description: "Fetches details about a Nexus Endpoint.",
52+
Attributes: nexusEndpointSchema(true),
53+
}
54+
}
55+
56+
func (d *nexusEndpointDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
57+
var input nexusEndpointDataModel
58+
resp.Diagnostics.Append(req.Config.Get(ctx, &input)...)
59+
if resp.Diagnostics.HasError() {
60+
return
61+
}
62+
63+
if len(input.ID.ValueString()) == 0 {
64+
resp.Diagnostics.AddError("invalid nexus endpoint id", "nexus endpoint id is required")
65+
return
66+
}
67+
68+
getResp, err := d.client.CloudService().GetNexusEndpoint(ctx, &cloudservicev1.GetNexusEndpointRequest{
69+
EndpointId: input.ID.ValueString(),
70+
})
71+
if err != nil {
72+
resp.Diagnostics.AddError("Unable to fetch nexus endpoint", err.Error())
73+
return
74+
}
75+
76+
endpointDataModel, diags := nexusEndpointToNexusEndpointDataModel(ctx, getResp.GetEndpoint())
77+
resp.Diagnostics.Append(diags...)
78+
if resp.Diagnostics.HasError() {
79+
return
80+
}
81+
82+
diags = resp.State.Set(ctx, &endpointDataModel)
83+
resp.Diagnostics.Append(diags...)
84+
}

0 commit comments

Comments
 (0)