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

[Resolve #1468] Cast parameters to strings #1471

Merged
merged 11 commits into from
Jul 3, 2024

Conversation

alex-harvey-z3q
Copy link
Contributor

@alex-harvey-z3q alex-harvey-z3q commented Jun 2, 2024

In already-resolved and merged issue #1443 we implemented parameter validation.

Subsequent discussion led to a consensus that it would be better to not only validate parameters, but also cast where applicable to string. This will lead to a cleaner user experience for most Sceptre users where parameters passed as ints, floats and bools in their YAML values files are cast to strings first and then sent to CloudFormation, since CloudFormation's API is unable to handle other types.

This PR changes the _ensure_parameters method to _cast_parameters in the Stack class to handle casting to strings where applicable instead of only validating.

PR Checklist

  • Wrote a good commit message & description [see guide below].
  • Commit message starts with [Resolve #issue-number].
  • Added/Updated unit tests.
  • Added/Updated integration tests (if applicable).
  • All unit tests (poetry run tox) are passing.
  • Used the same coding conventions as the rest of the project.
  • The new code passes pre-commit validations (poetry run pre-commit run --all-files).
  • The PR relates to only one subject with a clear title.
    and description in grammatically correct, complete sentences.

Approver/Reviewer Checklist

  • Before merge squash related commits.

Other Information

Guide to writing a good commit

In already-resolved and merged issue Sceptre#1443 we implemented parameter
validation.

Subsequent discussion led to a consensus that it would be better to not
only validate parameters, but also cast where applicable to string. This
will lead to a cleaner user experience for most Sceptre users where
parameters passed as ints, floats and bools in their YAML values files
are cast to strings first and then sent to CloudFormation, since
CloudFormation's API is unable to handle other types.

This PR changes the behaviour of the `_ensure_parameters` method in the
Stack class to handle casting to strings where applicable instead of
only validating.
Copy link
Contributor

@zaro0508 zaro0508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In already-resolved and merged issue #1443 we implemented parameter validation.

the PR for that issue was not merged?

Otherwise, in general this PR LGTM but would like the method to be more concise and clear.

sceptre/stack.py Show resolved Hide resolved
@alex-harvey-z3q
Copy link
Contributor Author

alex-harvey-z3q commented Jun 29, 2024

the PR for that issue was not merged?

It was merged in f3b7e51 but we have never released those changes thus no users will be impacted by this change to the earlier implementation (unless they are consuming the master branch).

Copy link
Contributor

@zaro0508 zaro0508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the clarification

@alex-harvey-z3q alex-harvey-z3q merged commit f96d4b3 into Sceptre:master Jul 3, 2024
11 checks passed
@alex-harvey-z3q alex-harvey-z3q deleted the ah/1468-cast-params branch July 3, 2024 01:46
@fen9li
Copy link
Contributor

fen9li commented Sep 10, 2024

Hey Alex,

Good day. I received an error may have something to do with this merge.

My config/bla-bla/config.yaml file looks like below:

---
sceptre_role: <aws-role-arn>

environment: bla-bla
application: bla-bla
accountid: <aws-account-id>
instance_type: t3.large
db_instance_type: db.t3.small
license_model: license-included
db_storage: '40'
multi_az: 'false'
restore_db_snapshot_identifier: 'null'

stack_tags_env:
  xxxxxx: xxxxxx

The error:

[2024-09-09T12:43:16.398Z] + sceptre --var-file config/config.yaml --var-file config/bla-bla/config.yaml launch -y bla-bla

[2024-09-09T12:43:16.964Z] "bla-bla/rds-instances: Values for parameters must be strings, lists or resolvers, got {'Environment': 'bla-bla', 'Application': 'bla-bla', 'RDSMasterUser': <username>, 'RDSMasterUserPassword': <password>, 'InstanceType': 'db.t3.small', 'LicenseModel': 'license-included', 'AllocatedStorageGB': '40', 'MultiAZ': 'false', 'RestoreDBSnapshotIdentifier': None}"

script returned exit code 1

I reckon that the string 'null' in my config/bla-bla/config.yaml somehow converted to None and failed the new added validation. Any chance to add one more test {"NullAsString": "null"}, here:

 "parameters",
        [
            {"IntAsString": "1"},
            {"Int": 1},
            {"BoolAsString": "true"},
            {"Bool": True},
            {"List": ["aStringAndA", FakeResolver()]},
            {"ListOfInts": [1, 2, 3]},
            {"Resolver": FakeResolver()},
        ],

So we can know if there is any bug here? Thank you very much.
Feng

@fen9li
Copy link
Contributor

fen9li commented Sep 10, 2024

Hey Alex,

I fixed the issue already. Need adding "" to the value when passed down like below.

 RestoreDBSnapshotIdentifier: "{{ var.restore_db_snapshot_identifier }}"

Thanks.
Feng

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

Successfully merging this pull request may close these issues.

3 participants