briefercloud / layerform

Layerform helps engineers create reusable environment stacks using plain .tf files. Ideal for multiple "staging" environments.

Home Page:https://layerform.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a command to select the current context

vieiralucas opened this issue · comments

Introduce a new command layerform config use-context <name> that will change the current selected context:

For example, if we have a config file like this:

currentContext: foo
contexts:
    bar:
        type: local
        dir: test
    baz:
        type: local
        dir: test
    foo:
        type: s3
        bucket: bucket
        region: us-east-1

Current context is foo

Running layerform config use-context bar, should set the current context to bar, changing the config file to:

currentContext: bar
contexts:
    bar:
        type: local
        dir: test
    baz:
        type: local
        dir: test
    foo:
        type: s3
        bucket: bucket
        region: us-east-1

@vieiralucas Can I work in this issue?

I think the implementation is similar to setting the cfg.CurrentContext in set_context.go.

btw what if the given context (<name>) is the one currently active (currentContext)?

do we return error, or treat it as success

layerform config use-context bar

currentContext: bar
contexts:
    bar:
        type: local
        dir: test

Hi @rafiramadhana, please go ahead. Thank you.

I think the implementation is similar to setting the cfg.CurrentContext in set_context.go.

^ Yes

btw what if the given context (<name>) is the one currently active (currentContext)?

do we return error, or treat it as success

layerform config use-context bar

currentContext: bar
contexts:
    bar:
        type: local
        dir: test

^ We treat it as a success, just check that the given context exists, if it exists, set and save (don't care if it is already current), if it does not exist, then error.