taskcat icon indicating copy to clipboard operation
taskcat copied to clipboard

Need to parse an empty parameter_input file

Open ustrahlendorf opened this issue 8 years ago • 14 comments

My cf-template already has the parameters section filled with the needed values. Need to know the structure to parse an empty parameter_input file or a feature to tell taskcat that no parameter_input file is needed.

ustrahlendorf avatar Nov 16 '18 21:11 ustrahlendorf

You should be able to pass an input file that has no key values defined. create the file like this echo "[{}]" >yourrepo/ci/input.json

in the ci/taskcat.yml to reference the input.json as the input file
example here

I have not tested this but it should work. Let us know if it solves your use-case

tonynv avatar Nov 16 '18 23:11 tonynv

I tested it, unfortunately no luck. Here my input.json [{}] Here the output of taskcat: test-project1.log

ustrahlendorf avatar Nov 16 '18 23:11 ustrahlendorf

Can confirm Im getting the same symptoms with [{}] as params file. Investigating cause...

jaymccon avatar Nov 17 '18 01:11 jaymccon

@ustrahlendorf you can use [] successfully. I think that behavior is fine, as a 0 length list works as expected, and if an element is present in the list ([{}]) it is expected to contain a ParameterKey key.

Error message could be better though.

jaymccon avatar Nov 17 '18 01:11 jaymccon

Can confirm that using [] in the parameter_input file works. Thanks for the help. Might be an idea to make it a bit easier for example don't require a parameter_input value, make it optional

ustrahlendorf avatar Nov 17 '18 10:11 ustrahlendorf

Hi folks,

I'm trying to use an empty parameter file with just [] but i'm getting a Traceback.

[INFO   ] :|Processing Overrides
Traceback (most recent call last):
  File "/Users/---/.pyenv/versions/3.6.0/bin/taskcat", line 101, in <module>
    main()
  File "/Users/---/.pyenv/versions/3.6.0/bin/taskcat", line 88, in main
    testdata = tcat_instance.stackcreate(taskcat_cfg, test_list, args.stack_prefix)
  File "/Users/---/.pyenv/versions/3.6.0/lib/python3.6/site-packages/taskcat/stacker.py", line 706, in stackcreate
    s_include_params = self.get_param_includes(s_parms)
  File "/Users/---/.pyenv/versions/3.6.0/lib/python3.6/site-packages/taskcat/stacker.py", line 323, in get_param_includes
    template_params = self.extract_template_parameters()
  File "/Users/---/.pyenv/versions/3.6.0/lib/python3.6/site-packages/taskcat/stacker.py", line 561, in extract_template_parameters
    return self.template_data['Parameters'].keys()
KeyError: 'Parameters'

jofwar avatar Jan 14 '19 17:01 jofwar

Interesting, is the template something you can share? It's throwing a traceback while looking for the 'Parameters' section of your template. What taskcat version is this? Do you see this if you provide a parameter (default value is fine).

andrew-glenn avatar Jan 14 '19 17:01 andrew-glenn

unfortunately i can't share the template due to secrets laced throughout but it essentially just creates roles and policies.. The template itself deploys correctly since it's already in production.
I first used the latest docker image which i believe is version 2018.817.210357. This actually doesn't throw a traceback, instead gives

[INFO   ] :Preparing to launch in region [eu-west-1] 
[INFO   ] :|Processing Overrides
[ERROR  ] :'Parameters'
[FAIL   ] :Cannot launch stackSet.yml

traceback happens with version 0.8.23.

the template doesn't have any parameters so i can't provide a default parameter.

if the template is required i will trim and remove any sensitive data and post it.

EDIT:

I've added a dummy parameter and it seems to work now. Possibly an issue with templates without parameters?

jofwar avatar Jan 15 '19 12:01 jofwar

@jofwar - Thanks for the confirmation - no need to post the template, the traceback gives a bit of a red herring. This is on our radar.

andrew-glenn avatar Jan 15 '19 19:01 andrew-glenn

Fixed in release 0.8.27

sshvans avatar Jan 31 '19 04:01 sshvans

Is this really fixed? I'm using taskcat ver 0.8.30 and I can't seem to get a template without any parameter to run. The template is here: https://github.com/zaro0508/aws-infra/blob/fix-dlm-role/templates/dlm-role.yaml

I tried with following scenarios:

A. empty json (i.e. [{}])
Result: [ERROR  ] :Invalid parameter {} all items must have both ParameterKey and ParameterValue keys

B. remove "parameter_input" from input.json file
Result: No key parameter_input in testdlm-role [ERROR  ] :While inspecting: regions

C. dummy value (i.e. [{"ParameterKey": "dummy", "ParameterValue": "value"}])
Result:
[DEBUG  ] :Parameters:
[DEBUG  ] :Tags:[{'Key': 'owner', 'Value': 'taskcat'}]
Traceback (most recent call last):
  File "/Users/zaro0508/.virtualenvs/py36-taskcat/bin/taskcat", line 101, in <module>
    main()
  File "/Users/zaro0508/.virtualenvs/py36-taskcat/bin/taskcat", line 88, in main
    testdata = tcat_instance.stackcreate(taskcat_cfg, test_list, args.stack_prefix)
  File "/Users/zaro0508/.virtualenvs/py36-taskcat/lib/python3.6/site-packages/taskcat/stacker.py", line 743, in stackcreate
    Tags=self.tags
  File "/Users/zaro0508/.virtualenvs/py36-taskcat/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/zaro0508/.virtualenvs/py36-taskcat/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the CreateStack operation: Parameter values specified for a template which does not require them.

My Environment:

❯❯❯ cat ci/taskcat.yaml 
---
global:
  package-lambda: true
  owner: [email protected]
  qsname: aws-infra
  regions:
    - us-east-1
tests:
  dlm-role:
    parameter_input: dlm-role-input.json
    regions:
      - us-east-1
    template_file: dlm-role.yaml

❯❯❯ python -V
Python 3.6.3

❯❯❯ taskcat --version
0.8.30

❯❯❯ pip freeze                                                                                                                                                 
aws-sam-translator==1.10.0
awscli==1.16.122
boto3==1.9.112
botocore==1.12.112
certifi==2019.3.9
cfn-lint==0.15.0
chardet==3.0.4
colorama==0.3.9
docutils==0.14
idna==2.8
Jinja2==2.10
jmespath==0.9.4
jsonpatch==1.23
jsonpointer==2.0
jsonschema==2.6.0
MarkupSafe==1.1.1
mock==2.0.0
pbr==5.1.3
pyasn1==0.4.5
pyfiglet==0.8.post1
python-dateutil==2.8.0
PyYAML==3.13
requests==2.21.0
rsa==3.4.2
s3transfer==0.2.0
six==1.12.0
tabulate==0.8.3
taskcat==0.8.30
urllib3==1.24.1
yattag==1.11.1

zaro0508 avatar Apr 02 '19 17:04 zaro0508

reopening.

andrew-glenn avatar Apr 02 '19 18:04 andrew-glenn

Decided it's best to tackle in v0.9 as we're doing a bunch of restructuring anyway.

andrew-glenn avatar Jul 22 '19 17:07 andrew-glenn

latest release removes the need for a parameters file altogether. parameters (if needed) can be defined in the project config file. Here's an example with no parameters: https://github.com/aws-quickstart/taskcat/blob/master/tests/data/lint-error/.taskcat.yml and one with a parameter defined https://github.com/aws-quickstart/taskcat/blob/master/tests/data/lambda_build_with_submodules/.taskcat.yml

jaymccon avatar Nov 01 '19 15:11 jaymccon