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

WIP: Update ressources state handling (& fix CREATE AS SELECT drop) #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

louich
Copy link
Contributor

@louich louich commented Jun 10, 2019

Refers to the issue #2

@louich louich changed the title Update ressources state handling WIP: Update ressources state handling Jun 10, 2019
louich added 2 commits June 27, 2019 12:35
Note: It also fixes the `CREATE AS SELECT` drop problem at the same time
@Mongey
Copy link
Owner

Mongey commented Jun 27, 2019

👋 @louich sorry I haven't had a change to take a look at the PR's, I should get some time time weekend

@louich louich changed the title WIP: Update ressources state handling WIP: Update ressources state handling (& fix CREATE AS SELECT drop) Jun 27, 2019
@louich
Copy link
Contributor Author

louich commented Jun 27, 2019

@Mongey no problem. I just changed the reference here to use the Mongey/ksql#7 code including the describe and the fix for drop on streams & tables running underlying persistent queries & so far so good... just a little struggle with go modules but it seems ok now

@louich
Copy link
Contributor Author

louich commented Jun 27, 2019

@Mongey I'm starting to have a concern when writing the same code twice as STREAM & TABLE KSQL objects are on the same form (returning the same described payload for the matter). How would you feel going the path of a parametrized resource builder, something along the line of:

type Resource struct {
  Type string
}

func (r *Resource) GenerateResource() *schema.Resource {
  return &schema.Resource{
    Create: r.create,
    Read:   r.read,
    Delete: r.delete,
    Schema: map[string]*schema.Schema{
      "name": {
        Type:             schema.TypeString,
        Required:         true,
        ForceNew:         true,
        Description:      "The name of the stream<Plug>_",
        DiffSuppressFunc: DiffSuppressCaseSensitivity,
      },
      "query": {
        Type:             schema.TypeString,
        Required:         true,
        ForceNew:         true,
        Description:      "The query",
      },
    },
  }
}

func (r *Resource) create(d *schema.ResourceData, meta interface{}) error {
  ...
  return r.Read(d, meta)
}

func (r *Resource) read(d *schema.ResourceData, meta interface{}) error {
  ...
  return nil
}

func (r *Resource) delete(d *schema.ResourceData, meta interface{}) error {
  ...
  return nil
}

and then use it like this:

func Provider() terraform.ResourceProvider {
  return &schema.Provider{
    Schema: map[string]*schema.Schema{
      "url": {
        Type:        schema.TypeString,
        Optional:    true,
        DefaultFunc: schema.EnvDefaultFunc("KSQL_SERVER_URL", "http://localhost:8088"),
      },
    },

    ConfigureFunc: providerConfigure,
    ResourcesMap: map[string]*schema.Resource{
      "ksql_table":  Resource{"table"}.GenerateResource(),
      "ksql_stream": Resource{"stream"}.GenerateResource(),
    },
  }
}

🤔 ?!?

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.

2 participants