Skip to content

design: samconfig#1503

Merged
sriram-mv merged 8 commits intoaws:release-v0.32.0from
sriram-mv:sam-app-config-design
Nov 13, 2019
Merged

design: samconfig#1503
sriram-mv merged 8 commits intoaws:release-v0.32.0from
sriram-mv:sam-app-config-design

Conversation

@sriram-mv
Copy link
Contributor

@sriram-mv sriram-mv commented Nov 5, 2019

  • a configuration that provides parameter pass throughs for
    sam cli commands

  • Write Design Document (Do I need to write a design document?)

  • Write unit tests

  • Write/update functional tests

  • Write/update integration tests

  • make pr passes

  • Write documentation

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

- an app level configuration that provides parameter pass throughs for
  sam cli commands
Copy link
Contributor

@awood45 awood45 left a comment

Choose a reason for hiding this comment

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

Some feedback.


* `sam package --s3-bucket ... --template-file ... --output-template-file ... --s3-prefix ... --kms-key-id ...`

* `sam deploy deploy --template-file ... --stack-name ... --capabilities ... --tags ... --parameter-overrides ... --kms-key-id ...`
Copy link
Contributor

Choose a reason for hiding this comment

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

sam deploy deploy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

* `sam package`
* `sam deploy`

That would be a huge user experience win.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add to the problem some more considerations:

  • Dev/Beta/PreProd/Prod workflows may vary and need to be reflected somehow.
  • There is a tie-in with ~/.aws/credentials and ~/.aws/config to respect, or at least to keep consistent in some way.
  • A solution should allow for overriding of any defaults - explicit parameter choices should always be respected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily. ~/.aws/credentials and ~/.aws/config are global files. Yes, explicit parameter will always be respected. I can add that under a section called tenets.

Copy link
Contributor

Choose a reason for hiding this comment

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

Those are global config files, but do we want the same profile identifier to work for both? Why or why not? Let's make a conscious decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can always leave the door open for identifiers, but I'd prefer not to start with one. It may conflate expectations with aws profiles.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to start with simple, as long as we keep door open to add profiles in future if needed


The suite of commands supported by SAM CLI would be aided by looking for a configuration file thats locally located to the template.yaml by default.

`.aws-sam/sam-app-config`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an .aws-sam directory relative to the project? Would we want to conflate this with build directories like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, its where build artifacts go today.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd want to separate these concepts. I don't think there's any harm to having this expected to exist at project root, or to be otherwise specified. (On that note, we should support an ENV variable for this possibly).


Sample configuration file

```
Copy link
Contributor

Choose a reason for hiding this comment

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

INI format?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, do we want to consider user profiles in a way that aligns with AWS CLI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is toml. looks similair to ini but understands types better. pip today respects pyproject.toml. I'd rather have multiple configuration files, similar to how parameter overrides usually denote different environments.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure toml supports what we want. I am ok with it but I prefer us to not support multiple configuration files. The upkeep on that might be more than we originally think.

Out-of-Scope
------------

* Not focusing on a global configuration. SAM CLI already has a notion of a global config at `~/.aws-sam/metadata.json`
Copy link
Contributor

Choose a reason for hiding this comment

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

Different in nature. In the future, could always support a global configuration file in ~/.aws-sam/ - it doesn't conflict with metadata.json existing. It's an intentional choice because a global config may not make sense for this problem.

region="us-east-1"
profile="srirammv"
```

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be worth mentioning how this config file will be bootstrapped. By hand? By a helper command? Via init? Some combination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This design does not cover for that scenario, but can account for potential directions forward.


The suite of commands supported by SAM CLI would be aided by looking for a configuration file thats locally located to the template.yaml by default.

`.aws-sam/sam-app-config`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why sam-app-config? Should we simplify this further to samconfig?

I am confused on the placement within .aws-sam. To this point, this directory is generated by the cli directly (to ensure correct permissions, mainly). With this, we are suggestion to customers that they need to now create this directory. This might be ok if the entry point was through a command (sam config generate) but we aren't that far yet. Why not place this within the root of the project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can move it up to the project root, to me this configuration was very specific to the app the user was working on at that point. Also might prevent accidental checking it in to source control, since we ignore the .aws-sam directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sam-app-config because it doesn't change the inherent behavior of SAM CLI, its a pass through of parameters.


Sample configuration file

```
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure toml supports what we want. I am ok with it but I prefer us to not support multiple configuration files. The upkeep on that might be more than we originally think.

CLI Changes
-----------

New command line argument is added per command called `--config` to be able to specify non default locations of config files
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we wouldn't want a command to not have the --config option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

generate-event consists of tons of subcommands, that may be a place where config might not be used as much. But we can add it across all commands.

What will be changed?
---------------------

The suite of commands supported by SAM CLI would be aided by looking for a configuration file thats locally located to the template.yaml by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work with build then? We have (at least try to) trained customers to operate on their source. In cases of build, we generate a new template for them (that they shouldn't care about). This means in some cases, we would pick the config in the source but others (that have run build before) we will be looking at the built template. Lets be strong on where this should live, otherwise this can be a point of confusion for customers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to project level with an option to set the location of the configuration file with a environment variable.

Documentation Changes
=====================

* Addition of a new `--config` file parameter per command
Copy link
Contributor

Choose a reason for hiding this comment

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

What about docs page about the config, what it does, how/why you should use it?

@sriram-mv
Copy link
Contributor Author

open to modification of --identifier. it could be environment, mode, config.

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

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

This looks awesome! Very powerful capability. I know we are rushing this quick, but I would like if you can explain all the other ways this feature can be extended in the future such as global + project-level config, checking the config into Git repo, multiple config files with a naming convention, etc.

Also, can you elaborate on how a users can use --debug to understand how SAM CLI read the config?

```


The default location of a .sam-config can be replaced by overriding an environment variable called `SAM_CONFIG`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this consistent with other env vars names? Should we make this SAM_CLI_CONFIG?


The suite of commands supported by SAM CLI would be aided by looking for a configuration file thats locally located at the project root where template.yaml is located by default.

`.sam-app-config`
Copy link
Contributor

Choose a reason for hiding this comment

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

change?

====================================


What is the problem?
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide a bigger scope

@@ -0,0 +1,282 @@
SAM CLI App Level Config
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this "SAM Config" in general then?

Be default the `default` section of the configuration is chosen.

```
[default]
Copy link
Contributor

Choose a reason for hiding this comment

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

awesome!

region="us-east-1"
profile="srirammv"

[dev]
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes much more sense to me. I like this


Users can pass an identifier for the section that will be scanned within the configuration file to pass parameters through.

Be default the `default` section of the configuration is chosen.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: By default

skip_pull_image=true
use_container=true

[default.package]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not overly familiar with TOML but is this required? What would we place in this section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its to showcase nesting, its theoretically not required, so I'll remove it for brevity.


* Potentially every sam command could have functionality to have a series of command line parameters exported into a configuraion file.

Tenets
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: consider moving this up before "What will be changed?". Might help set some context and be easier to reference and update when we make changes in the future.

- todo add more scope
@sriram-mv sriram-mv force-pushed the sam-app-config-design branch from 2273fc8 to fc91010 Compare November 12, 2019 06:46
@sriram-mv sriram-mv changed the title design: sam-app-config design: samconfig Nov 12, 2019

Optionally, if multiple configuration files are checked in. One can change the `SAM_CLI_CONFIG` environment variable to point a different configuration file.

`--env` can also be passed in to deal with custom environments defined in the configuration file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use a different parameter name than this, something more descriptive/connected to the config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to suggestions.

* Read `--env` to make sure we can select an appropriate portion in configuration file.


`.samrc` Changes
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR is samrc. Can you actually rename this part of the design doc template to call it samconfig instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure.


`
sam build --env devo
Error: Environment 'devo' was not found in .aws-sam/samconfig.toml , Possible environments are : ['dev', 'prod']
Copy link
Contributor

Choose a reason for hiding this comment

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

Good job on the thinking ahead about error messages.

Test Scenarios/Cases
--------------------

* Integration tests for every command with identifer based overrides, and command line overrides on existing sam configuration file and custom configuration file through environment variables.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/identifier/env


N/A

Test Scenarios/Cases
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you plan to verify that the config file with every single CLI command we have today and in future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets add a configuration file version number

Documentation Changes
=====================

* Addition of a new `--env` parameter per command
Copy link
Contributor

Choose a reason for hiding this comment

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

Also need documentation on how to write the config file. How to specify flags like --debug that don't have explicit values. How to verify whether a config file is parsable or not.

@sriram-mv sriram-mv changed the base branch from develop to release-v0.32.0 November 13, 2019 19:00
@sriram-mv sriram-mv merged commit 865e6b3 into aws:release-v0.32.0 Nov 13, 2019
sriram-mv added a commit that referenced this pull request Nov 20, 2019
* design: sam-app-config

- an app level configuration that provides parameter pass throughs for
  sam cli commands

* design: move config file location to project root

* design: add open questions

* fix: add `identifiers` to use configuration file.

* fix: address comments

- todo add more scope

* fix: address future and scope

* phases: implementation phases

* fix: add docs section for samconfig
sriram-mv added a commit that referenced this pull request Nov 23, 2019
* design: sam-app-config

- an app level configuration that provides parameter pass throughs for
  sam cli commands

* design: move config file location to project root

* design: add open questions

* fix: add `identifiers` to use configuration file.

* fix: address comments

- todo add more scope

* fix: address future and scope

* phases: implementation phases

* fix: add docs section for samconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants