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

feat(ssm): reference existing SSM list parameters #21880

Merged
merged 9 commits into from
Sep 15, 2022
Merged

feat(ssm): reference existing SSM list parameters #21880

merged 9 commits into from
Sep 15, 2022

Conversation

corymhall
Copy link
Contributor

@corymhall corymhall commented Sep 1, 2022

This PR fixes some issues with how SSM parameter types are implemented.
Currently this module models a single type of parameter (ParameterType
enum) and that type is used to represent both CloudFormation SSM
Parameter types

For example,

new cdk.CfnParameter(this, 'Param', {
  type: 'AWS::SSM::Parameter::Value<String>', // type
});

and the AWS::SSM::Parameter.type
For example,

new ssm.CfnParameter(this, 'Param', {
  type: 'String',
});

This overloading caused the issue in the referenced issue as well as
making it more confusing for the user. For example, You can specify a type when
creating a StringParameter, but you shouldn't need to since the only
valid values are String | StringList and these are modeled as two
separate classes StringParameter & StringListParameter.

To address this, the PR introduces a new enum ParameterValueType to
model the CloudFormation SSM Parameter Types. This enum is only used in
the valueForXXX and fromXXX methods since those return a CFN
parameter.

  • Deprecated ssm.StringParameter.valueForTypedStringParameter since it
    uses the old overloaded ParameterType.
    • Introduce a new ssm.StringParameter.valueForTypedStringParameterV2
      that uses the new ParameterValueType enum
  • Add ssm.StringListParameter.valueForTypedListParameter
  • Add ssm.StringListParameter.fromListParameterAttributes
  • Deprecated StringParameterProps.type since the value should only be
    String.

fix #12477, #14364


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

This PR fixes some issues with how SSM parameter types are implemented.
Currently this module models a single type of parameter (`ParameterType`
enum) and that type is used to represent _both_ [CloudFormation SSM
Parameter types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-ssm-parameter-types)
For example,

```ts
new cdk.CfnParameter(this, 'Param', {
  type: 'AWS::SSM::Parameter::Value<String>', // type
});
```

_and_ the [AWS::SSM::Parameter.type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-parameter.html#cfn-ssm-parameter-type)
For example,

```ts
new ssm.CfnParameter(this, 'Param', {
  type: 'String',
});
```

This overloading caused the issue in the referenced issue as well as
making it more confusing for the user. For example, You can specify a type when
creating a `StringParameter`, but you shouldn't need to since the only
valid values are `String | StringList` and these are modeled as two
separate classes `StringParameter & StringListParameter`.

To address this, the PR introduces a new enum `ParameterValueType` to
model the CloudFormation SSM Parameter Types. This enum is only used in
the `valueForXXX` and `fromXXX` methods since those return a CFN
parameter.

- Deprecated `ssm.StringParameter.valueForTypedStringParameter` since it
  uses the old overloaded `ParameterType`.
  - Introduce a new `ssm.StringParameter.valueForTypedStringParameterV2`
    that uses the new `ParameterValueType` enum
- Add `ssm.StringListParameter.valueForTypedListParameter`
- Add `ssm.StringListParameter.fromListParameterAttributes`
- Deprecated `StringParameterProps.type` since the value should only be
  `String`.

fix #12477
@gitpod-io
Copy link

gitpod-io bot commented Sep 1, 2022

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Sep 1, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team September 1, 2022 17:26
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 1, 2022
@Naumel
Copy link
Contributor

Naumel commented Sep 2, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 2, 2022

update

✅ Branch has been successfully updated

@Naumel
Copy link
Contributor

Naumel commented Sep 12, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 12, 2022

update

✅ Branch has been successfully updated

Comment on lines 370 to 378
readonly type?: ParameterType;

/**
* The type of the string parameter value
*
* @default ParameterValueType.STRING
*/
readonly valueType?: ParameterValueType;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The changes look fine, the meta-meta aspect for the names is making me do double-taken when reviewing them.

Could some of the other names you considered make it easier to read, even if it is more verbose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm I'm not sure, I was having a hard time coming up with an alternative for type ha. Any suggestions?

It's definitely confusing because we are modeling two different types of SSM parameters in the same construct, which each have the concept of type.

*
* @default ParameterValueType.STRING
*/
readonly valueType?: ParameterValueType;
Copy link
Contributor

@rix0rrr rix0rrr Sep 15, 2022

Choose a reason for hiding this comment

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

For lists, can we use a term like elementType ? (throughout, where necessary)

* @param type the type of the SSM list parameter
* @param version The parameter version (recommended in order to ensure that the value won't change during deployment)
*/
public static valueForTypedListParameter(scope: Construct, parameterName: string, type = ParameterValueType.STRING, version?: number): string[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does typing this value even add value? (ha)

We return it as a string[] anyway... so does anybody does any checking on the types at all? If so, who?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CloudFormation does the type checking in this case. If you request a ParameterValueType.AWS_EC2_IMAGE_ID it expects the value to be a string in the AMI format, and if it is not it will throw an error.

@Naumel
Copy link
Contributor

Naumel commented Sep 15, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 15, 2022

update

✅ Branch has been successfully updated

@mergify
Copy link
Contributor

mergify bot commented Sep 15, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 145dd4e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 8f7ee2b into aws:main Sep 15, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 15, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Dec 1, 2022
This PR fixes some issues with how SSM parameter types are implemented.
Currently this module models a single type of parameter (`ParameterType`
enum) and that type is used to represent _both_ [CloudFormation SSM
Parameter types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-ssm-parameter-types)
For example,

```ts
new cdk.CfnParameter(this, 'Param', {
  type: 'AWS::SSM::Parameter::Value<String>', // type
});
```

_and_ the [AWS::SSM::Parameter.type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-parameter.html#cfn-ssm-parameter-type)
For example,

```ts
new ssm.CfnParameter(this, 'Param', {
  type: 'String',
});
```

This overloading caused the issue in the referenced issue as well as
making it more confusing for the user. For example, You can specify a type when
creating a `StringParameter`, but you shouldn't need to since the only
valid values are `String | StringList` and these are modeled as two
separate classes `StringParameter & StringListParameter`.

To address this, the PR introduces a new enum `ParameterValueType` to
model the CloudFormation SSM Parameter Types. This enum is only used in
the `valueForXXX` and `fromXXX` methods since those return a CFN
parameter.

- Deprecated `ssm.StringParameter.valueForTypedStringParameter` since it
  uses the old overloaded `ParameterType`.
  - Introduce a new `ssm.StringParameter.valueForTypedStringParameterV2`
    that uses the new `ParameterValueType` enum
- Add `ssm.StringListParameter.valueForTypedListParameter`
- Add `ssm.StringListParameter.fromListParameterAttributes`
- Deprecated `StringParameterProps.type` since the value should only be
  `String`.

fix aws#12477, aws#14364


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-ssm): aws-ssm.ParameterType.STRING_LIST value is incorrect
4 participants