From f426ba46607ab0f75989f863f331537113ed7796 Mon Sep 17 00:00:00 2001 From: Andrew Pryde Date: Fri, 29 Sep 2017 10:51:31 +0100 Subject: [PATCH] Do not override region in OCI builder Only default the OCI builder region to us-phoenix-1 when no value is present in the packer template and the OCI config file. Fixes: #5401 --- builder/oracle/oci/client/config.go | 2 +- builder/oracle/oci/client/config_test.go | 2 +- builder/oracle/oci/config.go | 5 ++++- builder/oracle/oci/config_test.go | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/builder/oracle/oci/client/config.go b/builder/oracle/oci/client/config.go index 580cd9f77..4df6b6a01 100644 --- a/builder/oracle/oci/client/config.go +++ b/builder/oracle/oci/client/config.go @@ -182,7 +182,7 @@ func BaseTestConfig() (*ini.File, *os.File, error) { // Build ini cfg := ini.Empty() section, _ := cfg.NewSection("DEFAULT") - section.NewKey("region", "us-phoenix-1") + section.NewKey("region", "us-ashburn-1") section.NewKey("tenancy", "ocid1.tenancy.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") section.NewKey("user", "ocid1.user.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") section.NewKey("fingerprint", "3c:b6:44:d7:49:1a:ac:bf:de:7d:76:22:a7:f5:df:55") diff --git a/builder/oracle/oci/client/config_test.go b/builder/oracle/oci/client/config_test.go index 08f0b806d..221e725c3 100644 --- a/builder/oracle/oci/client/config_test.go +++ b/builder/oracle/oci/client/config_test.go @@ -81,7 +81,7 @@ func TestNewConfigDefaultsPopulated(t *testing.T) { t.Fatal("Expected ADMIN config to exist in map") } - if adminConfig.Region != "us-phoenix-1" { + if adminConfig.Region != "us-ashburn-1" { t.Errorf("Expected 'us-phoenix-1', got '%s'", adminConfig.Region) } } diff --git a/builder/oracle/oci/config.go b/builder/oracle/oci/config.go index 883c61cb5..36f8bb8e9 100644 --- a/builder/oracle/oci/config.go +++ b/builder/oracle/oci/config.go @@ -101,7 +101,10 @@ func NewConfig(raws ...interface{}) (*Config, error) { if c.Region != "" { accessCfg.Region = c.Region - } else { + } + + // Default if the template nor the API config contains a region. + if accessCfg.Region == "" { accessCfg.Region = "us-phoenix-1" } diff --git a/builder/oracle/oci/config_test.go b/builder/oracle/oci/config_test.go index bc6039a55..9a6bd6486 100644 --- a/builder/oracle/oci/config_test.go +++ b/builder/oracle/oci/config_test.go @@ -122,6 +122,20 @@ func TestConfig(t *testing.T) { }) + t.Run("RegionNotDefaultedToPHXWhenSetInOCISettings", func(t *testing.T) { + raw := testConfig(cfgFile) + c, errs := NewConfig(raw) + if errs != nil { + t.Fatalf("err: %+v", errs) + } + + expected := "us-ashburn-1" + if c.AccessCfg.Region != expected { + t.Errorf("Expected region: %s, got %s.", expected, c.AccessCfg.Region) + } + + }) + // Test the correct errors are produced when required template keys are // omitted. requiredKeys := []string{"availability_domain", "base_image_ocid", "shape", "subnet_ocid"}