From ad0f33d27d48809b7e7c362d3c0cb4b813b3bca2 Mon Sep 17 00:00:00 2001 From: Eric Beard Date: Mon, 16 Dec 2024 15:31:02 -0800 Subject: [PATCH 1/4] Adding unit test for building all types --- internal/cmd/build/build.go | 6 ++++++ internal/cmd/build/build_test.go | 21 +++++++++++++++++++++ internal/config/version.go | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/cmd/build/build.go b/internal/cmd/build/build.go index 2d1fc6f8..cc42dfb8 100644 --- a/internal/cmd/build/build.go +++ b/internal/cmd/build/build.go @@ -65,6 +65,10 @@ func buildProp(n *yaml.Node, propName string, prop cfn.Prop, schema cfn.Schema, prop.Type = cfn.ConvertPropType(prop.Type) + if prop.Type == "" && len(prop.OneOf) > 0 || len(prop.AnyOf) > 0 { + prop.Type = "object" + } + switch prop.Type { case "string": if len(prop.Enum) > 0 { @@ -179,6 +183,8 @@ func buildProp(n *yaml.Node, propName string, prop cfn.Prop, schema cfn.Schema, } } } else { + config.Debugf("Missing Ref: %s, ancestors: %v, %+v", + propName, ancestorTypes, prop) return fmt.Errorf("expected blank type to have $ref: %s", propName) } default: diff --git a/internal/cmd/build/build_test.go b/internal/cmd/build/build_test.go index 32284245..1d5482d4 100644 --- a/internal/cmd/build/build_test.go +++ b/internal/cmd/build/build_test.go @@ -2,6 +2,7 @@ package build import ( "os" + "strings" "testing" "github.com/aws-cloudformation/rain/cft" @@ -108,3 +109,23 @@ func Example_omit_read_only() { // FilterType: PREFIX_MATCH } + +func TestAllSchemas(t *testing.T) { + // Make sure rain build works for all schemas + // Sometimes service teams post incorrect schemas and it breaks us + // If something fails here, we need to add a patch + // See internal/aws/cfn/schema.go and patch.go + types, err := cfn.ListResourceTypes(noCache) + if err != nil { + t.Fatal(err) + } + for _, typeName := range types { + if !strings.HasPrefix(typeName, "AWS::") { + continue + } + _, err := build([]string{typeName}) + if err != nil { + t.Errorf("Unable to build type %s: %v", typeName, err) + } + } +} diff --git a/internal/config/version.go b/internal/config/version.go index 5867d8a6..a88796d9 100644 --- a/internal/config/version.go +++ b/internal/config/version.go @@ -5,5 +5,5 @@ const ( NAME = "Rain" // VERSION is the application's version string - VERSION = "v1.20.0" + VERSION = "v1.20.2" ) From b053d632edc6fa1a704bf54255090794175f80c6 Mon Sep 17 00:00:00 2001 From: Eric Beard Date: Tue, 17 Dec 2024 11:52:27 -0800 Subject: [PATCH 2/4] fixed schemas --- docs/index.md | 2 +- docs/rain_bootstrap.md | 2 +- docs/rain_build.md | 2 +- docs/rain_cat.md | 2 +- docs/rain_cc.md | 2 +- docs/rain_cc_deploy.md | 2 +- docs/rain_cc_drift.md | 2 +- docs/rain_cc_rm.md | 2 +- docs/rain_cc_state.md | 2 +- docs/rain_console.md | 2 +- docs/rain_deploy.md | 2 +- docs/rain_diff.md | 2 +- docs/rain_fmt.md | 2 +- docs/rain_forecast.md | 2 +- docs/rain_info.md | 2 +- docs/rain_logs.md | 2 +- docs/rain_ls.md | 2 +- docs/rain_merge.md | 2 +- docs/rain_module.md | 2 +- docs/rain_module_bootstrap.md | 2 +- docs/rain_module_install.md | 2 +- docs/rain_module_publish.md | 2 +- docs/rain_pkg.md | 2 +- docs/rain_rm.md | 2 +- docs/rain_stackset.md | 2 +- docs/rain_stackset_deploy.md | 2 +- docs/rain_stackset_ls.md | 2 +- docs/rain_stackset_rm.md | 2 +- docs/rain_tree.md | 2 +- docs/rain_watch.md | 2 +- go.mod | 6 +- go.sum | 6 + internal/aws/cfn/patch.go | 67 + internal/aws/cfn/schema.go | 8 + .../aws/autoscaling/autoscalinggroup.json | 14 +- .../schemas/aws/cloudformation/guardhook.json | 5 +- .../aws/cloudformation/lambdahook.json | 5 +- .../aws/cfn/schemas/aws/databrew/dataset.json | 18 + .../aws/cfn/schemas/aws/ec2/ec2fleet.json | 57 + .../aws/cfn/schemas/aws/ec2/spotfleet.json | 1305 +++++++++-------- internal/aws/cfn/schemas/aws/emr/studio.json | 8 +- .../schemas/aws/emr/studiosessionmapping.json | 27 +- .../cfn/schemas/aws/imagebuilder/image.json | 3 +- .../schemas/aws/internetmonitor/monitor.json | 8 +- .../schemas/aws/lambda/eventinvokeconfig.json | 6 +- .../aws/cfn/schemas/aws/lambda/function.json | 8 +- .../aws/cfn/schemas/aws/logs/integration.json | 3 +- internal/aws/cfn/schemas/aws/pcs/cluster.json | 332 +++++ .../cfn/schemas/aws/pcs/computenodegroup.json | 337 +++++ internal/aws/cfn/schemas/aws/pcs/queue.json | 177 +++ internal/cmd/build/build.go | 8 + 51 files changed, 1763 insertions(+), 705 deletions(-) create mode 100644 internal/aws/cfn/schemas/aws/pcs/cluster.json create mode 100644 internal/aws/cfn/schemas/aws/pcs/computenodegroup.json create mode 100644 internal/aws/cfn/schemas/aws/pcs/queue.json diff --git a/docs/index.md b/docs/index.md index 06b96507..92f9e2e8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,4 +36,4 @@ Rain is a command line tool for working with AWS CloudFormation templates and st * [rain tree](rain_tree.md) - Find dependencies of Resources and Outputs in a local template * [rain watch](rain_watch.md) - Display an updating view of a CloudFormation stack -###### Auto generated by spf13/cobra on 16-Dec-2024 +###### Auto generated by spf13/cobra on 17-Dec-2024 diff --git a/docs/rain_bootstrap.md b/docs/rain_bootstrap.md index dfd6d68e..ae84fce3 100644 --- a/docs/rain_bootstrap.md +++ b/docs/rain_bootstrap.md @@ -33,4 +33,4 @@ rain bootstrap * [rain](index.md) - -###### Auto generated by spf13/cobra on 16-Dec-2024 +###### Auto generated by spf13/cobra on 17-Dec-2024 diff --git a/docs/rain_build.md b/docs/rain_build.md index 1fa0a6d8..04946f77 100644 --- a/docs/rain_build.md +++ b/docs/rain_build.md @@ -41,4 +41,4 @@ rain build [] or * [rain](index.md) - -###### Auto generated by spf13/cobra on 16-Dec-2024 +###### Auto generated by spf13/cobra on 17-Dec-2024 diff --git a/docs/rain_cat.md b/docs/rain_cat.md index b29c2398..8f5e6593 100644 --- a/docs/rain_cat.md +++ b/docs/rain_cat.md @@ -35,4 +35,4 @@ rain cat * [rain](index.md) - -###### Auto generated by spf13/cobra on 16-Dec-2024 +###### Auto generated by spf13/cobra on 17-Dec-2024 diff --git a/docs/rain_cc.md b/docs/rain_cc.md index a65de5bd..b8e9c65f 100644 --- a/docs/rain_cc.md +++ b/docs/rain_cc.md @@ -33,4 +33,4 @@ You must pass the --experimental (-x) flag to use this command, to acknowledge t * [rain cc rm](rain_cc_rm.md) - Delete a deployment created by cc deploy (Experimental!) * [rain cc state](rain_cc_state.md) - Download the state file for a template deployed with cc deploy -###### Auto generated by spf13/cobra on 16-Dec-2024 +###### Auto generated by spf13/cobra on 17-Dec-2024 diff --git a/docs/rain_cc_deploy.md b/docs/rain_cc_deploy.md index d72ea64c..c4e50e06 100644 --- a/docs/rain_cc_deploy.md +++ b/docs/rain_cc_deploy.md @@ -40,4 +40,4 @@ rain cc deploy