Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Extract PlatformApplier and PlatformDestroyer from Platform interface #666

Open
invidian opened this issue Jun 24, 2020 · 0 comments
Open
Labels
technical-debt Technical debt-related issues

Comments

@invidian
Copy link
Member

Currently, Platform interface looks like this:

type Platform interface {
  LoadConfig(*hcl.Body, *hcl.EvalContext) hcl.Diagnostics
  Apply(*terraform.Executor) error
  Destroy(*terraform.Executor) error
  Initialize(*terraform.Executor) error
  Meta() Meta
}

We want to do the following:

  • Remove LoadConfig, as it shouldn't be there.
  • Replace Initialize with Render, to only return content of cluster.tf file, similar to what backend code is doing.

With that, we end up with:

type Platform interface {
  Apply(*terraform.Executor) error
  Destroy(*terraform.Executor) error
  Render() (string, error)
  Meta() Meta
}

Now, Apply() and Destroy() methods looks the same for AWS, AKS and bare-metal:

// Apply creates AKS infrastructure via Terraform.
func (c *config) Apply(ex *terraform.Executor) error {
  if err := c.Initialize(ex); err != nil {
    return err
  }

  return ex.Apply()
}

// Destroy destroys AKS infrastructure via Terraform.
func (c *config) Destroy(ex *terraform.Executor) error {
  if err := c.Initialize(ex); err != nil {
    return err
  }

  return ex.Destroy()
}

If we create following interfaces:

type PlatformApplier interface {
  Apply(*terraform.Executor) error
}

type PlatformDestroyer interface {
  Destroy(*terraform.Executor) error
}

Then we can check if given platform implements such interface and if not, just call generic Destroy() on executor, so platform code is more condensed.

@invidian invidian added the technical-debt Technical debt-related issues label Sep 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
technical-debt Technical debt-related issues
Projects
None yet
Development

No branches or pull requests

1 participant