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

feat(cluster-connection): implement conterpart for cluster connections api in particular tgw #115

Conversation

dkropachev
Copy link
Contributor

@dkropachev dkropachev commented Feb 10, 2024

Closes #121

Cluster connection API was implemented in https://github.com/scylladb/siren/pull/10362. This PR implements terraform counterpart for it.

Tested:

main.tf :


resource "scylladbcloud_cluster" "aws" {
  name       = "AWS-statuspage-test-${random_string.postfix.result}"
  cloud      = "AWS"
  region     = "us-east-1"
  node_count = 3
  node_type  = "t3.micro"
  cidr_block = "172.31.0.0/24"
  enable_dns = true
  user_api_interface = "ALTERNATOR"
  alternator_write_isolation = "only_rmw_uses_lwt"
}

resource "scylladbcloud_cluster_connection" "aws-tgw-test" {
  cluster_id = scylladbcloud_cluster.aws.id
  name       = "aws-tgw-test"
  cidrlist = ["10.201.0.0/16"]
  type = "AWS_TGW_ATTACHMENT"
  datacenter = "AWS_US_EAST_1"
  status = "ACTIVE"
  data = {
    tgwid = "tgw-08461afa1119f390b"
    ramarn = "arn:aws:ram:us-east-1:043400831220:resource-share/be3b0395-1782-47cb-9ae4-6d3517c6a721"
  }
}

Apply:

➜  status-page-agent-provisioning git:(main) ✗ terraform apply                                                                                            
random_string.postfix: Refreshing state... [id=h74aFU4o]
scylladbcloud_cluster.aws: Refreshing state... [id=262]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # scylladbcloud_cluster_connection.aws-tgw-test will be created
  + resource "scylladbcloud_cluster_connection" "aws-tgw-test" {
      + cidrlist    = [
          + "10.201.0.0/16",
        ]
      + cluster_id  = 262
      + data        = {
          + "ramarn" = "arn:aws:ram:us-east-1:043400831220:resource-share/be3b0395-1782-47cb-9ae4-6d3517c6a721"
          + "tgwid"  = "tgw-08461afa1119f390a"
        }
      + datacenter  = "AWS_US_EAST_1"
      + external_id = (known after apply)
      + id          = (known after apply)
      + name        = "aws-tgw-test"
      + region      = (known after apply)
      + status      = "ACTIVE"
      + type        = "AWS_TGW_ATTACHMENT"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

scylladbcloud_cluster_connection.aws-tgw-test: Creating...
scylladbcloud_cluster_connection.aws-tgw-test: Still creating... [10s elapsed]
scylladbcloud_cluster_connection.aws-tgw-test: Still creating... [20s elapsed]
....
scylladbcloud_cluster_connection.aws-tgw-test: Still creating... [1m40s elapsed]
scylladbcloud_cluster_connection.aws-tgw-test: Creation complete after 1m46s [id=74]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

@dkropachev dkropachev linked an issue Feb 10, 2024 that may be closed by this pull request
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch 2 times, most recently from 650ecdb to 4bd2cc5 Compare February 10, 2024 02:24
@dkropachev dkropachev marked this pull request as ready for review February 10, 2024 03:14
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch 3 times, most recently from fd0be9b to 0df4034 Compare February 10, 2024 05:07
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch from ffa1f8b to 8969d03 Compare February 20, 2024 11:35
@dkropachev dkropachev requested a review from rjeczalik February 20, 2024 12:06
cidrlist = ["10.201.0.0/16"]
type = "AWS_TGW_ATTACHMENT"
datacenter = "AWS_US_EAST_1"
status = "ACTIVE"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this needed here? this is a computed field that will be set by the provider, can you explain why user would like to provide the status?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary, removed.
When user creates connection he can pick status between ACTIVE and INACTIVE

Copy link
Collaborator

Choose a reason for hiding this comment

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

User can create a connection that will be INACTIVE by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yap

err := resourceClusterConnectionRead(ctx, data, i)
if err != nil {
if errors.Is(err, errNotFound) {
data.SetId("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

SetId sets the ID of the resource. If the value is blank, then the resource is destroyed. is the _ = data.Set("cluster_id", 0) needed in such case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question, what to do when resource is gone, while it is in the state? there are three options in this regard:

  1. Throw an error on read. It results in error on next terraform apply or terraform refresh
  2. Silently ignore. It results in having no error on apply and refresh, but object stays in state and if you want remove/recreate it, you need to go manually remove it from the state
  3. Do data.SetId("") and return no error. Will result in having no error on apply and refresh and object been deleted from the state

From my perspective 3rd option produce best UX.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

data.Set("cluster_id", 0) is not needed, removed

if errors.Is(err, errNotFound) {
data.SetId("")
_ = data.Set("cluster_id", 0)
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not return the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is going to fail apply and refresh operation, which produce bad UX

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would it be bad UX to fail when reading misconfigured/malformed resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not malformed, it is deleted resource, on malformed it is going to return error

internal/provider/cluster_connection.go Outdated Show resolved Hide resolved
internal/scylla/errors.go Outdated Show resolved Hide resolved
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch 2 times, most recently from a510f3d to ce70060 Compare February 21, 2024 05:45
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch from ce70060 to 164300d Compare February 21, 2024 05:47
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch 3 times, most recently from 17445c9 to aca6fd3 Compare March 20, 2024 17:05
@dkropachev
Copy link
Contributor Author

@charconstpointer, could you please take another look after rebase

CODEOWNERS Outdated Show resolved Hide resolved
@dkropachev dkropachev requested review from rjeczalik and removed request for rjeczalik March 22, 2024 02:25
Copy link
Member

@rjeczalik rjeczalik left a comment

Choose a reason for hiding this comment

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

👍 LGTM, some less important comments

@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch 2 times, most recently from 016519f to fd07d74 Compare March 23, 2024 11:38
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch from fd07d74 to 31dea58 Compare April 20, 2024 15:12
@dkropachev dkropachev force-pushed the dk/106-implement-conterpart-for-cluster-connections-api-in-particular-tgw branch from 31dea58 to 081461b Compare May 8, 2024 02:31
@dkropachev dkropachev merged commit 09cdd72 into main May 8, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants