spacelift-io / terraform-provider-spacelift

Terraform provider to interact with Spacelift
MIT License
74 stars 28 forks source link

Add stack_activator resource to terraform provider #444

Closed dobarx closed 1 year ago

dobarx commented 1 year ago

Description of the change

Created a new resource for enabling/disabling Spacelift stacks. Example:

resource "spacelift_stack" "app" {
  branch     = "master"
  name       = "Application stack"
  repository = "app"
}

resource "spacelift_stack_activator" "test" {
  enabled  = true
  stack_id = spacelift_stack.app.id
}

Type of change

Related issues

Checklists

Development

Code review

Clickup-user commented 1 year ago

Task linked: CU-334hhwd Add stack_activator resource to terraform provider

dobarx commented 1 year ago

@adamconnelly

So what if we flipped it slightly:

  1. Try to invoke the enable/disable mutation. I'm assuming it'll fail if the stack doesn't exist / you don't have access to it (but you'd need to double check that).
  2. Call resourceStackActivatorRead to query for the stack, and set the state based on the IsDisabled field.

Just a thought - feel free to ignore me if that doesn't make sense for some reason.

But how do we know which mutation to invoke? We have two separate mutations stackDisable(id) & stackEnable(id). I do not know which to call unless I query stack first and compare. It would only be possible if we had something like setStackEnabled(id, value).

adamconnelly commented 1 year ago

@adamconnelly

So what if we flipped it slightly:

  1. Try to invoke the enable/disable mutation. I'm assuming it'll fail if the stack doesn't exist / you don't have access to it (but you'd need to double check that).
  2. Call resourceStackActivatorRead to query for the stack, and set the state based on the IsDisabled field.

Just a thought - feel free to ignore me if that doesn't make sense for some reason.

But how do we know which mutation to invoke? We have two separate mutations stackDisable(id) & stackEnable(id). I do not know which to call unless I query stack first and compare. It would only be possible if we had something like setStackEnabled(id, value).

I guess I figured you'd know which one to call based on the value of the enabled Terraform property. But maybe that doesn't handle the situation where the stack is enabled but the Terraform state thinks it's disabled or something like that?

dobarx commented 1 year ago

@adamconnelly

So what if we flipped it slightly:

  1. Try to invoke the enable/disable mutation. I'm assuming it'll fail if the stack doesn't exist / you don't have access to it (but you'd need to double check that).
  2. Call resourceStackActivatorRead to query for the stack, and set the state based on the IsDisabled field.

Just a thought - feel free to ignore me if that doesn't make sense for some reason.

But how do we know which mutation to invoke? We have two separate mutations stackDisable(id) & stackEnable(id). I do not know which to call unless I query stack first and compare. It would only be possible if we had something like setStackEnabled(id, value).

I guess I figured you'd know which one to call based on the value of the enabled Terraform property. But maybe that doesn't handle the situation where the stack is enabled but the Terraform state thinks it's disabled or something like that?

I could use this d.GetChange("enabled") to get old and new values of TF state. But I figured if stack is enabled/disabled by other process then this could lead to the issue when applying changes fail. So retrieving current state before applying these changes seems a bit safer.

adamconnelly commented 1 year ago

@dobarx ok - no worries. Makes sense.