Skip to content

Locate kion.yml in parent directories #12

@hongtanner

Description

@hongtanner

Hi Corbalt team! I have a somewhat of an issue when trying to use your Kion tool: there is no option to set the path of the kion.yml config file. Here is what I mean.

We use Terragrunt, and here is an example of our repository for our IaC:

test git:(main) ✗ tree
.
├── .envrc
├── account.hcl
├── kion.yml
└── us-east-1
    ├── api
    │   ├── 00_api_fargate
    │   │   └── terragrunt.hcl
    │   └── env.hcl
    ├── base
    │   ├── 00_api_gateway
    │   │   └── terragrunt.hcl
    │   ├── 00_cms_securityhub_notifications
    │   │   └── terragrunt.hcl
    │   ├── 00_cmscloud
    │   │   └── terragrunt.hcl
...

In my kion.yml file is this:

test git:(main) ✗ cat kion.yml 
account-id: xxxxxxxxx461
cloud-access-role: mct-application-admin

And inside my .envrc file is this:

source_up
export AWS_PROFILE=kion

So, if I am inside the test directory and run aws sts get-caller-identity or a Terragrunt command, the Kion tool works as expected.

However, if I go into any of the subdirectories and try to do the same, I get an error since the kion.yml config file isn't in that subdirectory and it can't be found.

I would like to request an option be given to add a KION_CONFIG_PATH environment variable that can be used to find the kion.yml file no matter the location. For example, the go code can be updated like so:

func main() {
	var configPaths []string
	val, kionConfigPathEnvSet := os.LookupEnv("KION_CONFIG_PATH")

	userConfigName, err := config.UserConfigName()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	if kionConfigPathEnvSet {
		configPaths = []string{
			userConfigName,
			filepath.Join("/", val),
		}
	} else {
		configPaths = []string{
			userConfigName,
			filepath.Join(".", "kion.yml"),
		}
	}

I'm not a Go expert, so this could likely be improved upon.

Then, inside of my .envrc file I can add a line for the config path:

source_up
export AWS_PROFILE=kion
export KION_CONFIG_PATH=$PWD/kion.yml

Now, no matter which subdirectory I am in under the test directory, the kion.yml file can be found and used. This would help make the tool more flexible. Without this option we would need this kion.yml config file in all of our subdirectories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions