`samconfig.toml` location changes when `--template` is provided
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description:
Running `sam deploy` with `parameter_overrides` specified in the `samconfig.toml` results in the following error message:
> Error: Failed to create changeset for the stack: kubernetes-deployer, An error occurred (ValidationError) when calling the CreateChangeSet operation: Parameters: [FunctionName, BuildVersion, ClusterName, FunctionRoleArn, KopsStateBucket] must have values
### Steps to reproduce:
The `template.yaml`:
```yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: A Lambda function which manages applying configuration changes against a Kubernetes cluster.
Outputs:
FunctionArn:
Description: "The ARN of the Lambda function."
Value: !GetAtt KubernetesDeployer.Arn
Parameters:
BuildVersion:
Description: The version tag to use for the current build of the Lambda image.
Type: String
ClusterName:
Description: The name of the Kubernetes cluster to target.
Type: String
FunctionName:
Description: The name to use for the Lambda function.
Type: String
FunctionRoleArn:
Description: The ARN of the IAM role to assign to the Lambda function.
Type: String
KopsStateBucket:
Description: The name of the S3 bucket which contains the Kops state for the cluster.
Type: String
TimeoutSeconds:
Default: 300
Description: The Lambda execution timeout, in seconds.
Type: Number
Resources:
KubernetesDeployer:
Metadata:
Dockerfile: Dockerfile
DockerContext: ./
DockerTag: !Ref BuildVersion
Properties:
Environment:
Variables:
BUILD_VERSION: !Ref BuildVersion
CLUSTER_NAME: !Ref ClusterName
KOPS_STATE_BUCKET: !Ref KopsStateBucket
TIMEOUT_SECONDS: !Ref TimeoutSeconds
FunctionName: !Ref FunctionName
ImageConfig:
Command: ["app.handler"]
MemorySize: 256
PackageType: Image
Role: !Ref FunctionRoleArn
Timeout: !Ref TimeoutSeconds
Type: AWS::Serverless::Function
Transform: AWS::Serverless-2016-10-31
```
The `samconfig.toml`:
```toml
version = 0.1
[default.build.parameters]
parameter_overrides = ["BuildVersion=SNAPSHOT"]
[default.local_invoke.parameters]
parameter_overrides = ["ClusterName=docker-desktop"]
[preview.deploy.parameters]
parameter_overrides = [
"BuildVersion=SNAPSHOT",
"FunctionName=kubernetes-deployer",
"FunctionRoleArn=",
"ClusterName=",
"KopsStateBucket="
]
```
The `sam deploy` command is run from a `Makefile`:
```
export AWS_REGION ?= us-east-1
export PACKAGE_OUTPUT_TEMPLATE_FILE ?= .aws-sam/build/packaged.yaml
config:
# Generating samconfig.toml
@# Workaround for https://github.com/aws/aws-sam-cli/issues/2380
cat samconfig.template.toml | envsubst | tee samconfig.toml
deploy: config
sam deploy \
--config-env $(CONFIG_ENV) \
--image-repository $(IMAGE_REPOSITORY) \
--region $(AWS_REGION) \
--stack-name $(STACK_NAME) \
--template-file $(PACKAGE_OUTPUT_TEMPLATE_FILE)
```
Although I have also executed this outside of the Makefile manually, with a static configuration -- same result.
Example invocation:
```
BUILD_VERSION=SNAPSHOT CONFIG_ENV=preview IMAGE_REPOSITORY= FUNCTION_NAME=kubernetes-deployer FUNCTION_ROLE_ARN= make deploy
```
### Observed result:
```
sam deploy \
--debug \
--config-env preview \
--image-repository \
--region us-east-1 \
--stack-name kubernetes-deployer \
--template-file .aws-sam/build/packaged.yaml
2022-01-20 16:45:20,060 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-01-20 16:45:20,061 | Using config file: samconfig.toml, config environment: preview
2022-01-20 16:45:20,061 | Expand command line arguments to:
2022-01-20 16:45:20,061 | --template_file=/Users/kflorence/mosaic/github/solarmosaic-internal/mosaic/services/infra/kubernetes-deployer/.aws-sam/build/packaged.yaml --image_repository= --stack_name=kubernetes-deployer --fail_on_empty_changeset
2022-01-20 16:45:20,442 | Collected default values for parameters: {'TimeoutSeconds': 300}
2022-01-20 16:45:20,469 | Sam customer defined id is more priority than other IDs. Customer defined id for resource KubernetesDeployer is KubernetesDeployer
2022-01-20 16:45:20,470 | Unable to resolve property Value: OrderedDict([('Fn::GetAtt', ['KubernetesDeployer', 'Arn'])]). Leaving as is.
2022-01-20 16:45:20,470 | 1 stacks found in the template
2022-01-20 16:45:20,711 | Sam customer defined id is more priority than other IDs. Customer defined id for resource KubernetesDeployer is KubernetesDeployer
2022-01-20 16:45:20,711 | Sam customer defined id is more priority than other IDs. Customer defined id for resource KubernetesDeployer is KubernetesDeployer
2022-01-20 16:45:20,711 | Property ImageUri of KubernetesDeployer is already an ECR URL
Deploying with following values
===============================
Stack name : kubernetes-deployer
Region : us-east-1
Confirm changeset : False
Disable rollback : False
Deployment image repository :
Deployment s3 bucket : None
Capabilities : null
Parameter overrides : {}
Signing Profiles : {}
Initiating deployment
=====================
2022-01-20 16:45:20,796 | Collected default values for parameters: {'TimeoutSeconds': 300}
2022-01-20 16:45:20,813 | Sam customer defined id is more priority than other IDs. Customer defined id for resource KubernetesDeployer is KubernetesDeployer
2022-01-20 16:45:20,814 | Unable to resolve property Value: OrderedDict([('Fn::GetAtt', ['KubernetesDeployer', 'Arn'])]). Leaving as is.
2022-01-20 16:45:20,814 | 1 stacks found in the template
2022-01-20 16:45:20,814 | Collected default values for parameters: {'TimeoutSeconds': 300}
2022-01-20 16:45:20,830 | Sam customer defined id is more priority than other IDs. Customer defined id for resource KubernetesDeployer is KubernetesDeployer
2022-01-20 16:45:20,830 | Unable to resolve property Value: OrderedDict([('Fn::GetAtt', ['KubernetesDeployer', 'Arn'])]). Leaving as is.
2022-01-20 16:45:20,831 | 1 resources found in the stack
2022-01-20 16:45:20,831 | Collected default values for parameters: {'TimeoutSeconds': 300}
2022-01-20 16:45:20,847 | Sam customer defined id is more priority than other IDs. Customer defined id for resource KubernetesDeployer is KubernetesDeployer
2022-01-20 16:45:20,848 | Unable to resolve property Value: OrderedDict([('Fn::GetAtt', ['KubernetesDeployer', 'Arn'])]). Leaving as is.
2022-01-20 16:45:20,848 | Found Serverless function with name='KubernetesDeployer' and ImageUri=''
2022-01-20 16:45:20,848 | --base-dir is not presented, adjusting uri ./ relative to /var/folders/6v/kvpvnmfn7_v0zvb3r4q5ggmrvfbfvf/T/tmpqff8zlri
2022-01-20 16:45:20,848 | --base-dir is not presented, adjusting uri . relative to /var/folders/6v/kvpvnmfn7_v0zvb3r4q5ggmrvfbfvf/T/tmpqff8zlri
2022-01-20 16:45:21,078 | Stack with id kubernetes-deployer does not exist
2022-01-20 16:45:21,385 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '8536e507-352f-4448-bfb2-fbc222cff604', 'installationId': 'f82f3e33-e432-46f5-9f3f-4f37f92f3bd0', 'sessionId': '5f5bae40-7ca2-44ba-bdf1-4e13a1e2c6a8', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.12', 'samcliVersion': '1.37.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': 'us-east-1', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 1324, 'exitReason': 'ChangeSetError', 'exitCode': 1}}]}
2022-01-20 16:45:21,778 | Telemetry response: 200
Error: Failed to create changeset for the stack: kubernetes-deployer, An error occurred (ValidationError) when calling the CreateChangeSet operation: Parameters: [FunctionName, BuildVersion, ClusterName, FunctionRoleArn, KopsStateBucket] must have values
make: *** [deploy] Error 1
```
### Expected result:
The deploy should succeed, all necessary information is provided. Additionally, I would expect `Parameter overrides` to be populated in the output.
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. Mac OS/Linux
2. `sam --version`: SAM CLI, version 1.37.0
3. AWS region: us-east-1
Contributor guide
Assessment
This issue has not been assessed yet.