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

introduce stage dimension to spec variables #1795

Open
motatoes opened this issue Nov 5, 2024 · 0 comments
Open

introduce stage dimension to spec variables #1795

motatoes opened this issue Nov 5, 2024 · 0 comments

Comments

@motatoes
Copy link
Contributor

motatoes commented Nov 5, 2024

I just noticed this part of the code:

justNames := lo.Map(variablesSpec, func(item spec.VariableSpec, i int) string {

	variablesSpec := make([]spec.VariableSpec, 0)
	stateVariables := getVariablesSpecFromEnvMap(jobSpec.StateEnvVars)
	commandVariables := getVariablesSpecFromEnvMap(jobSpec.CommandEnvVars)
	runVariables := getVariablesSpecFromEnvMap(jobSpec.RunEnvVars)
	variablesSpec = append(variablesSpec, stateVariables...)
	variablesSpec = append(variablesSpec, commandVariables...)
	variablesSpec = append(variablesSpec, runVariables...)

	// check for duplicates in list of variablesSpec
	justNames := lo.Map(variablesSpec, func(item spec.VariableSpec, i int) string {
		return item.Name
	})
	hasDuplicates := len(justNames) != len(lo.Uniq(justNames))
	if hasDuplicates {
		return nil, fmt.Errorf("could not load variables due to duplicates")
	}

and it seems that we combine all of state, commands and run variables into a single list and then send them to a cli. Furthermore we are checking for duplicates accross all of the variables which is incorrect. For context digger.yml has variables defined like this:

workflows:
  staging:
    env_vars:
      state:
        - name: TF_LOG
          value: trace
      commands:
workflows:
  staging:
    env_vars:
      state:
        - name: TF_LOG
          value: trace
      commands:
        - name: AWS_ACCESS_KEY_ID
          value_from: STAGING_TF_ACCESS_KEY_ID 
      run:
        - name: MY_VAR
          value_from: VAL_ENV

What we are doing in that code block is combining all three types into one list and checking for duplicates which is incorrect. What we are also doing on the cli is we are exposing each variable in all three stages. What we should do instead:

  • check for duplication only in state individually, command individually, run individually
  • add an atribute to spec variable "stage" which can be state, commands, run
  • ensure that in the cli the variables are parsed to their correct stages

In the future we might have a key called "all" for variables that are exposed to all stages

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