Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus Endpoint resource #221

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Nexus Endpoint resource #221

wants to merge 4 commits into from

Conversation

nikki-dag
Copy link

@nikki-dag nikki-dag commented Jan 5, 2025

Closes #219

@nikki-dag nikki-dag marked this pull request as ready for review January 5, 2025 18:39
@nikki-dag nikki-dag requested review from jlacefie and a team as code owners January 5, 2025 18:39
Comment on lines +54 to +61
worker_target_spec = {
namespace_id = temporalcloud_namespace.target_namespace.id
task_queue = "terraform-task-queue"
}
allowed_caller_namespaces = [
temporalcloud_namespace.caller_namespace.id,
temporalcloud_namespace.caller_namespace_2.id,
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but I'm wondering if it'd be better to make the API a little more future-proof. Here's an example:

target = {
  type = "worker"
  namespace_id = temporalcloud_namespace.target_namespace.id
  task_queue   = "terraform-task-queue"
}

allowed_callers = [
  {
    type = "namespace"
    namespace_id = "..."
  }
]

But what you have is probably better for type safety.
Let's keep it as is.

Optional: true,
Sensitive: true,
},
"worker_target_spec": schema.SingleNestedAttribute{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just call this worker_target?

}

func getPolicySpecsFromModel(_ context.Context, model *nexusEndpointResourceModel) ([]*nexusv1.EndpointPolicySpec, diag.Diagnostics) {
policySpecs := make([]*nexusv1.EndpointPolicySpec, 0, len(model.AllowedCallerNamespaces.Elements()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a sorted set? Can we ensure that nothing happens if the set elements are arbitrarily ordered?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terraform sets are unordered

Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
WorkerTargetSpec types.Object `tfsdk:"worker_target_spec"`
AllowedCallerNamespaces types.Set `tfsdk:"allowed_caller_namespaces"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these real Go types? The TF type system will know how to do the conversion to/from go types for us. (same goes for the structs below)

"description": schema.StringAttribute{
Description: "The description for the Nexus endpoint.",
Optional: true,
Sensitive: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is description meant to be marked as sensitive here?

Required: true,
},
"allowed_caller_namespaces": schema.SetAttribute{
Description: "Namespace(s) that are allowed to call this Endpoint.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: "Namespace(s) that are allowed to call this Endpoint.",
Description: "Namespace Id(s) that are allowed to call this Endpoint.",

Timeouts timeouts.Value `tfsdk:"timeouts"`
}

nexusEndpointWorkerTargetModel struct {
Copy link
Contributor

@briankassouf briankassouf Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object and the Policy object are oneofs in the API. Do we want to follow suit here and wrap these in an object? That way if a new oneof option is added we can add it as another field in the wrapping struct?

Target: {
    WorkerTarget: {...}
}
Policy: {
    AllowedCallerNamesoaces: [...]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Create a Nexus Resource
3 participants