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

Implemented Rain::Env for pkg command #140

Merged
merged 2 commits into from
May 26, 2023
Merged

Implemented Rain::Env for pkg command #140

merged 2 commits into from
May 26, 2023

Conversation

null93
Copy link
Collaborator

@null93 null93 commented May 26, 2023

Description of Changes:

I find it very useful to inject environmental variables into the template. Some use cases would include injecting a default AMI name into a template based on what environment the template is being packaged for (staging/production). For me this happens during CI/CD.

Expected Behavior

The name of the environmental variable is passed as the only argument to Rain::Env.

If the environmental variable does not exist, then an error is returned, otherwise the value of the environmental variable is injected into the template as a string.

Example

Given a file named template.yaml with the following contents:

AWSTemplateFormatVersion: "2010-09-09"

Description: Template generated by rain

Parameters:
  ImageId:
    Type: String
    Default: !Rain::Env AMI_IMAGE

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref ImageId
      InstanceType: c6g.xlarge
      # ...

Running the following command:

export AMI_IMAGE=ami-1234567890
rain pkg template.yml

Should result in a template that looks like this:

AWSTemplateFormatVersion: "2010-09-09"

Description: Template generated by rain

Parameters:
  ImageId:
    Type: String
    Default: ami-1234567890

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref ImageId
      InstanceType: c6g.xlarge
      # ...

Additional Changes

I added some tests to for #136 as promised :)


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ericzbeard ericzbeard merged commit 0d5ae2b into aws-cloudformation:main May 26, 2023
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.

2 participants