@@ -2,14 +2,17 @@ package deploy
22
33import (
44 "bytes"
5+ "context"
56 "encoding/json"
67 "fmt"
78 "github.com/hashicorp/hcl/v2"
89 "github.com/multycloud/multy/api/converter"
910 "github.com/multycloud/multy/api/errors"
1011 "github.com/multycloud/multy/api/proto/common"
1112 "github.com/multycloud/multy/api/proto/config"
13+ "github.com/multycloud/multy/api/proto/creds"
1214 "github.com/multycloud/multy/api/proto/resources"
15+ "github.com/multycloud/multy/api/util"
1316 "github.com/multycloud/multy/decoder"
1417 "github.com/multycloud/multy/encoder"
1518 common_resources "github.com/multycloud/multy/resources"
@@ -31,7 +34,7 @@ const (
3134 tfState = "terraform.tfstate"
3235)
3336
34- func Translate (c * config.Config , prev * config.Resource , curr * config.Resource ) (string , error ) {
37+ func Translate (credentials * creds. CloudCredentials , c * config.Config , prev * config.Resource , curr * config.Resource ) (string , error ) {
3538 // TODO: get rid of this translation layer and instead use protos directly
3639 translated := map [string ]common_resources.CloudSpecificResource {}
3740 for _ , r := range c .Resources {
@@ -147,7 +150,16 @@ func Translate(c *config.Config, prev *config.Resource, curr *config.Resource) (
147150 Providers : provider ,
148151 }
149152
150- hclOutput , errs , err := encoder .Encode (& decodedResources )
153+ for _ , r := range translated {
154+ if string (r .Cloud ) == "aws" && credentials .AwsCreds == nil {
155+ return "" , fmt .Errorf ("aws credentials are required but not set" )
156+ }
157+ if string (r .Cloud ) == "azure" && credentials .AzureCreds == nil {
158+ return "" , fmt .Errorf ("azure credentials are required but not set" )
159+ }
160+ }
161+
162+ hclOutput , errs , err := encoder .Encode (& decodedResources , credentials )
151163 if len (errs ) > 0 {
152164 return hclOutput , errors .ValidationErrors (errs )
153165 }
@@ -158,9 +170,13 @@ func Translate(c *config.Config, prev *config.Resource, curr *config.Resource) (
158170 return hclOutput , nil
159171}
160172
161- func Deploy (c * config.Config , prev * config.Resource , curr * config.Resource ) (* output.TfState , error ) {
173+ func Deploy (ctx context. Context , c * config.Config , prev * config.Resource , curr * config.Resource ) (* output.TfState , error ) {
162174
163- hclOutput , err := Translate (c , prev , curr )
175+ credentials , err := util .ExtractCloudCredentials (ctx )
176+ if err != nil {
177+ return nil , err
178+ }
179+ hclOutput , err := Translate (credentials , c , prev , curr )
164180 if err != nil {
165181 return nil , err
166182 }
0 commit comments