Merge pull request #10305 from Direnol/yandex/fix-verify-service-account-id-in-export

added check of service account id in export
This commit is contained in:
Megan Marsh 2020-11-30 09:39:33 -08:00 committed by GitHub
commit f40eab4733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -25,6 +25,7 @@
### BUG FIXES
* builder/amazon: Fix single `tag` interpolation to allow for templating engine
usage. [GH-10224]
* post-processort/yandex-export: added check of service account id
## 1.6.5 (October 30, 2020)

View File

@ -21,6 +21,8 @@ import (
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
"github.com/hashicorp/packer/post-processor/artifice"
"github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1"
ycsdk "github.com/yandex-cloud/go-sdk"
)
const defaultStorageEndpoint = "storage.yandexcloud.net"
@ -196,6 +198,11 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
return nil, false, false, err
}
ui.Say(fmt.Sprintf("Validating service_account_id: '%s'...", yandexConfig.ServiceAccountID))
if err := validateServiceAccount(ctx, driver.SDK(), yandexConfig.ServiceAccountID); err != nil {
return nil, false, false, err
}
// Set up the state.
state := new(multistep.BasicStateBag)
state.Put("config", &yandexConfig)
@ -259,3 +266,10 @@ func formUrls(paths []string) []string {
}
return result
}
func validateServiceAccount(ctx context.Context, ycsdk *ycsdk.SDK, serviceAccountID string) error {
_, err := ycsdk.IAM().ServiceAccount().Get(ctx, &iam.GetServiceAccountRequest{
ServiceAccountId: serviceAccountID,
})
return err
}