-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional options to control storage endpoints on import #84
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ package yandeximport | |
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/hcl/v2/hcldec" | ||
"github.com/hashicorp/packer-plugin-sdk/common" | ||
|
@@ -17,9 +19,15 @@ import ( | |
"github.com/hashicorp/packer-plugin-sdk/template/interpolate" | ||
"github.com/hashicorp/packer-plugin-yandex/builder/yandex" | ||
yandexexport "github.com/hashicorp/packer-plugin-yandex/post-processor/yandex-export" | ||
"github.com/yandex-cloud/go-genproto/yandex/cloud/endpoint" | ||
"github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1/awscompatibility" | ||
) | ||
|
||
const ( | ||
defaultStorageEndpoint = "storage.yandexcloud.net" | ||
defaultStorageRegion = "ru-central1" | ||
) | ||
|
||
type Config struct { | ||
common.PackerConfig `mapstructure:",squash"` | ||
yandex.AccessConfig `mapstructure:",squash"` | ||
|
@@ -42,6 +50,14 @@ type Config struct { | |
// leave it in the bucket, `false` to remove it. Default is `false`. | ||
SkipClean bool `mapstructure:"skip_clean" required:"false"` | ||
|
||
// StorageEndpoint custom Yandex Object Storage endpoint to upload image, Default `storage.yandexcloud.net`. | ||
StorageEndpoint string `mapstructure:"storage_endpoint" required:"false"` | ||
// StorageEndpointAutoresolve auto resolve storage endpoint via YC Public API ListEndpoints call. Option has | ||
// precedence over 'storage_endpoint' option. | ||
StorageEndpointAutoresolve bool `mapstructure:"storage_endpoint_autoresolve" required:"false"` | ||
// StorageRegion custom Yandex Object region. Default `ru-central1` | ||
StorageRegion string `mapstructure:"storage_region" required:"false"` | ||
|
||
ctx interpolate.Context | ||
} | ||
|
||
|
@@ -124,7 +140,33 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa | |
return nil, false, false, err | ||
} | ||
|
||
storageClient, err := newYCStorageClient("", respWithKey.GetAccessKey().GetKeyId(), respWithKey.GetSecret()) | ||
if p.config.StorageEndpoint == "" { | ||
p.config.StorageEndpoint = defaultStorageEndpoint | ||
} | ||
|
||
if p.config.StorageRegion == "" { | ||
p.config.StorageRegion = defaultStorageRegion | ||
} | ||
|
||
if p.config.StorageEndpointAutoresolve { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably also check during |
||
ui.Say("Resolving storage endpoint...") | ||
response, err := client.SDK().ApiEndpoint().ApiEndpoint().Get(ctx, &endpoint.GetApiEndpointRequest{ | ||
ApiEndpointId: "storage", | ||
}) | ||
|
||
if err != nil { | ||
return nil, false, false, err | ||
} | ||
// The API request returns a string potentially containing colon followed by a port number. | ||
// This causes confusion later at Compute API call, which does not understand URI with port specification. | ||
// While clearly a bug on Compute side, this is the only workaround we have to be able to operate if | ||
// the url is resolved automatically. | ||
p.config.StorageEndpoint, _, _ = strings.Cut(response.Address, ":") | ||
} | ||
|
||
log.Printf("[DEBUG] Using storage endpoint: '%s'", p.config.StorageEndpoint) | ||
|
||
storageClient, err := newYCStorageClient(p.config.StorageEndpoint, respWithKey.GetAccessKey().GetKeyId(), respWithKey.GetSecret()) | ||
if err != nil { | ||
return nil, false, false, fmt.Errorf("error create object storage client: %s", err) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we reject using both at the same time through a check in
Configure
(which I think would make sense), this comment should be amended to state that this and thestorage_endpoint
options are mutually exclusive.