Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

#745 environment variables to be used instead of 'region' property for aws-ecr registry #841

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion builtin/aws/ecr/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"os"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -45,6 +47,22 @@ func (r *Registry) Push(
ui terminal.UI,
src *component.Source,
) (*docker.Image, error) {

// If there is no region setup. Try and load it from environment variables.
if r.config.Region == "" {
r.config.Region = os.Getenv("AWS_REGION")

if r.config.Region == "" {
r.config.Region = os.Getenv("AWS_REGION_DEFAULT")
}
}

if r.config.Region == "" {
return nil, status.Error(
codes.FailedPrecondition,
"Please set your aws region in the deployment config, or set the environment variable 'AWS_REGION' or 'AWS_DEFAULT_REGION'")
}

sg := ui.StepGroup()
defer sg.Wait()

Expand Down Expand Up @@ -218,7 +236,7 @@ func (r *Registry) Push(
// Config is the configuration structure for the registry.
type Config struct {
// AWS Region to access ECR in
Region string `hcl:"region,attr"`
Region string `hcl:"region,optional"`

// Repository to store the image into
Repository string `hcl:"repository,optional"`
Expand Down Expand Up @@ -251,6 +269,9 @@ registry {
doc.SetField(
"region",
"the AWS region the ECR repository is in",
docs.Summary("if not set uses the environment variable AWS_REGION or AWS_REGION_DEFAULT"),
docs.EnvVar("AWS_REGION"),
docs.EnvVar("AWS_REGION_DEFAULT"),
)

doc.SetField(
Expand Down