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

Locate kion.yml in parent directories #12

Open
hongtanner opened this issue Jul 14, 2023 · 0 comments
Open

Locate kion.yml in parent directories #12

hongtanner opened this issue Jul 14, 2023 · 0 comments

Comments

@hongtanner
Copy link

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.

@jonahb jonahb changed the title No option for Kion config file path environment variable Locate kion.yml in parent directories Jul 24, 2023
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

No branches or pull requests

1 participant