This repository has been archived by the owner on Jan 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
581 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
data "megaport_location" "foo" { | ||
name_regex = "{{ .locationA }}" | ||
} | ||
|
||
resource "megaport_port" "foo" { | ||
name = "terraform_acctest_a_{{ .uid }}" | ||
location_id = data.megaport_location.foo.id | ||
speed = 1000 | ||
term = 1 | ||
} | ||
|
||
data "megaport_location" "bar" { | ||
name_regex = "{{ .locationB }}" | ||
} | ||
|
||
resource "megaport_port" "bar" { | ||
name = "terraform_acctest_b_{{ .uid }}" | ||
location_id = data.megaport_location.bar.id | ||
speed = 1000 | ||
term = 1 | ||
} | ||
|
||
resource "megaport_private_vxc" "foobar" { | ||
name = "terraform_acctest_{{ .uid }}" | ||
rate_limit = 100 | ||
|
||
a_end { | ||
product_uid = megaport_port.foo.id | ||
} | ||
|
||
b_end { | ||
product_uid = megaport_port.bar.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
data "megaport_location" "foo" { | ||
name_regex = "{{ .locationA }}" | ||
} | ||
|
||
resource "megaport_port" "foo" { | ||
name = "terraform_acctest_a_{{ .uid }}" | ||
location_id = data.megaport_location.foo.id | ||
speed = 1000 | ||
term = 1 | ||
} | ||
|
||
data "megaport_location" "bar" { | ||
name_regex = "{{ .locationB }}" | ||
} | ||
|
||
resource "megaport_port" "bar" { | ||
name = "terraform_acctest_b_{{ .uid }}" | ||
location_id = data.megaport_location.bar.id | ||
speed = 1000 | ||
term = 1 | ||
} | ||
|
||
resource "megaport_private_vxc" "foobar" { | ||
name = "terraform_acctest_{{ .uid }}" | ||
rate_limit = 200 | ||
invoice_reference = "{{ .uid }}" | ||
|
||
a_end { | ||
product_uid = megaport_port.foo.id | ||
vlan = {{ .vlanA }} | ||
} | ||
|
||
b_end { | ||
product_uid = megaport_port.bar.id | ||
vlan = {{ .vlanB }} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package megaport | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
var ( | ||
testAccConfigTemplates = &template.Template{} | ||
) | ||
|
||
func mergeMaps(a, b map[string]interface{}) map[string]interface{} { | ||
r := make(map[string]interface{}, len(a)) | ||
for k, v := range a { | ||
r[k] = v | ||
} | ||
for k, v := range b { | ||
r[k] = v | ||
} | ||
return r | ||
} | ||
|
||
func testAccNewConfig(name string) (*template.Template, error) { | ||
config := "" | ||
if err := filepath.Walk(filepath.Join("../examples/", name), func(path string, f os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if f.IsDir() { | ||
return nil | ||
} | ||
r, err := filepath.Match("*.tf", f.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
if r { | ||
c, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
config = config + string(c) | ||
} | ||
return nil | ||
}); err != nil { | ||
return nil, err | ||
} | ||
t, err := testAccConfigTemplates.New(name).Parse(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return t, nil | ||
} | ||
|
||
type testAccConfig struct { | ||
Config string | ||
Name string | ||
Step int | ||
} | ||
|
||
func (c testAccConfig) log() { | ||
l := strings.Split(c.Config, "\n") | ||
for i := range l { | ||
l[i] = " " + l[i] | ||
} | ||
fmt.Printf("+++ CONFIG %q (step %d):\n%s\n", c.Name, c.Step, strings.Join(l, "\n")) | ||
} | ||
|
||
func newTestAccConfig(name string, values map[string]interface{}, step int) (*testAccConfig, error) { | ||
var ( | ||
t *template.Template | ||
err error | ||
cfg = &strings.Builder{} | ||
) | ||
t = testAccConfigTemplates.Lookup(name) | ||
if t == nil { | ||
t, err = testAccNewConfig(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
if err := t.Execute(cfg, values); err != nil { | ||
return nil, err | ||
} | ||
return &testAccConfig{Config: cfg.String(), Name: name, Step: step}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.