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
This commit is contained in:
Andrew Pryde 2017-09-29 10:51:31 +01:00
parent 3998a07086
commit f426ba4660
4 changed files with 20 additions and 3 deletions

View File

@ -182,7 +182,7 @@ func BaseTestConfig() (*ini.File, *os.File, error) {
// Build ini // Build ini
cfg := ini.Empty() cfg := ini.Empty()
section, _ := cfg.NewSection("DEFAULT") 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("tenancy", "ocid1.tenancy.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
section.NewKey("user", "ocid1.user.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") section.NewKey("fingerprint", "3c:b6:44:d7:49:1a:ac:bf:de:7d:76:22:a7:f5:df:55")

View File

@ -81,7 +81,7 @@ func TestNewConfigDefaultsPopulated(t *testing.T) {
t.Fatal("Expected ADMIN config to exist in map") 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) t.Errorf("Expected 'us-phoenix-1', got '%s'", adminConfig.Region)
} }
} }

View File

@ -101,7 +101,10 @@ func NewConfig(raws ...interface{}) (*Config, error) {
if c.Region != "" { if c.Region != "" {
accessCfg.Region = 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" accessCfg.Region = "us-phoenix-1"
} }

View File

@ -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 // Test the correct errors are produced when required template keys are
// omitted. // omitted.
requiredKeys := []string{"availability_domain", "base_image_ocid", "shape", "subnet_ocid"} requiredKeys := []string{"availability_domain", "base_image_ocid", "shape", "subnet_ocid"}