Skip to content

Commit

Permalink
Allow empty values in provisioning parameters
Browse files Browse the repository at this point in the history
Remove check for empty value in order to allow an empty string to pass through
to the CloudFormation template.

Update tests to use provisioning parameters in order to exercise this
functionality.

Fixes hashicorp#21349
  • Loading branch information
wedge-jarrad committed Nov 8, 2021
1 parent de17e73 commit 2b041e4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/service/servicecatalog/provisioned_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func expandServiceCatalogProvisioningParameter(tfMap map[string]interface{}) *se
apiObject.Key = aws.String(v)
}

if v, ok := tfMap["value"].(string); ok && v != "" {
if v, ok := tfMap["value"].(string); ok {
apiObject.Value = aws.String(v)
}

Expand Down Expand Up @@ -629,7 +629,7 @@ func expandServiceCatalogUpdateProvisioningParameter(tfMap map[string]interface{
apiObject.UsePreviousValue = aws.Bool(v)
}

if v, ok := tfMap["value"].(string); ok && v != "" {
if v, ok := tfMap["value"].(string); ok {
apiObject.Value = aws.String(v)
}

Expand Down
45 changes: 44 additions & 1 deletion internal/service/servicecatalog/provisioned_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestAccServiceCatalogProvisionedProduct_basic(t *testing.T) {
"accept_language",
"ignore_errors",
"provisioning_artifact_name",
"provisioning_parameters",
"retain_physical_resources",
},
},
Expand Down Expand Up @@ -175,11 +176,33 @@ resource "aws_s3_bucket_object" "test" {
content = jsonencode({
AWSTemplateFormatVersion = "2010-09-09"
Parameters = {
VPCPrimaryCIDR = {
Type = "String"
}
LeaveMeEmpty = {
Type = "String"
Description = "Make sure that empty values come through. Issue #21349"
}
}
"Conditions" = {
"IsEmptyParameter" = {
"Fn::Equals" = [
{
"Ref" = "LeaveMeEmpty"
},
"",
]
}
}
Resources = {
MyVPC = {
Type = "AWS::EC2::VPC"
Condition = "IsEmptyParameter"
Properties = {
CidrBlock = "10.1.0.0/16"
CidrBlock = { Ref = "VPCPrimaryCIDR" }
}
}
}
Expand Down Expand Up @@ -268,6 +291,16 @@ resource "aws_servicecatalog_provisioned_product" "test" {
product_id = aws_servicecatalog_product.test.id
provisioning_artifact_name = %[1]q
path_id = data.aws_servicecatalog_launch_paths.test.summaries[0].path_id
provisioning_parameters {
key = "VPCPrimaryCIDR"
value = "10.1.0.0/16"
}
provisioning_parameters {
key = "LeaveMeEmpty"
value = ""
}
}
`, rName))
}
Expand All @@ -281,6 +314,16 @@ resource "aws_servicecatalog_provisioned_product" "test" {
provisioning_artifact_name = %[1]q
path_id = data.aws_servicecatalog_launch_paths.test.summaries[0].path_id
provisioning_parameters {
key = "VPCPrimaryCIDR"
value = "10.2.0.0/16"
}
provisioning_parameters {
key = "LeaveMeEmpty"
value = ""
}
tags = {
%[2]q = %[3]q
}
Expand Down

0 comments on commit 2b041e4

Please sign in to comment.