@@ -63,66 +63,94 @@ func GetCredentialsFromProvider(runner tflint.Runner) (map[string]Credentials, e
6363 opts := & tflint.EvaluateExprOption {ModuleCtx : tflint .RootModuleCtxType }
6464
6565 if attr , exists := provider .Body .Attributes ["access_key" ]; exists {
66- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .AccessKey , opts ), func () error { return nil }); err != nil {
66+ if err := runner .EvaluateExpr (attr .Expr , func (accessKey string ) error {
67+ creds .AccessKey = accessKey
68+ return nil
69+ }, opts ); err != nil {
6770 return nil , err
6871 }
6972 }
7073
7174 if attr , exists := provider .Body .Attributes ["secret_key" ]; exists {
72- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .SecretKey , opts ), func () error { return nil }); err != nil {
75+ if err := runner .EvaluateExpr (attr .Expr , func (secretKey string ) error {
76+ creds .SecretKey = secretKey
77+ return nil
78+ }, opts ); err != nil {
7379 return nil , err
7480 }
7581 }
7682
7783 if attr , exists := provider .Body .Attributes ["profile" ]; exists {
78- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .Profile , opts ), func () error { return nil }); err != nil {
84+ if err := runner .EvaluateExpr (attr .Expr , func (profile string ) error {
85+ creds .Profile = profile
86+ return nil
87+ }, opts ); err != nil {
7988 return nil , err
8089 }
8190 }
8291
8392 if attr , exists := provider .Body .Attributes ["shared_credentials_file" ]; exists {
84- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .CredsFile , opts ), func () error { return nil }); err != nil {
93+ if err := runner .EvaluateExpr (attr .Expr , func (credsFile string ) error {
94+ creds .CredsFile = credsFile
95+ return nil
96+ }, opts ); err != nil {
8597 return nil , err
8698 }
8799 }
88100
89101 if attr , exists := provider .Body .Attributes ["region" ]; exists {
90- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .Region , opts ), func () error { return nil }); err != nil {
102+ if err := runner .EvaluateExpr (attr .Expr , func (region string ) error {
103+ creds .Region = region
104+ return nil
105+ }, opts ); err != nil {
91106 return nil , err
92107 }
93108 }
94109
95110 for _ , assumeRole := range provider .Body .Blocks {
96111 if attr , exists := assumeRole .Body .Attributes ["role_arn" ]; exists {
97- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .AssumeRoleARN , opts ), func () error { return nil }); err != nil {
112+ if err := runner .EvaluateExpr (attr .Expr , func (roleARN string ) error {
113+ creds .AssumeRoleARN = roleARN
114+ return nil
115+ }, opts ); err != nil {
98116 return nil , err
99117 }
100118 }
101119
102120 if attr , exists := assumeRole .Body .Attributes ["session_name" ]; exists {
103- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .AssumeRoleSessionName , opts ), func () error { return nil }); err != nil {
121+ if err := runner .EvaluateExpr (attr .Expr , func (sessionName string ) error {
122+ creds .AssumeRoleSessionName = sessionName
123+ return nil
124+ }, opts ); err != nil {
104125 return nil , err
105126 }
106127 }
107128
108129 if attr , exists := assumeRole .Body .Attributes ["external_id" ]; exists {
109- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .AssumeRoleExternalID , opts ), func () error { return nil }); err != nil {
130+ if err := runner .EvaluateExpr (attr .Expr , func (id string ) error {
131+ creds .AssumeRoleExternalID = id
132+ return nil
133+ }, opts ); err != nil {
110134 return nil , err
111135 }
112136 }
113137
114138 if attr , exists := assumeRole .Body .Attributes ["policy" ]; exists {
115- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & creds .AssumeRolePolicy , opts ), func () error { return nil }); err != nil {
139+ if err := runner .EvaluateExpr (attr .Expr , func (policy string ) error {
140+ creds .AssumeRolePolicy = policy
141+ return nil
142+ }, opts ); err != nil {
116143 return nil , err
117144 }
118145 }
119146 }
120147 if attr , exists := provider .Body .Attributes ["alias" ]; exists {
121- var alas string
122- if err := runner .EnsureNoError (runner .EvaluateExpr (attr .Expr , & alas , opts ), func () error { return nil }); err != nil {
148+ if err := runner .EvaluateExpr (attr .Expr , func (alias string ) error {
149+ m [alias ] = creds
150+ return nil
151+ }, opts ); err != nil {
123152 return nil , err
124153 }
125- m [alas ] = creds
126154 } else {
127155 m ["aws" ] = creds
128156 }
0 commit comments