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

ENV variables are not taking precedence over the plugin config (schema) #371

Closed
arm4b opened this issue Dec 7, 2022 · 1 comment · Fixed by #396
Closed

ENV variables are not taking precedence over the plugin config (schema) #371

arm4b opened this issue Dec 7, 2022 · 1 comment · Fixed by #396
Labels
bug 🪲 Something isn't working plugins
Milestone

Comments

@arm4b
Copy link
Member

arm4b commented Dec 7, 2022

During the plugin deploy stage, if the ENV variable is set for the respective bitops plugin config option, it'll be ignored and the config setting will be applied instead. The expectation is that the ENV always takes precedence.

Example

Example Terraform schema:
https://github.com/bitops-plugins/terraform/blob/ce701be1616cec9420b9ae484e2533ba131cddbf/bitops.schema.yaml#L19-L23
https://bitops.sh/tool-configuration/configuration-terraform/#terraform-bitops-schema

With the following bitops.config.yaml:

terraform:
    cli:
        stack-action: apply
    options: {}

and BITOPS_TERRAFORM_COMMAND=destroy, the terraform apply is executed which is undesired.

Example Docker CLI command:

docker run \
--rm \
-e BITOPS_ENVIRONMENT="test" \
-e BITOPS_LOGGING_LEVEL=DEBUG \
-e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \
-e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \
-e AWS_DEFAULT_REGION="us-east-2" \
-e TF_STATE_BUCKET="heyemoji" \
-e BITOPS_TERRAFORM_COMMAND="destroy" \
-e HEYEMOJI_SLACK_API_TOKEN="$HUBOT_SLACK_TOKEN" \
-v $(pwd):/opt/bitops_deployment \
bitovi/bitops:latest

Will run terraform apply instead of destroy.

Expected behavior

The ENV variable if set should always override the respective bitops.config section based on the plugin schema.

Logs

Based on the logs, BITOPS_TERRAFORM_COMMAND=apply is derived from config:

        NEW SCHEMA:
                Name:         [stack-action]            
                Schema Key:   [terraform.properties.cli.properties.stack-action]            
                Config_Key:   [terraform.cli.stack-action]            
                Schema Type:  [cli]            
                                  
                Export Env:   [TERRAFORM_COMMAND]            
                Default:      [plan]            
                Enabled:      [None]            
                Type:         [string]            
                Parameter:    [None]            
                Dash Type:    [None]            
                Required:     [True]            
                                  
                Value Set:    []
2022-12-07 01:28:49,378 root         DEBUG 
                SEARCHING FOR KEY:  [terraform.cli.stack-action]                      
                SEARCH_DICT:        [{'terraform': {'cli': {'stack-action': 'apply'}, 'options': {}}}]
2022-12-07 01:28:49,378 root         DEBUG 
                KEY [terraform.cli.stack-action] 
                RESULT FOUND:   [apply]
2022-12-07 01:28:49,392 root         INFO 
        Searching for: [terraform.cli.stack-action]
                Result Found: [apply]
2022-12-07 01:28:49,394 root         INFO Override found for: [stack-action], default: [plan], new value: [apply]
[...]
2022-12-07 01:28:49,469 root         DEBUG 
        SCHEMA:
                Name:         [stack-action]            
                Schema Key:   [terraform.properties.cli.properties.stack-action]            
                Config_Key:   [terraform.cli.stack-action]            
                Schema Type:  [cli]            
                                  
                Export Env:   [TERRAFORM_COMMAND]            
                Default:      [plan]            
                Enabled:      [None]            
                Type:         [string]            
                Parameter:    [None]            
                Dash Type:    [None]            
                Required:     [True]            
                                  
                Value Set:    [apply]

~#~#~#~BITOPS ENVIRONMENT VARIABLES~#~#~#~
        BITOPS_TERRAFORM_COMMAND=apply
@PhillypHenning
Copy link
Contributor

Seems to me that this is an issue caused by overriding the env var..

Something like

def add_value_to_env(export_env, value):
    ...
    if value is None or value == "" or value == "None" or export_env is None or export_env == "":
        return

    if os.environ.get('BITOPS_'+export_env):
        logger.info("Environment Varible alredy set. Configuration value ignored.")
        return
    ...

Should fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working plugins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants