bitovi/bitops

CLI args to the plugins are not passed

arm4b opened this issue · 5 comments

arm4b commented

Originally found in bitops-plugins/terraform#20.

BitOps core implements plugin schema parsing

However, populating and passing the raw CLI args based on the plugin schema is not implemented:

terraform:
  type: object
  properties:
    cli:
      backend-config:
        type: list
        parameter: backend-config
        dash_type: "-"

This means it's not possible to just add the new CLI param in the plugin schema and consider it'll be sent to the plugins's binary even if plugin.deployment.core_schema_parsing: true in the plugin.config.yaml.

Testing

I agree that this functionality is no longer working;

bitops.config.yaml

terraform:
  cli:  
    backend-config:
        type: list
        parameter: backend-config
        dash_type: "-"
    stack-action: destroy
  options: {}
2022-11-21 20:40:09,569 root         DEBUG 
        SCHEMA:
                Name:         [backend-config]            
                Schema Key:   [terraform.properties.cli.properties.backend-config]            
                Config_Key:   [terraform.cli.backend-config]            
                Schema Type:  [cli]            
                                  
                Export Env:   [None]            
                Default:      [None]            
                Enabled:      [None]            
                Type:         [list]            
                Parameter:    [backend-config]            
                Dash Type:    [-]            
                Required:     [None]            
                                  
                Value Set:    [['type', 'parameter', 'dash_type']]

Actually thinking about this. I'm not sure this is even what we should offer...

Instead I think it would be better to offer (across all plugins) an EXTRA_VARS value that allows individuals to specify flags, k/v pairs, etc and just merge it into the command appropriately.

Example;

terraform apply <EXTRA_VARS applied here>

@mickmcgrath13 and @armab

bitops-plugins/ansible seems to already use this in fact

extra-vars:
          type: string
          parameter: extra-vars
          export_env: ANSIBLE_EXTRA_VARS
armab commented

Good idea! An EXTRA_ARGS ENV var (and respective extra_args setting in the bitops.config.yaml) user can set to pass to the plugin might be an option 👍
I'd normally think about a more structured YAML param approach, but this sounds good and simple enough:

terraform:
  cli:
    stack-action: plan
    extra_args: "-out=<path> -parallelism=<n> -var='foo=bar'"
  options: {}

Which will produce:

terraform plan -out=<path> -parallelism=<n> -var='foo=bar'
armab commented

Looking deeper, EXTRA_ARGS could be an additional option, but it doesn't solve the root problem with the schema and passing params to the plugins. As experienced in the bitovi/github-actions-deploy-stackstorm#49 and bitops-plugins/ansible#10, the big part of the schema is not implemented on the plugin side.

Here is what we currently do:

Now we're creating a bash logic for every possible CLI param in the plugin.
Example ansible/deploy.sh

 # Check if the BITOPS_ANSIBLE_INVENTORY value is set 
 if [ -n "$BITOPS_ANSIBLE_INVENTORY" ]; then 
   BITOPS_CONFIG_COMMAND="$BITOPS_CONFIG_COMMAND --inventory-file=$BITOPS_ANSIBLE_INVENTORY" 
 fi

with the ansible/bitops.schema.yaml

 inventory: 
   type: string 
   parameter: inventory 
   export_env: ANSIBLE_INVENTORY

This is not scalable as logic needs to be added for every possible CLI param.

Here is what we should be doing

Ansible bitops.schema.yaml

 inventory: 
   type: string 
   parameter: inventory-file
   export_env: ANSIBLE_INVENTORY

should generate the following ENV var passed to the plugin:

BITOPS_COMMAND="--inventory-file=$BITOPS_ANSIBLE_INVENTORY"