Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 9d26275

Browse files
authored
Merge pull request #53 from ergomake/validate-before-configure
validate layers before provisioning
2 parents a2d54c7 + 2727464 commit 9d26275

File tree

8 files changed

+417
-149
lines changed

8 files changed

+417
-149
lines changed

cmd/cli/configure.go

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ package cli
22

33
import (
44
"context"
5-
"fmt"
65
"os"
7-
"time"
86

9-
"github.com/briandowns/spinner"
107
"github.com/hashicorp/go-hclog"
118
"github.com/spf13/cobra"
129

1310
"github.com/pkg/errors"
1411

15-
"github.com/ergomake/layerform/internal/layerfile"
12+
"github.com/ergomake/layerform/internal/command"
1613
"github.com/ergomake/layerform/internal/lfconfig"
1714
)
1815

@@ -73,81 +70,18 @@ Here's an example layer definition configurations:
7370
return errors.Wrap(err, "fail to get --file flag, this is a bug in layerform")
7471
}
7572

76-
s := spinner.New(
77-
spinner.CharSets[14],
78-
60*time.Millisecond,
79-
spinner.WithWriter(os.Stdout),
80-
spinner.WithSuffix(
81-
fmt.Sprintf(
82-
" Loading layer definitions from \"%s\"\n",
83-
fpath,
84-
),
85-
),
86-
)
87-
s.Start()
88-
89-
layerfile, err := layerfile.FromFile(fpath)
90-
if err != nil {
91-
return errors.Wrap(err, "fail to read layerform layers definitions from file")
92-
}
93-
94-
layers, err := layerfile.ToLayers()
95-
if err != nil {
96-
return errors.Wrap(err, "fail to load layers from layerform layers definitions file")
97-
}
98-
99-
if len(layers) == 0 {
100-
s.Stop()
101-
return errors.Errorf("No layers are defined at \"%s\"\n", fpath)
102-
}
103-
104-
s.FinalMSG = fmt.Sprintf(
105-
"✓ %d %s loaded from \"%s\"\n",
106-
len(layers),
107-
pluralize("layer", len(layers)),
108-
fpath,
109-
)
110-
s.Stop()
111-
11273
layersBackend, err := cfg.GetLayersBackend(ctx)
11374
if err != nil {
11475
return errors.Wrap(err, "fail to get layers backend")
11576
}
11677

117-
s = spinner.New(
118-
spinner.CharSets[14],
119-
60*time.Millisecond,
120-
spinner.WithWriter(os.Stdout),
121-
spinner.WithSuffix(" Saving layer definitions\n"),
122-
)
123-
s.Start()
124-
125-
location, err := layersBackend.Location(ctx)
126-
if err != nil {
127-
return errors.Wrap(err, "fail to get layers backend location")
128-
}
129-
130-
err = layersBackend.UpdateLayers(ctx, layers)
78+
statesBackend, err := cfg.GetStateBackend(ctx)
13179
if err != nil {
132-
return errors.Wrap(err, "fail to update layers")
80+
return errors.Wrap(err, "fail to get state backend")
13381
}
13482

135-
s.FinalMSG = fmt.Sprintf(
136-
"✓ %d %s saved to \"%s\"\n",
137-
len(layers),
138-
pluralize("layer", len(layers)),
139-
location,
140-
)
141-
s.Stop()
83+
configure := command.NewConfigure(layersBackend, statesBackend)
14284

143-
return nil
85+
return configure.Run(ctx, fpath)
14486
},
14587
}
146-
147-
func pluralize(s string, n int) string {
148-
if n == 1 {
149-
return s
150-
}
151-
152-
return s + "s"
153-
}

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.20
44

55
require (
66
github.com/aws/aws-sdk-go v1.44.320
7-
github.com/briandowns/spinner v1.23.0
87
github.com/carlmjohnson/versioninfo v0.22.5
98
github.com/cbroglie/mustache v1.4.0
9+
github.com/chelnak/ysmrr v0.3.0
1010
github.com/google/uuid v1.3.0
1111
github.com/hashicorp/go-hclog v1.5.0
1212
github.com/hashicorp/go-version v1.6.0
@@ -18,30 +18,30 @@ require (
1818
github.com/pkg/errors v0.9.1
1919
github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69
2020
github.com/spf13/cobra v1.7.0
21-
github.com/stretchr/testify v1.8.0
21+
github.com/stretchr/testify v1.8.4
2222
github.com/zclconf/go-cty v1.13.0
23+
go.uber.org/multierr v1.11.0
2324
gopkg.in/yaml.v3 v3.0.1
2425
)
2526

2627
require (
2728
github.com/agext/levenshtein v1.2.2 // indirect
2829
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
2930
github.com/davecgh/go-spew v1.1.1 // indirect
30-
github.com/fatih/color v1.13.0 // indirect
31+
github.com/fatih/color v1.15.0 // indirect
3132
github.com/google/go-cmp v0.5.9 // indirect
3233
github.com/hashicorp/errwrap v1.0.0 // indirect
3334
github.com/hashicorp/go-multierror v1.1.1 // indirect
3435
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3536
github.com/jmespath/go-jmespath v0.4.0 // indirect
3637
github.com/kylelemons/godebug v1.1.0 // indirect
37-
github.com/mattn/go-colorable v0.1.12 // indirect
38-
github.com/mattn/go-isatty v0.0.14 // indirect
38+
github.com/mattn/go-colorable v0.1.13 // indirect
39+
github.com/mattn/go-isatty v0.0.19 // indirect
3940
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
4041
github.com/pmezard/go-difflib v1.0.0 // indirect
4142
github.com/spf13/pflag v1.0.5 // indirect
42-
github.com/stretchr/objx v0.4.0 // indirect
43+
github.com/stretchr/objx v0.5.0 // indirect
4344
golang.org/x/mod v0.7.0 // indirect
44-
golang.org/x/sys v0.4.0 // indirect
45-
golang.org/x/term v0.4.0 // indirect
45+
golang.org/x/sys v0.6.0 // indirect
4646
golang.org/x/text v0.6.0 // indirect
4747
)

go.sum

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY
2020
github.com/aws/aws-sdk-go v1.44.320 h1:o2cno15HVUYj+IAgZHJ5No6ifAxwa2HcluzahMEPfOw=
2121
github.com/aws/aws-sdk-go v1.44.320/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
2222
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
23-
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
24-
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
2523
github.com/carlmjohnson/versioninfo v0.22.5 h1:O00sjOLUAFxYQjlN/bzYTuZiS0y6fWDQjMRvwtKgwwc=
2624
github.com/carlmjohnson/versioninfo v0.22.5/go.mod h1:QT9mph3wcVfISUKd0i9sZfVrPviHuSF+cUtLjm2WSf8=
2725
github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU=
2826
github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM=
27+
github.com/chelnak/ysmrr v0.3.0 h1:eBm6PvNnjAV920MOEwCzCG3gLn+EFGUf4Go+t+T2/Ps=
28+
github.com/chelnak/ysmrr v0.3.0/go.mod h1:HedVxtqeGSPnSS7qDRtq4vPVGoz8DXcCr9jvjF263rQ=
2929
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
3030
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3131
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
@@ -35,8 +35,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
3535
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
3636
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
3737
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
38-
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
3938
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
39+
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
40+
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
4041
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
4142
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
4243
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
@@ -115,12 +116,15 @@ github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaK
115116
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
116117
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
117118
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
118-
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
119119
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
120+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
121+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
120122
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
121123
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
122-
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
123124
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
125+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
126+
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
127+
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
124128
github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4=
125129
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
126130
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
@@ -154,8 +158,9 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
154158
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
155159
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
156160
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
157-
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
158161
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
162+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
163+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
159164
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
160165
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
161166
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -164,8 +169,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
164169
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
165170
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
166171
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
167-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
168172
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
173+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
174+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
169175
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
170176
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
171177
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
@@ -178,6 +184,8 @@ github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uU
178184
github.com/zclconf/go-cty v1.13.0 h1:It5dfKTTZHe9aeppbNOda3mN7Ag7sg6QkBNm6TkyFa0=
179185
github.com/zclconf/go-cty v1.13.0/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
180186
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
187+
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
188+
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
181189
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
182190
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
183191
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -222,13 +230,14 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
222230
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
223231
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
224232
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
233+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
225234
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
226-
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
227235
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
236+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
237+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
228238
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
229239
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
230240
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
231-
golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg=
232241
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
233242
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
234243
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

0 commit comments

Comments
 (0)