From 6fa074d0cf5d8a233951e40b7ad0ac9dba68ac86 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Thu, 21 Feb 2019 23:42:59 +0100 Subject: [PATCH 1/8] Fix file permissions Signed-off-by: Stephen Hoekstra --- cosmic/resource_cosmic_loadbalancer_rule.go | 0 cosmic/resource_cosmic_loadbalancer_rule_test.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 cosmic/resource_cosmic_loadbalancer_rule.go mode change 100755 => 100644 cosmic/resource_cosmic_loadbalancer_rule_test.go diff --git a/cosmic/resource_cosmic_loadbalancer_rule.go b/cosmic/resource_cosmic_loadbalancer_rule.go old mode 100755 new mode 100644 diff --git a/cosmic/resource_cosmic_loadbalancer_rule_test.go b/cosmic/resource_cosmic_loadbalancer_rule_test.go old mode 100755 new mode 100644 From 7dc71d909f26049dcc4f7da305eb90720854a734 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Sat, 2 Feb 2019 17:41:06 +0100 Subject: [PATCH 2/8] Add GNUmakefile and support scripts Signed-off-by: Stephen Hoekstra --- GNUmakefile | 60 +++++++++++++++++++++++++++++++++++++++++++ scripts/errcheck.sh | 24 +++++++++++++++++ scripts/gofmtcheck.sh | 13 ++++++++++ 3 files changed, 97 insertions(+) create mode 100644 GNUmakefile create mode 100755 scripts/errcheck.sh create mode 100755 scripts/gofmtcheck.sh diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..a4226f0 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,60 @@ +TEST?=$$(go list ./... | grep -v 'vendor') +GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor) +WEBSITE_REPO=github.com/hashicorp/terraform-website +PKG_NAME=cosmic + +default: build + +build: fmtcheck + go install + +test: fmtcheck + go test -i $(TEST) || exit 1 + echo $(TEST) | \ + xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 + +testacc: fmtcheck + TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 30m + +vet: + @echo "go vet ." + @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ + echo ""; \ + echo "Vet found suspicious constructs. Please check the reported constructs"; \ + echo "and fix them if necessary before submitting the code for review."; \ + exit 1; \ + fi + +fmt: + gofmt -w $(GOFMT_FILES) + +fmtcheck: + @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" + +errcheck: + @sh -c "'$(CURDIR)/scripts/errcheck.sh'" + +test-compile: + @if [ "$(TEST)" = "./..." ]; then \ + echo "ERROR: Set TEST to a specific package. For example,"; \ + echo " make test-compile TEST=./$(PKG_NAME)"; \ + exit 1; \ + fi + go test -c $(TEST) $(TESTARGS) + +website: +ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) + echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..." + git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO) +endif + @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) + +website-test: +ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) + echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..." + git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO) +endif + @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) + +.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test + diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh new file mode 100755 index 0000000..15464f5 --- /dev/null +++ b/scripts/errcheck.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Check gofmt +echo "==> Checking for unchecked errors..." + +if ! which errcheck > /dev/null; then + echo "==> Installing errcheck..." + go get -u github.com/kisielk/errcheck +fi + +err_files=$(errcheck -ignoretests \ + -ignore 'github.com/hashicorp/terraform/helper/schema:Set' \ + -ignore 'bytes:.*' \ + -ignore 'io:Close|Write' \ + $(go list ./...| grep -v /vendor/)) + +if [[ -n ${err_files} ]]; then + echo 'Unchecked errors found in the following places:' + echo "${err_files}" + echo "Please handle returned errors. You can check directly with \`make errcheck\`" + exit 1 +fi + +exit 0 diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh new file mode 100755 index 0000000..1c05581 --- /dev/null +++ b/scripts/gofmtcheck.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# Check gofmt +echo "==> Checking that code complies with gofmt requirements..." +gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`) +if [[ -n ${gofmt_files} ]]; then + echo 'gofmt needs running on the following files:' + echo "${gofmt_files}" + echo "You can use the command: \`make fmt\` to reformat code." + exit 1 +fi + +exit 0 From ca57aa4b1c1aca7c752ca2fcd78d2e5e31686880 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 18 Feb 2019 23:35:42 +0100 Subject: [PATCH 3/8] Remove empty main_test.go Signed-off-by: Stephen Hoekstra --- main_test.go | 1 - 1 file changed, 1 deletion(-) delete mode 100644 main_test.go diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 06ab7d0..0000000 --- a/main_test.go +++ /dev/null @@ -1 +0,0 @@ -package main From 74c918dab4b45fbd93138cbebd5f5275aa340da5 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Tue, 19 Feb 2019 21:51:12 +0100 Subject: [PATCH 4/8] Remove cosmic_egress_firewall and cosmic_firewall These two resources are no longer supported by the Cosmic API and will be removed in a future release of Cosmic, going removing them from this provider now. Signed-off-by: Stephen Hoekstra --- CHANGELOG.md | 1 + cosmic/provider.go | 2 - cosmic/resource_cosmic_egress_firewall.go | 545 ----------------- .../resource_cosmic_egress_firewall_test.go | 203 ------- cosmic/resource_cosmic_firewall.go | 546 ------------------ cosmic/resource_cosmic_firewall_test.go | 213 ------- 6 files changed, 1 insertion(+), 1509 deletions(-) delete mode 100644 cosmic/resource_cosmic_egress_firewall.go delete mode 100644 cosmic/resource_cosmic_egress_firewall_test.go delete mode 100644 cosmic/resource_cosmic_firewall.go delete mode 100644 cosmic/resource_cosmic_firewall_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 127f128..a1df9c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Add option to configure provider using `COSMIC_CONFIG` and `COSMIC_PROFILE` environment variables - Changing `cosmic_network`'s `ip_exclusion_list` option no longer recreates the resource - Changing `cosmic_vpc`'s `vpc_offering` option no longer recreates the resource +- Removed `cosmic_egress_firewall` and `cosmic_firewall` resources; no longer implemented by the Cosmic API ## 0.1.0 (2019-01-27) diff --git a/cosmic/provider.go b/cosmic/provider.go index ff50e9d..7f3c443 100644 --- a/cosmic/provider.go +++ b/cosmic/provider.go @@ -63,8 +63,6 @@ func Provider() terraform.ResourceProvider { ResourcesMap: map[string]*schema.Resource{ "cosmic_affinity_group": resourceCosmicAffinityGroup(), "cosmic_disk": resourceCosmicDisk(), - "cosmic_egress_firewall": resourceCosmicEgressFirewall(), - "cosmic_firewall": resourceCosmicFirewall(), "cosmic_instance": resourceCosmicInstance(), "cosmic_ipaddress": resourceCosmicIPAddress(), "cosmic_loadbalancer_rule": resourceCosmicLoadBalancerRule(), diff --git a/cosmic/resource_cosmic_egress_firewall.go b/cosmic/resource_cosmic_egress_firewall.go deleted file mode 100644 index df2ca5d..0000000 --- a/cosmic/resource_cosmic_egress_firewall.go +++ /dev/null @@ -1,545 +0,0 @@ -package cosmic - -import ( - "fmt" - "strconv" - "strings" - "sync" - "time" - - "github.com/MissionCriticalCloud/go-cosmic/cosmic" - "github.com/hashicorp/go-multierror" - "github.com/hashicorp/terraform/helper/schema" -) - -func resourceCosmicEgressFirewall() *schema.Resource { - return &schema.Resource{ - Create: resourceCosmicEgressFirewallCreate, - Read: resourceCosmicEgressFirewallRead, - Update: resourceCosmicEgressFirewallUpdate, - Delete: resourceCosmicEgressFirewallDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "network_id": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "managed": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "rule": &schema.Schema{ - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "cidr_list": &schema.Schema{ - Type: schema.TypeSet, - Required: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "protocol": &schema.Schema{ - Type: schema.TypeString, - Required: true, - }, - - "icmp_type": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - - "icmp_code": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - - "ports": &schema.Schema{ - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "uuids": &schema.Schema{ - Type: schema.TypeMap, - Computed: true, - }, - }, - }, - }, - - "parallelism": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 2, - }, - }, - } -} - -func resourceCosmicEgressFirewallCreate(d *schema.ResourceData, meta interface{}) error { - // Make sure all required parameters are there - if err := verifyEgressFirewallParams(d); err != nil { - return err - } - - // We need to set this upfront in order to be able to save a partial state - d.SetId(d.Get("network_id").(string)) - - // Create all rules that are configured - if nrs := d.Get("rule").(*schema.Set); nrs.Len() > 0 { - // Create an empty schema.Set to hold all rules - rules := resourceCosmicEgressFirewall().Schema["rule"].ZeroValue().(*schema.Set) - - err := createEgressFirewallRules(d, meta, rules, nrs) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - - return resourceCosmicEgressFirewallRead(d, meta) -} - -func createEgressFirewallRules(d *schema.ResourceData, meta interface{}, rules *schema.Set, nrs *schema.Set) error { - var errs *multierror.Error - - var wg sync.WaitGroup - wg.Add(nrs.Len()) - - sem := make(chan struct{}, d.Get("parallelism").(int)) - for _, rule := range nrs.List() { - // Put in a tiny sleep here to avoid DoS'ing the API - time.Sleep(500 * time.Millisecond) - - go func(rule map[string]interface{}) { - defer wg.Done() - sem <- struct{}{} - - // Create a single rule - err := createEgressFirewallRule(d, meta, rule) - - // If we have at least one UUID, we need to save the rule - if len(rule["uuids"].(map[string]interface{})) > 0 { - rules.Add(rule) - } - - if err != nil { - errs = multierror.Append(errs, err) - } - - <-sem - }(rule.(map[string]interface{})) - } - - wg.Wait() - - return errs.ErrorOrNil() -} -func createEgressFirewallRule(d *schema.ResourceData, meta interface{}, rule map[string]interface{}) error { - cs := meta.(*cosmic.CosmicClient) - uuids := rule["uuids"].(map[string]interface{}) - - // Make sure all required rule parameters are there - if err := verifyEgressFirewallRuleParams(d, rule); err != nil { - return err - } - - // Create a new parameter struct - p := cs.Firewall.NewCreateEgressFirewallRuleParams(d.Id(), rule["protocol"].(string)) - - // Set the CIDR list - p.SetCidrlist(createCidrList(rule["cidr_list"].(*schema.Set))) - - // If the protocol is ICMP set the needed ICMP parameters - if rule["protocol"].(string) == "icmp" { - p.SetIcmptype(rule["icmp_type"].(int)) - p.SetIcmpcode(rule["icmp_code"].(int)) - - r, err := cs.Firewall.CreateEgressFirewallRule(p) - if err != nil { - return err - } - uuids["icmp"] = r.Id - rule["uuids"] = uuids - } - - // If protocol is not ICMP, loop through all ports - if rule["protocol"].(string) != "icmp" { - if ps := rule["ports"].(*schema.Set); ps.Len() > 0 { - - // Create an empty schema.Set to hold all processed ports - ports := &schema.Set{F: schema.HashString} - - for _, port := range ps.List() { - if _, ok := uuids[port.(string)]; ok { - ports.Add(port) - rule["ports"] = ports - continue - } - - m := splitPorts.FindStringSubmatch(port.(string)) - - startPort, err := strconv.Atoi(m[1]) - if err != nil { - return err - } - - endPort := startPort - if m[2] != "" { - endPort, err = strconv.Atoi(m[2]) - if err != nil { - return err - } - } - - p.SetStartport(startPort) - p.SetEndport(endPort) - - r, err := cs.Firewall.CreateEgressFirewallRule(p) - if err != nil { - return err - } - - ports.Add(port) - rule["ports"] = ports - - uuids[port.(string)] = r.Id - rule["uuids"] = uuids - } - } - } - - return nil -} - -func resourceCosmicEgressFirewallRead(d *schema.ResourceData, meta interface{}) error { - cs := meta.(*cosmic.CosmicClient) - - // Get all the rules from the running environment - p := cs.Firewall.NewListEgressFirewallRulesParams() - p.SetNetworkid(d.Id()) - p.SetListall(true) - - l, err := cs.Firewall.ListEgressFirewallRules(p) - if err != nil { - return err - } - - // Make a map of all the rules so we can easily find a rule - ruleMap := make(map[string]*cosmic.EgressFirewallRule, l.Count) - for _, r := range l.EgressFirewallRules { - ruleMap[r.Id] = r - } - - // Create an empty schema.Set to hold all rules - rules := resourceCosmicEgressFirewall().Schema["rule"].ZeroValue().(*schema.Set) - - // Read all rules that are configured - if rs := d.Get("rule").(*schema.Set); rs.Len() > 0 { - for _, rule := range rs.List() { - rule := rule.(map[string]interface{}) - uuids := rule["uuids"].(map[string]interface{}) - - if rule["protocol"].(string) == "icmp" { - id, ok := uuids["icmp"] - if !ok { - continue - } - - // Get the rule - r, ok := ruleMap[id.(string)] - if !ok { - delete(uuids, "icmp") - continue - } - - // Delete the known rule so only unknown rules remain in the ruleMap - delete(ruleMap, id.(string)) - - // Create a set with all CIDR's - cidrs := &schema.Set{F: schema.HashString} - for _, cidr := range strings.Split(r.Cidrlist, ",") { - cidrs.Add(cidr) - } - - // Update the values - rule["protocol"] = r.Protocol - rule["icmp_type"] = r.Icmptype - rule["icmp_code"] = r.Icmpcode - rule["cidr_list"] = cidrs - rules.Add(rule) - } - - // If protocol is not ICMP, loop through all ports - if rule["protocol"].(string) != "icmp" { - if ps := rule["ports"].(*schema.Set); ps.Len() > 0 { - - // Create an empty schema.Set to hold all ports - ports := &schema.Set{F: schema.HashString} - - // Loop through all ports and retrieve their info - for _, port := range ps.List() { - id, ok := uuids[port.(string)] - if !ok { - continue - } - - // Get the rule - r, ok := ruleMap[id.(string)] - if !ok { - delete(uuids, port.(string)) - continue - } - - // Delete the known rule so only unknown rules remain in the ruleMap - delete(ruleMap, id.(string)) - - // Create a set with all CIDR's - cidrs := &schema.Set{F: schema.HashString} - for _, cidr := range strings.Split(r.Cidrlist, ",") { - cidrs.Add(cidr) - } - - // Update the values - rule["protocol"] = r.Protocol - rule["cidr_list"] = cidrs - ports.Add(port) - } - - // If there is at least one port found, add this rule to the rules set - if ports.Len() > 0 { - rule["ports"] = ports - rules.Add(rule) - } - } - } - } - } - - // If this is a managed firewall, add all unknown rules into a single dummy rule - managed := d.Get("managed").(bool) - if managed && len(ruleMap) > 0 { - for uuid := range ruleMap { - // We need to create and add a dummy value to a schema.Set as the - // cidr_list is a required field and thus needs a value - cidrs := &schema.Set{F: schema.HashString} - cidrs.Add(uuid) - - // Make a dummy rule to hold the unknown UUID - rule := map[string]interface{}{ - "cidr_list": uuid, - "protocol": uuid, - "uuids": map[string]interface{}{uuid: uuid}, - } - - // Add the dummy rule to the rules set - rules.Add(rule) - } - } - - if rules.Len() > 0 { - d.Set("rule", rules) - } else if !managed { - d.SetId("") - } - - return nil -} - -func resourceCosmicEgressFirewallUpdate(d *schema.ResourceData, meta interface{}) error { - // Make sure all required parameters are there - if err := verifyEgressFirewallParams(d); err != nil { - return err - } - - // Check if the rule set as a whole has changed - if d.HasChange("rule") { - o, n := d.GetChange("rule") - ors := o.(*schema.Set).Difference(n.(*schema.Set)) - nrs := n.(*schema.Set).Difference(o.(*schema.Set)) - - // We need to start with a rule set containing all the rules we - // already have and want to keep. Any rules that are not deleted - // correctly and any newly created rules, will be added to this - // set to make sure we end up in a consistent state - rules := o.(*schema.Set).Intersection(n.(*schema.Set)) - - // First loop through all the old rules and delete them - if ors.Len() > 0 { - err := deleteEgressFirewallRules(d, meta, rules, ors) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - - // Then loop through all the new rules and create them - if nrs.Len() > 0 { - err := createEgressFirewallRules(d, meta, rules, nrs) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - } - - return resourceCosmicEgressFirewallRead(d, meta) -} - -func resourceCosmicEgressFirewallDelete(d *schema.ResourceData, meta interface{}) error { - // Create an empty rule set to hold all rules that where - // not deleted correctly - rules := resourceCosmicEgressFirewall().Schema["rule"].ZeroValue().(*schema.Set) - - // Delete all rules - if ors := d.Get("rule").(*schema.Set); ors.Len() > 0 { - err := deleteEgressFirewallRules(d, meta, rules, ors) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - - return nil -} - -func deleteEgressFirewallRules(d *schema.ResourceData, meta interface{}, rules *schema.Set, ors *schema.Set) error { - var errs *multierror.Error - - var wg sync.WaitGroup - wg.Add(ors.Len()) - - sem := make(chan struct{}, d.Get("parallelism").(int)) - for _, rule := range ors.List() { - // Put a sleep here to avoid DoS'ing the API - time.Sleep(500 * time.Millisecond) - - go func(rule map[string]interface{}) { - defer wg.Done() - sem <- struct{}{} - - // Delete a single rule - err := deleteEgressFirewallRule(d, meta, rule) - - // If we have at least one UUID, we need to save the rule - if len(rule["uuids"].(map[string]interface{})) > 0 { - rules.Add(rule) - } - - if err != nil { - errs = multierror.Append(errs, err) - } - - <-sem - }(rule.(map[string]interface{})) - } - - wg.Wait() - - return errs.ErrorOrNil() -} - -func deleteEgressFirewallRule(d *schema.ResourceData, meta interface{}, rule map[string]interface{}) error { - cs := meta.(*cosmic.CosmicClient) - uuids := rule["uuids"].(map[string]interface{}) - - for k, id := range uuids { - // We don't care about the count here, so just continue - if k == "%" { - continue - } - - // Create the parameter struct - p := cs.Firewall.NewDeleteEgressFirewallRuleParams(id.(string)) - - // Delete the rule - if _, err := cs.Firewall.DeleteEgressFirewallRule(p); err != nil { - - // This is a very poor way to be told the ID does no longer exist :( - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id.(string))) { - delete(uuids, k) - continue - } - - return err - } - - // Delete the UUID of this rule - delete(uuids, k) - rule["uuids"] = uuids - } - - return nil -} - -func verifyEgressFirewallParams(d *schema.ResourceData) error { - managed := d.Get("managed").(bool) - _, rules := d.GetOk("rule") - - if !rules && !managed { - return fmt.Errorf( - "You must supply at least one 'rule' when not using the 'managed' firewall feature") - } - - return nil -} - -func verifyEgressFirewallRuleParams(d *schema.ResourceData, rule map[string]interface{}) error { - protocol := rule["protocol"].(string) - if protocol != "tcp" && protocol != "udp" && protocol != "icmp" { - return fmt.Errorf( - "%q is not a valid protocol. Valid options are 'tcp', 'udp' and 'icmp'", protocol) - } - - if protocol == "icmp" { - if _, ok := rule["icmp_type"]; !ok { - return fmt.Errorf( - "Parameter icmp_type is a required parameter when using protocol 'icmp'") - } - if _, ok := rule["icmp_code"]; !ok { - return fmt.Errorf( - "Parameter icmp_code is a required parameter when using protocol 'icmp'") - } - } else { - if ports, ok := rule["ports"].(*schema.Set); ok { - for _, port := range ports.List() { - m := splitPorts.FindStringSubmatch(port.(string)) - if m == nil { - return fmt.Errorf( - "%q is not a valid port value. Valid options are '80' or '80-90'", port.(string)) - } - } - } else { - return fmt.Errorf( - "Parameter ports is a required parameter when *not* using protocol 'icmp'") - } - } - - return nil -} diff --git a/cosmic/resource_cosmic_egress_firewall_test.go b/cosmic/resource_cosmic_egress_firewall_test.go deleted file mode 100644 index 9860605..0000000 --- a/cosmic/resource_cosmic_egress_firewall_test.go +++ /dev/null @@ -1,203 +0,0 @@ -package cosmic - -import ( - "fmt" - "strings" - "testing" - - "github.com/MissionCriticalCloud/go-cosmic/cosmic" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestAccCosmicEgressFirewall_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicEgressFirewallDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicEgressFirewall_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicEgressFirewallRulesExist("cosmic_egress_firewall.foo"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.#", "1"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", - "rule.813975931.cidr_list.1700444180", - "10.10.10.10/32"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.813975931.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.813975931.ports.32925333", "8080"), - ), - }, - }, - }) -} - -func TestAccCosmicEgressFirewall_update(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicEgressFirewallDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicEgressFirewall_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicEgressFirewallRulesExist("cosmic_egress_firewall.foo"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.#", "1"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", - "rule.813975931.cidr_list.1700444180", - "10.10.10.10/32"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.813975931.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.813975931.ports.32925333", "8080"), - ), - }, - - resource.TestStep{ - Config: testAccCosmicEgressFirewall_update, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicEgressFirewallRulesExist("cosmic_egress_firewall.foo"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.#", "2"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", - "rule.233813027.cidr_list.3722895217", - "10.10.10.11/32"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", - "rule.3600316628.cidr_list.1700444180", - "10.10.10.10/32"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.233813027.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.3600316628.ports.32925333", "8080"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", - "rule.3600316628.cidr_list.3722895217", - "10.10.10.11/32"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.3600316628.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_egress_firewall.foo", "rule.233813027.ports.1889509032", "80"), - ), - }, - }, - }) -} - -func testAccCheckCosmicEgressFirewallRulesExist(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No firewall ID is set") - } - - for k, id := range rs.Primary.Attributes { - if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.%") { - continue - } - - cs := testAccProvider.Meta().(*cosmic.CosmicClient) - _, count, err := cs.Firewall.GetEgressFirewallRuleByID(id) - - if err != nil { - return err - } - - if count == 0 { - return fmt.Errorf("Firewall rule for %s not found", k) - } - } - - return nil - } -} - -func testAccCheckCosmicEgressFirewallDestroy(s *terraform.State) error { - cs := testAccProvider.Meta().(*cosmic.CosmicClient) - - for _, rs := range s.RootModule().Resources { - if rs.Type != "cosmic_egress_firewall" { - continue - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No instance ID is set") - } - - for k, id := range rs.Primary.Attributes { - if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.%") { - continue - } - - _, _, err := cs.Firewall.GetEgressFirewallRuleByID(id) - if err == nil { - return fmt.Errorf("Egress rule %s still exists", rs.Primary.ID) - } - } - } - - return nil -} - -var testAccCosmicEgressFirewall_basic = fmt.Sprintf(` -resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "10.10.10.0/24" - network_offering = "%s" - zone = "%s" - tags = { - terraform-tag = "true" - } -} - -resource "cosmic_egress_firewall" "foo" { - network_id = "${cosmic_network.foo.id}" - - rule { - cidr_list = ["10.10.10.10/32"] - protocol = "tcp" - ports = ["8080"] - } -}`, - COSMIC_NETWORK_2_OFFERING, - COSMIC_ZONE) - -var testAccCosmicEgressFirewall_update = fmt.Sprintf(` -resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "10.10.10.0/24" - network_offering = "%s" - zone = "%s" - tags = { - terraform-tag = "true" - } -} - -resource "cosmic_egress_firewall" "foo" { - network_id = "${cosmic_network.foo.id}" - - rule { - cidr_list = ["10.10.10.10/32", "10.10.10.11/32"] - protocol = "tcp" - ports = ["8080"] - } - - rule { - cidr_list = ["10.10.10.11/32"] - protocol = "tcp" - ports = ["80", "1000-2000"] - } -}`, - COSMIC_NETWORK_2_OFFERING, - COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_firewall.go b/cosmic/resource_cosmic_firewall.go deleted file mode 100644 index 5797485..0000000 --- a/cosmic/resource_cosmic_firewall.go +++ /dev/null @@ -1,546 +0,0 @@ -package cosmic - -import ( - "fmt" - "strconv" - "strings" - "sync" - "time" - - "github.com/MissionCriticalCloud/go-cosmic/cosmic" - "github.com/hashicorp/go-multierror" - "github.com/hashicorp/terraform/helper/schema" -) - -func resourceCosmicFirewall() *schema.Resource { - return &schema.Resource{ - Create: resourceCosmicFirewallCreate, - Read: resourceCosmicFirewallRead, - Update: resourceCosmicFirewallUpdate, - Delete: resourceCosmicFirewallDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "ip_address_id": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "managed": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "rule": &schema.Schema{ - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "cidr_list": &schema.Schema{ - Type: schema.TypeSet, - Required: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "protocol": &schema.Schema{ - Type: schema.TypeString, - Required: true, - }, - - "icmp_type": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - - "icmp_code": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - - "ports": &schema.Schema{ - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "uuids": &schema.Schema{ - Type: schema.TypeMap, - Computed: true, - }, - }, - }, - }, - - "parallelism": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 2, - }, - }, - } -} - -func resourceCosmicFirewallCreate(d *schema.ResourceData, meta interface{}) error { - // Make sure all required parameters are there - if err := verifyFirewallParams(d); err != nil { - return err - } - - // We need to set this upfront in order to be able to save a partial state - d.SetId(d.Get("ip_address_id").(string)) - - // Create all rules that are configured - if nrs := d.Get("rule").(*schema.Set); nrs.Len() > 0 { - // Create an empty schema.Set to hold all rules - rules := resourceCosmicFirewall().Schema["rule"].ZeroValue().(*schema.Set) - - err := createFirewallRules(d, meta, rules, nrs) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - - return resourceCosmicFirewallRead(d, meta) -} -func createFirewallRules(d *schema.ResourceData, meta interface{}, rules *schema.Set, nrs *schema.Set) error { - var errs *multierror.Error - - var wg sync.WaitGroup - wg.Add(nrs.Len()) - - sem := make(chan struct{}, d.Get("parallelism").(int)) - for _, rule := range nrs.List() { - // Put in a tiny sleep here to avoid DoS'ing the API - time.Sleep(500 * time.Millisecond) - - go func(rule map[string]interface{}) { - defer wg.Done() - sem <- struct{}{} - - // Create a single rule - err := createFirewallRule(d, meta, rule) - - // If we have at least one UUID, we need to save the rule - if len(rule["uuids"].(map[string]interface{})) > 0 { - rules.Add(rule) - } - - if err != nil { - errs = multierror.Append(errs, err) - } - - <-sem - }(rule.(map[string]interface{})) - } - - wg.Wait() - - return errs.ErrorOrNil() -} - -func createFirewallRule(d *schema.ResourceData, meta interface{}, rule map[string]interface{}) error { - cs := meta.(*cosmic.CosmicClient) - uuids := rule["uuids"].(map[string]interface{}) - - // Make sure all required rule parameters are there - if err := verifyFirewallRuleParams(d, rule); err != nil { - return err - } - - // Create a new parameter struct - p := cs.Firewall.NewCreateFirewallRuleParams(d.Id(), rule["protocol"].(string)) - - // Set the CIDR list - p.SetCidrlist(createCidrList(rule["cidr_list"].(*schema.Set))) - - // If the protocol is ICMP set the needed ICMP parameters - if rule["protocol"].(string) == "icmp" { - p.SetIcmptype(rule["icmp_type"].(int)) - p.SetIcmpcode(rule["icmp_code"].(int)) - - r, err := cs.Firewall.CreateFirewallRule(p) - if err != nil { - return err - } - - uuids["icmp"] = r.Id - rule["uuids"] = uuids - } - - // If protocol is not ICMP, loop through all ports - if rule["protocol"].(string) != "icmp" { - if ps := rule["ports"].(*schema.Set); ps.Len() > 0 { - - // Create an empty schema.Set to hold all processed ports - ports := &schema.Set{F: schema.HashString} - - for _, port := range ps.List() { - if _, ok := uuids[port.(string)]; ok { - ports.Add(port) - rule["ports"] = ports - continue - } - - m := splitPorts.FindStringSubmatch(port.(string)) - - startPort, err := strconv.Atoi(m[1]) - if err != nil { - return err - } - - endPort := startPort - if m[2] != "" { - endPort, err = strconv.Atoi(m[2]) - if err != nil { - return err - } - } - - p.SetStartport(startPort) - p.SetEndport(endPort) - - r, err := cs.Firewall.CreateFirewallRule(p) - if err != nil { - return err - } - - ports.Add(port) - rule["ports"] = ports - - uuids[port.(string)] = r.Id - rule["uuids"] = uuids - } - } - } - - return nil -} - -func resourceCosmicFirewallRead(d *schema.ResourceData, meta interface{}) error { - cs := meta.(*cosmic.CosmicClient) - - // Get all the rules from the running environment - p := cs.Firewall.NewListFirewallRulesParams() - p.SetIpaddressid(d.Id()) - p.SetListall(true) - - l, err := cs.Firewall.ListFirewallRules(p) - if err != nil { - return err - } - - // Make a map of all the rules so we can easily find a rule - ruleMap := make(map[string]*cosmic.FirewallRule, l.Count) - for _, r := range l.FirewallRules { - ruleMap[r.Id] = r - } - - // Create an empty schema.Set to hold all rules - rules := resourceCosmicFirewall().Schema["rule"].ZeroValue().(*schema.Set) - - // Read all rules that are configured - if rs := d.Get("rule").(*schema.Set); rs.Len() > 0 { - for _, rule := range rs.List() { - rule := rule.(map[string]interface{}) - uuids := rule["uuids"].(map[string]interface{}) - - if rule["protocol"].(string) == "icmp" { - id, ok := uuids["icmp"] - if !ok { - continue - } - - // Get the rule - r, ok := ruleMap[id.(string)] - if !ok { - delete(uuids, "icmp") - continue - } - - // Delete the known rule so only unknown rules remain in the ruleMap - delete(ruleMap, id.(string)) - - // Create a set with all CIDR's - cidrs := &schema.Set{F: schema.HashString} - for _, cidr := range strings.Split(r.Cidrlist, ",") { - cidrs.Add(cidr) - } - - // Update the values - rule["protocol"] = r.Protocol - rule["icmp_type"] = r.Icmptype - rule["icmp_code"] = r.Icmpcode - rule["cidr_list"] = cidrs - rules.Add(rule) - } - - // If protocol is not ICMP, loop through all ports - if rule["protocol"].(string) != "icmp" { - if ps := rule["ports"].(*schema.Set); ps.Len() > 0 { - - // Create an empty schema.Set to hold all ports - ports := &schema.Set{F: schema.HashString} - - // Loop through all ports and retrieve their info - for _, port := range ps.List() { - id, ok := uuids[port.(string)] - if !ok { - continue - } - - // Get the rule - r, ok := ruleMap[id.(string)] - if !ok { - delete(uuids, port.(string)) - continue - } - - // Delete the known rule so only unknown rules remain in the ruleMap - delete(ruleMap, id.(string)) - - // Create a set with all CIDR's - cidrs := &schema.Set{F: schema.HashString} - for _, cidr := range strings.Split(r.Cidrlist, ",") { - cidrs.Add(cidr) - } - - // Update the values - rule["protocol"] = r.Protocol - rule["cidr_list"] = cidrs - ports.Add(port) - } - - // If there is at least one port found, add this rule to the rules set - if ports.Len() > 0 { - rule["ports"] = ports - rules.Add(rule) - } - } - } - } - } - - // If this is a managed firewall, add all unknown rules into a single dummy rule - managed := d.Get("managed").(bool) - if managed && len(ruleMap) > 0 { - for uuid := range ruleMap { - // We need to create and add a dummy value to a schema.Set as the - // cidr_list is a required field and thus needs a value - cidrs := &schema.Set{F: schema.HashString} - cidrs.Add(uuid) - - // Make a dummy rule to hold the unknown UUID - rule := map[string]interface{}{ - "cidr_list": cidrs, - "protocol": uuid, - "uuids": map[string]interface{}{uuid: uuid}, - } - - // Add the dummy rule to the rules set - rules.Add(rule) - } - } - - if rules.Len() > 0 { - d.Set("rule", rules) - } else if !managed { - d.SetId("") - } - - return nil -} - -func resourceCosmicFirewallUpdate(d *schema.ResourceData, meta interface{}) error { - // Make sure all required parameters are there - if err := verifyFirewallParams(d); err != nil { - return err - } - - // Check if the rule set as a whole has changed - if d.HasChange("rule") { - o, n := d.GetChange("rule") - ors := o.(*schema.Set).Difference(n.(*schema.Set)) - nrs := n.(*schema.Set).Difference(o.(*schema.Set)) - - // We need to start with a rule set containing all the rules we - // already have and want to keep. Any rules that are not deleted - // correctly and any newly created rules, will be added to this - // set to make sure we end up in a consistent state - rules := o.(*schema.Set).Intersection(n.(*schema.Set)) - - // First loop through all the old rules and delete them - if ors.Len() > 0 { - err := deleteFirewallRules(d, meta, rules, ors) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - - // Then loop through all the new rules and create them - if nrs.Len() > 0 { - err := createFirewallRules(d, meta, rules, nrs) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - } - - return resourceCosmicFirewallRead(d, meta) -} - -func resourceCosmicFirewallDelete(d *schema.ResourceData, meta interface{}) error { - // Create an empty rule set to hold all rules that where - // not deleted correctly - rules := resourceCosmicFirewall().Schema["rule"].ZeroValue().(*schema.Set) - - // Delete all rules - if ors := d.Get("rule").(*schema.Set); ors.Len() > 0 { - err := deleteFirewallRules(d, meta, rules, ors) - - // We need to update this first to preserve the correct state - d.Set("rule", rules) - - if err != nil { - return err - } - } - - return nil -} - -func deleteFirewallRules(d *schema.ResourceData, meta interface{}, rules *schema.Set, ors *schema.Set) error { - var errs *multierror.Error - - var wg sync.WaitGroup - wg.Add(ors.Len()) - - sem := make(chan struct{}, d.Get("parallelism").(int)) - for _, rule := range ors.List() { - // Put a sleep here to avoid DoS'ing the API - time.Sleep(500 * time.Millisecond) - - go func(rule map[string]interface{}) { - defer wg.Done() - sem <- struct{}{} - - // Delete a single rule - err := deleteFirewallRule(d, meta, rule) - - // If we have at least one UUID, we need to save the rule - if len(rule["uuids"].(map[string]interface{})) > 0 { - rules.Add(rule) - } - - if err != nil { - errs = multierror.Append(errs, err) - } - - <-sem - }(rule.(map[string]interface{})) - } - - wg.Wait() - - return errs.ErrorOrNil() -} - -func deleteFirewallRule(d *schema.ResourceData, meta interface{}, rule map[string]interface{}) error { - cs := meta.(*cosmic.CosmicClient) - uuids := rule["uuids"].(map[string]interface{}) - - for k, id := range uuids { - // We don't care about the count here, so just continue - if k == "%" { - continue - } - - // Create the parameter struct - p := cs.Firewall.NewDeleteFirewallRuleParams(id.(string)) - - // Delete the rule - if _, err := cs.Firewall.DeleteFirewallRule(p); err != nil { - - // This is a very poor way to be told the ID does no longer exist :( - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id.(string))) { - delete(uuids, k) - continue - } - - return err - } - - // Delete the UUID of this rule - delete(uuids, k) - rule["uuids"] = uuids - } - - return nil -} - -func verifyFirewallParams(d *schema.ResourceData) error { - managed := d.Get("managed").(bool) - _, rules := d.GetOk("rule") - - if !rules && !managed { - return fmt.Errorf( - "You must supply at least one 'rule' when not using the 'managed' firewall feature") - } - - return nil -} - -func verifyFirewallRuleParams(d *schema.ResourceData, rule map[string]interface{}) error { - protocol := rule["protocol"].(string) - if protocol != "tcp" && protocol != "udp" && protocol != "icmp" { - return fmt.Errorf( - "%q is not a valid protocol. Valid options are 'tcp', 'udp' and 'icmp'", protocol) - } - - if protocol == "icmp" { - if _, ok := rule["icmp_type"]; !ok { - return fmt.Errorf( - "Parameter icmp_type is a required parameter when using protocol 'icmp'") - } - if _, ok := rule["icmp_code"]; !ok { - return fmt.Errorf( - "Parameter icmp_code is a required parameter when using protocol 'icmp'") - } - } else { - if ports, ok := rule["ports"].(*schema.Set); ok { - for _, port := range ports.List() { - m := splitPorts.FindStringSubmatch(port.(string)) - if m == nil { - return fmt.Errorf( - "%q is not a valid port value. Valid options are '80' or '80-90'", port.(string)) - } - } - } else { - return fmt.Errorf( - "Parameter ports is a required parameter when *not* using protocol 'icmp'") - } - } - - return nil -} diff --git a/cosmic/resource_cosmic_firewall_test.go b/cosmic/resource_cosmic_firewall_test.go deleted file mode 100644 index de254fd..0000000 --- a/cosmic/resource_cosmic_firewall_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package cosmic - -import ( - "fmt" - "strings" - "testing" - - "github.com/MissionCriticalCloud/go-cosmic/cosmic" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestAccCosmicFirewall_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicFirewallDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicFirewall_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicFirewallRulesExist("cosmic_firewall.foo"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "ip_address_id", COSMIC_PUBLIC_IPADDRESS), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.#", "2"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.2263505090.cidr_list.3482919157", "10.0.0.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.2263505090.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.2263505090.ports.32925333", "8080"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.cidr_list.3482919157", "10.0.0.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.ports.1209010669", "1000-2000"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.ports.1889509032", "80"), - ), - }, - }, - }) -} - -func TestAccCosmicFirewall_update(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicFirewallDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicFirewall_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicFirewallRulesExist("cosmic_firewall.foo"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "ip_address_id", COSMIC_PUBLIC_IPADDRESS), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.#", "2"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.2263505090.cidr_list.3482919157", "10.0.0.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.2263505090.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.2263505090.ports.32925333", "8080"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.cidr_list.3482919157", "10.0.0.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.ports.1209010669", "1000-2000"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.ports.1889509032", "80"), - ), - }, - - resource.TestStep{ - Config: testAccCosmicFirewall_update, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicFirewallRulesExist("cosmic_firewall.foo"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "ip_address_id", COSMIC_PUBLIC_IPADDRESS), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.#", "3"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3529885171.cidr_list.80081744", "10.0.1.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3529885171.cidr_list.3482919157", "10.0.0.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3529885171.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3529885171.ports.32925333", "8080"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.cidr_list.3482919157", "10.0.0.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.ports.1209010669", "1000-2000"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.3782201428.ports.1889509032", "80"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.4160426500.cidr_list.2835005819", "172.16.100.0/24"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.4160426500.protocol", "tcp"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.4160426500.ports.1889509032", "80"), - resource.TestCheckResourceAttr( - "cosmic_firewall.foo", "rule.4160426500.ports.3638101695", "443"), - ), - }, - }, - }) -} - -func testAccCheckCosmicFirewallRulesExist(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No firewall ID is set") - } - - for k, id := range rs.Primary.Attributes { - if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.%") { - continue - } - - cs := testAccProvider.Meta().(*cosmic.CosmicClient) - _, count, err := cs.Firewall.GetFirewallRuleByID(id) - - if err != nil { - return err - } - - if count == 0 { - return fmt.Errorf("Firewall rule for %s not found", k) - } - } - - return nil - } -} - -func testAccCheckCosmicFirewallDestroy(s *terraform.State) error { - cs := testAccProvider.Meta().(*cosmic.CosmicClient) - - for _, rs := range s.RootModule().Resources { - if rs.Type != "cosmic_firewall" { - continue - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No instance ID is set") - } - - for k, id := range rs.Primary.Attributes { - if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.%") { - continue - } - - _, _, err := cs.Firewall.GetFirewallRuleByID(id) - if err == nil { - return fmt.Errorf("Firewall rule %s still exists", rs.Primary.ID) - } - } - } - - return nil -} - -var testAccCosmicFirewall_basic = fmt.Sprintf(` -resource "cosmic_firewall" "foo" { - ip_address_id = "%s" - - rule { - cidr_list = ["10.0.0.0/24"] - protocol = "tcp" - ports = ["8080"] - } - - rule { - cidr_list = ["10.0.0.0/24"] - protocol = "tcp" - ports = ["80", "1000-2000"] - } -}`, COSMIC_PUBLIC_IPADDRESS) - -var testAccCosmicFirewall_update = fmt.Sprintf(` -resource "cosmic_firewall" "foo" { - ip_address_id = "%s" - - rule { - cidr_list = ["10.0.0.0/24", "10.0.1.0/24"] - protocol = "tcp" - ports = ["8080"] - } - - rule { - cidr_list = ["10.0.0.0/24"] - protocol = "tcp" - ports = ["80", "1000-2000"] - } - - rule { - cidr_list = ["172.16.100.0/24"] - protocol = "tcp" - ports = ["80", "443"] - } -}`, COSMIC_PUBLIC_IPADDRESS) From 92c8a7a0743f0634b04ca52647bd115c1d51c56b Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Fri, 22 Feb 2019 00:18:05 +0100 Subject: [PATCH 5/8] Fix formatting in test plans Signed-off-by: Stephen Hoekstra --- cosmic/resource_cosmic_affinity_group_test.go | 4 +- cosmic/resource_cosmic_disk_test.go | 86 ++++---- cosmic/resource_cosmic_instance_test.go | 120 +++++------ cosmic/resource_cosmic_ipaddress_test.go | 10 +- .../resource_cosmic_loadbalancer_rule_test.go | 203 +++++++++--------- .../resource_cosmic_network_acl_rule_test.go | 78 +++---- cosmic/resource_cosmic_network_acl_test.go | 12 +- cosmic/resource_cosmic_network_test.go | 93 ++++---- cosmic/resource_cosmic_nic_test.go | 48 ++--- cosmic/resource_cosmic_port_forward_test.go | 52 ++--- .../resource_cosmic_private_gateway_test.go | 30 +-- ...esource_cosmic_secondary_ipaddress_test.go | 37 ++-- cosmic/resource_cosmic_ssh_keypair_test.go | 2 +- cosmic/resource_cosmic_static_nat_test.go | 27 ++- cosmic/resource_cosmic_static_route_test.go | 42 ++-- cosmic/resource_cosmic_template_test.go | 32 ++- cosmic/resource_cosmic_vpc_test.go | 10 +- cosmic/resource_cosmic_vpn_connection_test.go | 32 +-- ...source_cosmic_vpn_customer_gateway_test.go | 68 +++--- cosmic/resource_cosmic_vpn_gateway_test.go | 6 +- 20 files changed, 493 insertions(+), 499 deletions(-) diff --git a/cosmic/resource_cosmic_affinity_group_test.go b/cosmic/resource_cosmic_affinity_group_test.go index a9ecb23..960e2a1 100644 --- a/cosmic/resource_cosmic_affinity_group_test.go +++ b/cosmic/resource_cosmic_affinity_group_test.go @@ -100,6 +100,6 @@ func testAccCheckCosmicAffinityGroupDestroy(s *terraform.State) error { var testAccCosmicAffinityGroup = fmt.Sprintf(` resource "cosmic_affinity_group" "foo" { - name = "terraform-affinity-group" - type = "host anti-affinity" + name = "terraform-affinity-group" + type = "host anti-affinity" }`) diff --git a/cosmic/resource_cosmic_disk_test.go b/cosmic/resource_cosmic_disk_test.go index 43359f7..224b22a 100644 --- a/cosmic/resource_cosmic_disk_test.go +++ b/cosmic/resource_cosmic_disk_test.go @@ -162,32 +162,32 @@ func testAccCheckCosmicDiskDestroy(s *terraform.State) error { var testAccCosmicDisk_basic = fmt.Sprintf(` resource "cosmic_disk" "foo" { - name = "terraform-disk" - attach = false + name = "terraform-disk" + attach = false disk_offering = "%s" - zone = "%s" + zone = "%s" }`, COSMIC_DISK_OFFERING_1, COSMIC_ZONE) var testAccCosmicDisk_deviceID = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_disk" "foo" { - name = "terraform-disk" - attach = true - device_id = 4 - disk_offering = "%s" - virtual_machine_id = "${cosmic_instance.foobar.id}" - zone = "${cosmic_instance.foobar.zone}" + name = "terraform-disk" + attach = true + device_id = 4 + disk_offering = "%s" + virtual_machine_id = "${cosmic_instance.foo.id}" + zone = "${cosmic_instance.foo.zone}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, @@ -196,22 +196,22 @@ resource "cosmic_disk" "foo" { COSMIC_DISK_OFFERING_1) var testAccCosmicDisk_update = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_disk" "foo" { - name = "terraform-disk" - attach = true - disk_offering = "%s" - virtual_machine_id = "${cosmic_instance.foobar.id}" - zone = "${cosmic_instance.foobar.zone}" + name = "terraform-disk" + attach = true + disk_offering = "%s" + virtual_machine_id = "${cosmic_instance.foo.id}" + zone = "${cosmic_instance.foo.zone}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, @@ -220,22 +220,22 @@ resource "cosmic_disk" "foo" { COSMIC_DISK_OFFERING_1) var testAccCosmicDisk_resize = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_disk" "foo" { - name = "terraform-disk" - attach = true - disk_offering = "%s" - virtual_machine_id = "${cosmic_instance.foobar.id}" - zone = "${cosmic_instance.foobar.zone}" + name = "terraform-disk" + attach = true + disk_offering = "%s" + virtual_machine_id = "${cosmic_instance.foo.id}" + zone = "${cosmic_instance.foo.zone}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, diff --git a/cosmic/resource_cosmic_instance_test.go b/cosmic/resource_cosmic_instance_test.go index 195d0c1..2905dab 100644 --- a/cosmic/resource_cosmic_instance_test.go +++ b/cosmic/resource_cosmic_instance_test.go @@ -21,10 +21,10 @@ func TestAccCosmicInstance_basic(t *testing.T) { Config: testAccCosmicInstance_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( - "cosmic_instance.foobar", &instance), + "cosmic_instance.foo", &instance), testAccCheckCosmicInstanceAttributes(&instance), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"), + "cosmic_instance.foo", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"), ), }, }, @@ -43,10 +43,10 @@ func TestAccCosmicInstance_update(t *testing.T) { Config: testAccCosmicInstance_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( - "cosmic_instance.foobar", &instance), + "cosmic_instance.foo", &instance), testAccCheckCosmicInstanceAttributes(&instance), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"), + "cosmic_instance.foo", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"), ), }, @@ -54,14 +54,14 @@ func TestAccCosmicInstance_update(t *testing.T) { Config: testAccCosmicInstance_renameAndResize, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( - "cosmic_instance.foobar", &instance), + "cosmic_instance.foo", &instance), testAccCheckCosmicInstanceRenamedAndResized(&instance), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "name", "terraform-updated"), + "cosmic_instance.foo", "name", "terraform-updated"), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "display_name", "terraform-updated"), + "cosmic_instance.foo", "display_name", "terraform-updated"), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "service_offering", COSMIC_SERVICE_OFFERING_2), + "cosmic_instance.foo", "service_offering", COSMIC_SERVICE_OFFERING_2), ), }, }, @@ -80,9 +80,9 @@ func TestAccCosmicInstance_fixedIP(t *testing.T) { Config: testAccCosmicInstance_fixedIP, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( - "cosmic_instance.foobar", &instance), + "cosmic_instance.foo", &instance), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "ip_address", COSMIC_NETWORK_1_IPADDRESS1), + "cosmic_instance.foo", "ip_address", COSMIC_NETWORK_1_IPADDRESS_1), ), }, }, @@ -101,9 +101,9 @@ func TestAccCosmicInstance_keyPair(t *testing.T) { Config: testAccCosmicInstance_keyPair, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( - "cosmic_instance.foobar", &instance), + "cosmic_instance.foo", &instance), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "keypair", "terraform-test-keypair"), + "cosmic_instance.foo", "keypair", "terraform-test-keypair"), ), }, }, @@ -122,9 +122,9 @@ func TestAccCosmicInstance_project(t *testing.T) { Config: testAccCosmicInstance_project, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( - "cosmic_instance.foobar", &instance), + "cosmic_instance.foo", &instance), resource.TestCheckResourceAttr( - "cosmic_instance.foobar", "project", COSMIC_PROJECT_NAME), + "cosmic_instance.foo", "project", COSMIC_PROJECT_NAME), ), }, }, @@ -230,15 +230,15 @@ func testAccCheckCosmicInstanceDestroy(s *terraform.State) error { } var testAccCosmicInstance_basic = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - user_data = "foobar\nfoo\nbar" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + user_data = "foobar\nfoo\nbar" + expunge = true }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, @@ -246,15 +246,15 @@ resource "cosmic_instance" "foobar" { COSMIC_ZONE) var testAccCosmicInstance_renameAndResize = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-updated" - display_name = "terraform-updated" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - user_data = "foobar\nfoo\nbar" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-updated" + display_name = "terraform-updated" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + user_data = "foobar\nfoo\nbar" + expunge = true }`, COSMIC_SERVICE_OFFERING_2, COSMIC_NETWORK_1, @@ -262,15 +262,15 @@ resource "cosmic_instance" "foobar" { COSMIC_ZONE) var testAccCosmicInstance_fixedIP = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform-test" - service_offering= "%s" - network_id = "%s" - ip_address = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform-test" + service_offering = "%s" + network_id = "%s" + ip_address = "%s" + template = "%s" + zone = "%s" + expunge = true }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, @@ -283,16 +283,16 @@ resource "cosmic_ssh_keypair" "foo" { name = "terraform-test-keypair" } -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform-test" - service_offering= "%s" - network_id = "%s" - ip_address = "%s" - template = "%s" - zone = "%s" - keypair = "${cosmic_ssh_keypair.foo.name}" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform-test" + service_offering = "%s" + network_id = "%s" + ip_address = "%s" + template = "%s" + zone = "%s" + keypair = "${cosmic_ssh_keypair.foo.name}" + expunge = true }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, @@ -301,15 +301,15 @@ resource "cosmic_instance" "foobar" { COSMIC_ZONE) var testAccCosmicInstance_project = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - project = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + project = "%s" + zone = "%s" + expunge = true }`, COSMIC_SERVICE_OFFERING_1, COSMIC_PROJECT_NETWORK, diff --git a/cosmic/resource_cosmic_ipaddress_test.go b/cosmic/resource_cosmic_ipaddress_test.go index f06405d..4e50823 100644 --- a/cosmic/resource_cosmic_ipaddress_test.go +++ b/cosmic/resource_cosmic_ipaddress_test.go @@ -116,15 +116,15 @@ resource "cosmic_ipaddress" "foo" { }`, COSMIC_NETWORK_1) var testAccCosmicIPAddress_vpc = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_ipaddress" "foo" { - vpc_id = "${cosmic_vpc.foobar.id}" + vpc_id = "${cosmic_vpc.foo.id}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_loadbalancer_rule_test.go b/cosmic/resource_cosmic_loadbalancer_rule_test.go index a2f4a7a..3c81974 100644 --- a/cosmic/resource_cosmic_loadbalancer_rule_test.go +++ b/cosmic/resource_cosmic_loadbalancer_rule_test.go @@ -241,25 +241,24 @@ func testAccCheckCosmicLoadBalancerRuleDestroy(s *terraform.State) error { } var testAccCosmicLoadBalancerRule_basic = fmt.Sprintf(` -resource "cosmic_instance" "foobar1" { - name = "terraform-server1" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo1" { + name = "terraform-server1" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb" + name = "terraform-lb" ip_address_id = "%s" - algorithm = "roundrobin" - public_port = 80 - private_port = 80 - member_ids = ["${cosmic_instance.foobar1.id}"] -} -`, + algorithm = "roundrobin" + public_port = 80 + private_port = 80 + member_ids = ["${cosmic_instance.foo1.id}"] +}`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, COSMIC_TEMPLATE, @@ -267,25 +266,24 @@ resource "cosmic_loadbalancer_rule" "foo" { COSMIC_PUBLIC_IPADDRESS) var testAccCosmicLoadBalancerRule_update = fmt.Sprintf(` -resource "cosmic_instance" "foobar1" { - name = "terraform-server1" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo1" { + name = "terraform-server1" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb-update" + name = "terraform-lb-update" ip_address_id = "%s" - algorithm = "leastconn" - public_port = 80 - private_port = 80 - member_ids = ["${cosmic_instance.foobar1.id}"] -} -`, + algorithm = "leastconn" + public_port = 80 + private_port = 80 + member_ids = ["${cosmic_instance.foo1.id}"] +}`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, COSMIC_TEMPLATE, @@ -293,26 +291,25 @@ resource "cosmic_loadbalancer_rule" "foo" { COSMIC_PUBLIC_IPADDRESS) var testAccCosmicLoadBalancerRule_forcenew = fmt.Sprintf(` -resource "cosmic_instance" "foobar1" { - name = "terraform-server1" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo1" { + name = "terraform-server1" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb-update" + name = "terraform-lb-update" ip_address_id = "%s" - algorithm = "leastconn" - public_port = 443 - private_port = 443 - protocol = "tcp-proxy" - member_ids = ["${cosmic_instance.foobar1.id}"] -} -`, + algorithm = "leastconn" + public_port = 443 + private_port = 443 + protocol = "tcp-proxy" + member_ids = ["${cosmic_instance.foo1.id}"] +}`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, COSMIC_TEMPLATE, @@ -320,44 +317,44 @@ resource "cosmic_loadbalancer_rule" "foo" { COSMIC_PUBLIC_IPADDRESS) var testAccCosmicLoadBalancerRule_vpc = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - gateway = "%s" + name = "terraform-network" + cidr = "%s" + gateway = "%s" network_offering = "%s" - vpc_id = "${cosmic_vpc.foobar.id}" - zone = "${cosmic_vpc.foobar.zone}" + vpc_id = "${cosmic_vpc.foo.id}" + zone = "${cosmic_vpc.foo.zone}" } resource "cosmic_ipaddress" "foo" { - vpc_id = "${cosmic_vpc.foobar.id}" + vpc_id = "${cosmic_vpc.foo.id}" } -resource "cosmic_instance" "foobar1" { - name = "terraform-server1" - display_name = "terraform" - service_offering= "%s" - network_id = "${cosmic_network.foo.id}" - template = "%s" - zone = "${cosmic_network.foo.zone}" - expunge = true +resource "cosmic_instance" "foo1" { + name = "terraform-server1" + display_name = "terraform" + service_offering = "%s" + network_id = "${cosmic_network.foo.id}" + template = "%s" + zone = "${cosmic_network.foo.zone}" + expunge = true } resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb" + name = "terraform-lb" ip_address_id = "${cosmic_ipaddress.foo.id}" - algorithm = "roundrobin" - network_id = "${cosmic_network.foo.id}" - public_port = 80 - private_port = 80 - member_ids = ["${cosmic_instance.foobar1.id}"] + algorithm = "roundrobin" + network_id = "${cosmic_network.foo.id}" + public_port = 80 + private_port = 80 + member_ids = ["${cosmic_instance.foo1.id}"] }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, @@ -369,54 +366,54 @@ resource "cosmic_loadbalancer_rule" "foo" { COSMIC_TEMPLATE) var testAccCosmicLoadBalancerRule_vpc_update = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - gateway = "%s" + name = "terraform-network" + cidr = "%s" + gateway = "%s" network_offering = "%s" - vpc_id = "${cosmic_vpc.foobar.id}" - zone = "${cosmic_vpc.foobar.zone}" + vpc_id = "${cosmic_vpc.foo.id}" + zone = "${cosmic_vpc.foo.zone}" } resource "cosmic_ipaddress" "foo" { - vpc_id = "${cosmic_vpc.foobar.id}" + vpc_id = "${cosmic_vpc.foo.id}" } -resource "cosmic_instance" "foobar1" { - name = "terraform-server1" - display_name = "terraform" - service_offering= "%s" - network_id = "${cosmic_network.foo.id}" - template = "%s" - zone = "${cosmic_network.foo.zone}" - expunge = true +resource "cosmic_instance" "foo1" { + name = "terraform-server1" + display_name = "terraform" + service_offering = "%s" + network_id = "${cosmic_network.foo.id}" + template = "%s" + zone = "${cosmic_network.foo.zone}" + expunge = true } -resource "cosmic_instance" "foobar2" { - name = "terraform-server2" - display_name = "terraform" - service_offering= "%s" - network_id = "${cosmic_network.foo.id}" - template = "%s" - zone = "${cosmic_network.foo.zone}" - expunge = true +resource "cosmic_instance" "foo2" { + name = "terraform-server2" + display_name = "terraform" + service_offering = "%s" + network_id = "${cosmic_network.foo.id}" + template = "%s" + zone = "${cosmic_network.foo.zone}" + expunge = true } resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb-update" + name = "terraform-lb-update" ip_address_id = "${cosmic_ipaddress.foo.id}" - algorithm = "leastconn" - network_id = "${cosmic_network.foo.id}" - public_port = 443 - private_port = 443 - member_ids = ["${cosmic_instance.foobar1.id}", "${cosmic_instance.foobar2.id}"] + algorithm = "leastconn" + network_id = "${cosmic_network.foo.id}" + public_port = 443 + private_port = 443 + member_ids = ["${cosmic_instance.foo1.id}", "${cosmic_instance.foo2.id}"] }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_network_acl_rule_test.go b/cosmic/resource_cosmic_network_acl_rule_test.go index 79f5ad6..76cd4de 100644 --- a/cosmic/resource_cosmic_network_acl_rule_test.go +++ b/cosmic/resource_cosmic_network_acl_rule_test.go @@ -209,42 +209,42 @@ func testAccCheckCosmicNetworkACLRuleDestroy(s *terraform.State) error { } var testAccCosmicNetworkACLRule_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_network_acl" "foo" { - name = "terraform-acl" + name = "terraform-acl" description = "terraform-acl-text" - vpc_id = "${cosmic_vpc.foobar.id}" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_network_acl_rule" "foo" { acl_id = "${cosmic_network_acl.foo.id}" rule { - action = "allow" - cidr_list = ["172.18.100.0/24"] - protocol = "all" + action = "allow" + cidr_list = ["172.18.100.0/24"] + protocol = "all" traffic_type = "ingress" } rule { - action = "allow" - cidr_list = ["172.18.100.0/24"] - protocol = "icmp" - icmp_type = "-1" - icmp_code = "-1" + action = "allow" + cidr_list = ["172.18.100.0/24"] + protocol = "icmp" + icmp_type = "-1" + icmp_code = "-1" traffic_type = "ingress" } rule { - cidr_list = ["172.16.100.0/24"] - protocol = "tcp" - ports = ["80", "443"] + cidr_list = ["172.16.100.0/24"] + protocol = "tcp" + ports = ["80", "443"] traffic_type = "ingress" } }`, @@ -253,51 +253,51 @@ resource "cosmic_network_acl_rule" "foo" { COSMIC_ZONE) var testAccCosmicNetworkACLRule_update = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_network_acl" "foo" { - name = "terraform-acl" + name = "terraform-acl" description = "terraform-acl-text" - vpc_id = "${cosmic_vpc.foobar.id}" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_network_acl_rule" "foo" { acl_id = "${cosmic_network_acl.foo.id}" rule { - action = "deny" - cidr_list = ["172.18.100.0/24"] - protocol = "all" + action = "deny" + cidr_list = ["172.18.100.0/24"] + protocol = "all" traffic_type = "ingress" } rule { - action = "deny" - cidr_list = ["172.18.100.0/24", "172.18.101.0/24"] - protocol = "icmp" - icmp_type = "-1" - icmp_code = "-1" + action = "deny" + cidr_list = ["172.18.100.0/24", "172.18.101.0/24"] + protocol = "icmp" + icmp_type = "-1" + icmp_code = "-1" traffic_type = "ingress" } rule { - action = "allow" - cidr_list = ["172.18.100.0/24"] - protocol = "tcp" - ports = ["80", "443"] + action = "allow" + cidr_list = ["172.18.100.0/24"] + protocol = "tcp" + ports = ["80", "443"] traffic_type = "ingress" } rule { - action = "deny" - cidr_list = ["10.0.0.0/24"] - protocol = "tcp" - ports = ["80", "1000-2000"] + action = "deny" + cidr_list = ["10.0.0.0/24"] + protocol = "tcp" + ports = ["80", "1000-2000"] traffic_type = "egress" } }`, diff --git a/cosmic/resource_cosmic_network_acl_test.go b/cosmic/resource_cosmic_network_acl_test.go index f0a3c95..02f5385 100644 --- a/cosmic/resource_cosmic_network_acl_test.go +++ b/cosmic/resource_cosmic_network_acl_test.go @@ -94,17 +94,17 @@ func testAccCheckCosmicNetworkACLDestroy(s *terraform.State) error { } var testAccCosmicNetworkACL_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_network_acl" "foo" { - name = "terraform-acl" + name = "terraform-acl" description = "terraform-acl-text" - vpc_id = "${cosmic_vpc.foobar.id}" + vpc_id = "${cosmic_vpc.foo.id}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_network_test.go b/cosmic/resource_cosmic_network_test.go index a014318..6b7fdc1 100644 --- a/cosmic/resource_cosmic_network_test.go +++ b/cosmic/resource_cosmic_network_test.go @@ -187,33 +187,34 @@ func testAccCheckCosmicNetworkDestroy(s *terraform.State) error { var testAccCosmicNetwork_basic = fmt.Sprintf(` resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - network_offering = "%s" - zone = "%s" - tags = { - terraform-tag = "true" - } + name = "terraform-network" + cidr = "%s" + network_offering = "%s" + zone = "%s" + + tags = { + terraform-tag = "true" + } }`, COSMIC_NETWORK_2_CIDR, COSMIC_NETWORK_2_OFFERING, COSMIC_ZONE) var testAccCosmicNetwork_vpc = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - gateway = "%s" - network_offering = "%s" - vpc_id = "${cosmic_vpc.foobar.id}" - zone = "${cosmic_vpc.foobar.zone}" + name = "terraform-network" + cidr = "%s" + gateway = "%s" + network_offering = "%s" + vpc_id = "${cosmic_vpc.foo.id}" + zone = "${cosmic_vpc.foo.zone}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, @@ -223,26 +224,26 @@ resource "cosmic_network" "foo" { COSMIC_VPC_NETWORK_OFFERING) var testAccCosmicNetwork_acl = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_network_acl" "foo" { - name = "foo" - vpc_id = "${cosmic_vpc.foobar.id}" + name = "foo" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - gateway = "%s" - network_offering = "%s" - vpc_id = "${cosmic_vpc.foobar.id}" - acl_id = "${cosmic_network_acl.foo.id}" - zone = "${cosmic_vpc.foobar.zone}" + name = "terraform-network" + cidr = "%s" + gateway = "%s" + network_offering = "%s" + vpc_id = "${cosmic_vpc.foo.id}" + acl_id = "${cosmic_network_acl.foo.id}" + zone = "${cosmic_vpc.foo.zone}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, @@ -252,26 +253,26 @@ resource "cosmic_network" "foo" { COSMIC_VPC_NETWORK_OFFERING) var testAccCosmicNetwork_updateACL = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_network_acl" "bar" { - name = "bar" - vpc_id = "${cosmic_vpc.foobar.id}" + name = "bar" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - gateway = "%s" - network_offering = "%s" - vpc_id = "${cosmic_vpc.foobar.id}" - acl_id = "${cosmic_network_acl.bar.id}" - zone = "${cosmic_vpc.foobar.zone}" + name = "terraform-network" + cidr = "%s" + gateway = "%s" + network_offering = "%s" + vpc_id = "${cosmic_vpc.foo.id}" + acl_id = "${cosmic_network_acl.bar.id}" + zone = "${cosmic_vpc.foo.zone}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_nic_test.go b/cosmic/resource_cosmic_nic_test.go index 2c26917..d3de679 100644 --- a/cosmic/resource_cosmic_nic_test.go +++ b/cosmic/resource_cosmic_nic_test.go @@ -21,7 +21,7 @@ func TestAccCosmicNIC_basic(t *testing.T) { Config: testAccCosmicNIC_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNICExists( - "cosmic_instance.foobar", "cosmic_nic.foo", &nic), + "cosmic_instance.foo", "cosmic_nic.foo", &nic), testAccCheckCosmicNICAttributes(&nic), ), }, @@ -41,7 +41,7 @@ func TestAccCosmicNIC_update(t *testing.T) { Config: testAccCosmicNIC_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNICExists( - "cosmic_instance.foobar", "cosmic_nic.foo", &nic), + "cosmic_instance.foo", "cosmic_nic.foo", &nic), testAccCheckCosmicNICAttributes(&nic), ), }, @@ -50,7 +50,7 @@ func TestAccCosmicNIC_update(t *testing.T) { Config: testAccCosmicNIC_ipaddress, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNICExists( - "cosmic_instance.foobar", "cosmic_nic.foo", &nic), + "cosmic_instance.foo", "cosmic_nic.foo", &nic), testAccCheckCosmicNICIPAddress(&nic), resource.TestCheckResourceAttr( "cosmic_nic.foo", "ip_address", COSMIC_2ND_NIC_IPADDRESS), @@ -150,19 +150,19 @@ func testAccCheckCosmicNICDestroy(s *terraform.State) error { } var testAccCosmicNIC_basic = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_nic" "foo" { - network_id = "%s" - virtual_machine_id = "${cosmic_instance.foobar.id}" + network_id = "%s" + virtual_machine_id = "${cosmic_instance.foo.id}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, @@ -171,20 +171,20 @@ resource "cosmic_nic" "foo" { COSMIC_2ND_NIC_NETWORK) var testAccCosmicNIC_ipaddress = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_nic" "foo" { - network_id = "%s" - ip_address = "%s" - virtual_machine_id = "${cosmic_instance.foobar.id}" + network_id = "%s" + ip_address = "%s" + virtual_machine_id = "${cosmic_instance.foo.id}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, diff --git a/cosmic/resource_cosmic_port_forward_test.go b/cosmic/resource_cosmic_port_forward_test.go index f0315d2..80f50ef 100644 --- a/cosmic/resource_cosmic_port_forward_test.go +++ b/cosmic/resource_cosmic_port_forward_test.go @@ -121,23 +121,23 @@ func testAccCheckCosmicPortForwardDestroy(s *terraform.State) error { } var testAccCosmicPortForward_basic = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_port_forward" "foo" { ip_address_id = "%s" forward { - protocol = "tcp" - private_port = 443 - public_port = 8443 - virtual_machine_id = "${cosmic_instance.foobar.id}" + protocol = "tcp" + private_port = 443 + public_port = 8443 + virtual_machine_id = "${cosmic_instance.foo.id}" } }`, COSMIC_SERVICE_OFFERING_1, @@ -147,30 +147,30 @@ resource "cosmic_port_forward" "foo" { COSMIC_PUBLIC_IPADDRESS) var testAccCosmicPortForward_update = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_port_forward" "foo" { ip_address_id = "%s" forward { - protocol = "tcp" - private_port = 443 - public_port = 8443 - virtual_machine_id = "${cosmic_instance.foobar.id}" + protocol = "tcp" + private_port = 443 + public_port = 8443 + virtual_machine_id = "${cosmic_instance.foo.id}" } forward { - protocol = "tcp" - private_port = 80 - public_port = 8080 - virtual_machine_id = "${cosmic_instance.foobar.id}" + protocol = "tcp" + private_port = 80 + public_port = 8080 + virtual_machine_id = "${cosmic_instance.foo.id}" } }`, COSMIC_SERVICE_OFFERING_1, diff --git a/cosmic/resource_cosmic_private_gateway_test.go b/cosmic/resource_cosmic_private_gateway_test.go index a661b94..1d53deb 100644 --- a/cosmic/resource_cosmic_private_gateway_test.go +++ b/cosmic/resource_cosmic_private_gateway_test.go @@ -90,30 +90,30 @@ func testAccCheckCosmicPrivateGatewayDestroy(s *terraform.State) error { } var testAccCosmicPrivateGateway_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - network_offering = "%s" - zone = "${cosmic_vpc.foobar.zone}" + name = "terraform-network" + cidr = "%s" + network_offering = "%s" + zone = "${cosmic_vpc.foo.zone}" } resource "cosmic_network_acl" "foo" { - name = "terraform-acl" - vpc_id = "${cosmic_vpc.foobar.id}" + name = "terraform-acl" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_private_gateway" "foo" { - ip_address = "%s" - network_id = "${cosmic_network.foo.id}" - acl_id = "${cosmic_network_acl.foo.id}" - vpc_id = "${cosmic_vpc.foobar.id}" + ip_address = "%s" + network_id = "${cosmic_network.foo.id}" + acl_id = "${cosmic_network_acl.foo.id}" + vpc_id = "${cosmic_vpc.foo.id}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_secondary_ipaddress_test.go b/cosmic/resource_cosmic_secondary_ipaddress_test.go index 8ed5d4d..8093c57 100644 --- a/cosmic/resource_cosmic_secondary_ipaddress_test.go +++ b/cosmic/resource_cosmic_secondary_ipaddress_test.go @@ -200,37 +200,36 @@ func testAccCheckCosmicSecondaryIPAddressDestroy(s *terraform.State) error { } var testAccCosmicSecondaryIPAddress_basic = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_secondary_ipaddress" "foo" { - virtual_machine_id = "${cosmic_instance.foobar.id}" -} -`, + virtual_machine_id = "${cosmic_instance.foo.id}" +}`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, COSMIC_TEMPLATE, COSMIC_ZONE) var testAccCosmicSecondaryIPAddress_fixedIP = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + expunge = true } resource "cosmic_secondary_ipaddress" "foo" { - ip_address = "%s" - virtual_machine_id = "${cosmic_instance.foobar.id}" + ip_address = "%s" + virtual_machine_id = "${cosmic_instance.foo.id}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, diff --git a/cosmic/resource_cosmic_ssh_keypair_test.go b/cosmic/resource_cosmic_ssh_keypair_test.go index 16e6421..bd7fe79 100644 --- a/cosmic/resource_cosmic_ssh_keypair_test.go +++ b/cosmic/resource_cosmic_ssh_keypair_test.go @@ -164,6 +164,6 @@ resource "cosmic_ssh_keypair" "foo" { var testAccCosmicSSHKeyPair_register = fmt.Sprintf(` resource "cosmic_ssh_keypair" "foo" { - name = "terraform-test-keypair" + name = "terraform-test-keypair" public_key = "%s" }`, COSMIC_SSH_PUBLIC_KEY) diff --git a/cosmic/resource_cosmic_static_nat_test.go b/cosmic/resource_cosmic_static_nat_test.go index fd7e366..4b335c2 100644 --- a/cosmic/resource_cosmic_static_nat_test.go +++ b/cosmic/resource_cosmic_static_nat_test.go @@ -96,27 +96,26 @@ func testAccCheckCosmicStaticNATDestroy(s *terraform.State) error { } var testAccCosmicStaticNAT_basic = fmt.Sprintf(` -resource "cosmic_instance" "foobar" { - name = "terraform-test" - display_name = "terraform-test" - service_offering= "%s" - network_id = "%s" - template = "%s" - zone = "%s" - user_data = "foobar\nfoo\nbar" - expunge = true +resource "cosmic_instance" "foo" { + name = "terraform-test" + display_name = "terraform-test" + service_offering = "%s" + network_id = "%s" + template = "%s" + zone = "%s" + user_data = "foobar\nfoo\nbar" + expunge = true } resource "cosmic_ipaddress" "foo" { - network_id = "${cosmic_instance.foobar.network_id}" + network_id = "${cosmic_instance.foo.network_id}" } resource "cosmic_static_nat" "foo" { - ip_address_id = "${cosmic_ipaddress.foo.id}" - virtual_machine_id = "${cosmic_instance.foobar.id}" + ip_address_id = "${cosmic_ipaddress.foo.id}" + virtual_machine_id = "${cosmic_instance.foo.id}" }`, COSMIC_SERVICE_OFFERING_1, COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE, -) + COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_static_route_test.go b/cosmic/resource_cosmic_static_route_test.go index 3ca98e4..62f61c9 100644 --- a/cosmic/resource_cosmic_static_route_test.go +++ b/cosmic/resource_cosmic_static_route_test.go @@ -21,7 +21,7 @@ func TestAccCosmicStaticRoute_basic(t *testing.T) { Config: testAccCosmicStaticRoute_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicStaticRouteExists( - "cosmic_static_route.bar", &route), + "cosmic_static_route.foo", &route), testAccCheckCosmicStaticRouteAttributes(&route), ), }, @@ -92,37 +92,37 @@ func testAccCheckCosmicStaticRouteDestroy(s *terraform.State) error { } var testAccCosmicStaticRoute_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foobar" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - network_offering = "%s" - zone = "${cosmic_vpc.foobar.zone}" + name = "terraform-network" + cidr = "%s" + network_offering = "%s" + zone = "${cosmic_vpc.foo.zone}" } resource "cosmic_network_acl" "foo" { - name = "terraform-acl" - vpc_id = "${cosmic_vpc.foobar.id}" + name = "terraform-acl" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_private_gateway" "foo" { - ip_address = "%s" - network_id = "${cosmic_network.foo.id}" - acl_id = "${cosmic_network_acl.foo.id}" - vpc_id = "${cosmic_vpc.foobar.id}" + ip_address = "%s" + network_id = "${cosmic_network.foo.id}" + acl_id = "${cosmic_network_acl.foo.id}" + vpc_id = "${cosmic_vpc.foo.id}" } -resource "cosmic_static_route" "bar" { - depends_on = ["cosmic_private_gateway.foo"] - cidr = "%s" - nexthop = "%s" - vpc_id = "${cosmic_vpc.foobar.id}" +resource "cosmic_static_route" "foo" { + depends_on = ["cosmic_private_gateway.foo"] + cidr = "%s" + nexthop = "%s" + vpc_id = "${cosmic_vpc.foo.id}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_template_test.go b/cosmic/resource_cosmic_template_test.go index a69a86f..7b66262 100644 --- a/cosmic/resource_cosmic_template_test.go +++ b/cosmic/resource_cosmic_template_test.go @@ -160,14 +160,13 @@ func testAccCheckCosmicTemplateDestroy(s *terraform.State) error { var testAccCosmicTemplate_basic = fmt.Sprintf(` resource "cosmic_template" "foo" { - name = "terraform-test" - format = "%s" + name = "terraform-test" + format = "%s" hypervisor = "%s" - os_type = "%s" - url = "%s" - zone = "%s" -} -`, + os_type = "%s" + url = "%s" + zone = "%s" +}`, COSMIC_TEMPLATE_FORMAT, COSMIC_HYPERVISOR, COSMIC_TEMPLATE_OS_TYPE, @@ -176,17 +175,16 @@ resource "cosmic_template" "foo" { var testAccCosmicTemplate_update = fmt.Sprintf(` resource "cosmic_template" "foo" { - name = "terraform-test" - display_text = "terraform-updated" - format = "%s" - hypervisor = "%s" - os_type = "%s" - url = "%s" - zone = "%s" + name = "terraform-test" + display_text = "terraform-updated" + format = "%s" + hypervisor = "%s" + os_type = "%s" + url = "%s" + zone = "%s" is_dynamically_scalable = true - password_enabled = true -} -`, + password_enabled = true +}`, COSMIC_TEMPLATE_FORMAT, COSMIC_HYPERVISOR, COSMIC_TEMPLATE_OS_TYPE, diff --git a/cosmic/resource_cosmic_vpc_test.go b/cosmic/resource_cosmic_vpc_test.go index abadab7..afa9b22 100644 --- a/cosmic/resource_cosmic_vpc_test.go +++ b/cosmic/resource_cosmic_vpc_test.go @@ -107,12 +107,12 @@ func testAccCheckCosmicVPCDestroy(s *terraform.State) error { var testAccCosmicVPC_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - display_text = "terraform-vpc-text" - cidr = "%s" - vpc_offering = "%s" + name = "terraform-vpc" + display_text = "terraform-vpc-text" + cidr = "%s" + vpc_offering = "%s" network_domain = "terraform-domain" - zone = "%s" + zone = "%s" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_vpn_connection_test.go b/cosmic/resource_cosmic_vpn_connection_test.go index b8c7906..3a65957 100644 --- a/cosmic/resource_cosmic_vpn_connection_test.go +++ b/cosmic/resource_cosmic_vpn_connection_test.go @@ -82,17 +82,17 @@ func testAccCheckCosmicVPNConnectionDestroy(s *terraform.State) error { var testAccCosmicVPNConnection_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { - name = "terraform-vpc-foo" - cidr = "%s" + name = "terraform-vpc-foo" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_vpc" "bar" { - name = "terraform-vpc-bar" - cidr = "%s" + name = "terraform-vpc-bar" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_vpn_gateway" "foo" { @@ -104,31 +104,31 @@ resource "cosmic_vpn_gateway" "bar" { } resource "cosmic_vpn_customer_gateway" "foo" { - name = "terraform-foo" - cidr = "${cosmic_vpc.foo.cidr}" + name = "terraform-foo" + cidr = "${cosmic_vpc.foo.cidr}" esp_policy = "aes256-sha1" - gateway = "${cosmic_vpn_gateway.foo.public_ip}" + gateway = "${cosmic_vpn_gateway.foo.public_ip}" ike_policy = "aes256-sha1" - ipsec_psk = "terraform" + ipsec_psk = "terraform" } resource "cosmic_vpn_customer_gateway" "bar" { - name = "terraform-bar" - cidr = "${cosmic_vpc.bar.cidr}" + name = "terraform-bar" + cidr = "${cosmic_vpc.bar.cidr}" esp_policy = "aes256-sha1" - gateway = "${cosmic_vpn_gateway.bar.public_ip}" + gateway = "${cosmic_vpn_gateway.bar.public_ip}" ike_policy = "aes256-sha1" - ipsec_psk = "terraform" + ipsec_psk = "terraform" } resource "cosmic_vpn_connection" "foo-bar" { customer_gateway_id = "${cosmic_vpn_customer_gateway.foo.id}" - vpn_gateway_id = "${cosmic_vpn_gateway.bar.id}" + vpn_gateway_id = "${cosmic_vpn_gateway.bar.id}" } resource "cosmic_vpn_connection" "bar-foo" { customer_gateway_id = "${cosmic_vpn_customer_gateway.bar.id}" - vpn_gateway_id = "${cosmic_vpn_gateway.foo.id}" + vpn_gateway_id = "${cosmic_vpn_gateway.foo.id}" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_vpn_customer_gateway_test.go b/cosmic/resource_cosmic_vpn_customer_gateway_test.go index ed96699..326cde3 100644 --- a/cosmic/resource_cosmic_vpn_customer_gateway_test.go +++ b/cosmic/resource_cosmic_vpn_customer_gateway_test.go @@ -174,43 +174,43 @@ func testAccCheckCosmicVPNCustomerGatewayDestroy(s *terraform.State) error { var testAccCosmicVPNCustomerGateway_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { - name = "terraform-vpc-foo" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" + name = "terraform-vpc-foo" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_vpc" "bar" { - name = "terraform-vpc-bar" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" + name = "terraform-vpc-bar" + cidr = "%s" + vpc_offering = "%s" + zone = "%s" } resource "cosmic_vpn_gateway" "foo" { - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "${cosmic_vpc.foo.id}" } resource "cosmic_vpn_gateway" "bar" { - vpc_id = "${cosmic_vpc.bar.id}" + vpc_id = "${cosmic_vpc.bar.id}" } resource "cosmic_vpn_customer_gateway" "foo" { - name = "terraform-foo" - cidr = "${cosmic_vpc.foo.cidr}" - esp_policy = "aes256-sha1" - gateway = "${cosmic_vpn_gateway.foo.public_ip}" - ike_policy = "aes256-sha1" - ipsec_psk = "terraform" + name = "terraform-foo" + cidr = "${cosmic_vpc.foo.cidr}" + esp_policy = "aes256-sha1" + gateway = "${cosmic_vpn_gateway.foo.public_ip}" + ike_policy = "aes256-sha1" + ipsec_psk = "terraform" } resource "cosmic_vpn_customer_gateway" "bar" { - name = "terraform-bar" - cidr = "${cosmic_vpc.bar.cidr}" + name = "terraform-bar" + cidr = "${cosmic_vpc.bar.cidr}" esp_policy = "aes256-sha1" - gateway = "${cosmic_vpn_gateway.bar.public_ip}" + gateway = "${cosmic_vpn_gateway.bar.public_ip}" ike_policy = "aes256-sha1" - ipsec_psk = "terraform" + ipsec_psk = "terraform" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, @@ -221,17 +221,17 @@ resource "cosmic_vpn_customer_gateway" "bar" { var testAccCosmicVPNCustomerGateway_update = fmt.Sprintf(` resource "cosmic_vpc" "foo" { - name = "terraform-vpc-foo" - cidr = "%s" + name = "terraform-vpc-foo" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_vpc" "bar" { - name = "terraform-vpc-bar" - cidr = "%s" + name = "terraform-vpc-bar" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_vpn_gateway" "foo" { @@ -243,21 +243,21 @@ resource "cosmic_vpn_gateway" "bar" { } resource "cosmic_vpn_customer_gateway" "foo" { - name = "terraform-foo-bar" - cidr = "${cosmic_vpc.foo.cidr}" + name = "terraform-foo-bar" + cidr = "${cosmic_vpc.foo.cidr}" esp_policy = "3des-md5" - gateway = "${cosmic_vpn_gateway.foo.public_ip}" + gateway = "${cosmic_vpn_gateway.foo.public_ip}" ike_policy = "3des-md5" - ipsec_psk = "terraform" + ipsec_psk = "terraform" } resource "cosmic_vpn_customer_gateway" "bar" { - name = "terraform-bar-foo" - cidr = "${cosmic_vpc.bar.cidr}" + name = "terraform-bar-foo" + cidr = "${cosmic_vpc.bar.cidr}" esp_policy = "3des-md5" - gateway = "${cosmic_vpn_gateway.bar.public_ip}" + gateway = "${cosmic_vpn_gateway.bar.public_ip}" ike_policy = "3des-md5" - ipsec_psk = "terraform" + ipsec_psk = "terraform" }`, COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, diff --git a/cosmic/resource_cosmic_vpn_gateway_test.go b/cosmic/resource_cosmic_vpn_gateway_test.go index 1303f47..0c3ea96 100644 --- a/cosmic/resource_cosmic_vpn_gateway_test.go +++ b/cosmic/resource_cosmic_vpn_gateway_test.go @@ -80,11 +80,11 @@ func testAccCheckCosmicVPNGatewayDestroy(s *terraform.State) error { var testAccCosmicVPNGateway_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { - name = "terraform-vpc" + name = "terraform-vpc" display_text = "terraform-vpc-text" - cidr = "%s" + cidr = "%s" vpc_offering = "%s" - zone = "%s" + zone = "%s" } resource "cosmic_vpn_gateway" "foo" { From 57b98e37e7425b931329d572a4197388fa2cb616 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Sun, 24 Feb 2019 22:10:22 +0100 Subject: [PATCH 6/8] Update test suite * Build and tear down dependencies instead of relying on resources to exist (except VPCs, those are time consuming to build) * Update tests so they pass * Clean up testing variables; use more hard coded values and depend on less being provided by tester Signed-off-by: Stephen Hoekstra --- cosmic/provider_test.go | 155 +---------- cosmic/resource_cosmic_affinity_group_test.go | 6 +- cosmic/resource_cosmic_disk_test.go | 168 +++++++++--- cosmic/resource_cosmic_instance_test.go | 145 ++++++++--- cosmic/resource_cosmic_ipaddress_test.go | 51 +--- .../resource_cosmic_loadbalancer_rule_test.go | 246 ++---------------- .../resource_cosmic_network_acl_rule_test.go | 34 +-- cosmic/resource_cosmic_network_acl_test.go | 16 +- cosmic/resource_cosmic_network_test.go | 140 ++-------- cosmic/resource_cosmic_nic_test.go | 96 ++++--- cosmic/resource_cosmic_port_forward_test.go | 66 +++-- .../resource_cosmic_private_gateway_test.go | 29 +-- ...esource_cosmic_secondary_ipaddress_test.go | 51 ++-- cosmic/resource_cosmic_ssh_keypair_test.go | 22 +- cosmic/resource_cosmic_static_nat_test.go | 28 +- cosmic/resource_cosmic_static_route_test.go | 49 +--- cosmic/resource_cosmic_template_test.go | 42 ++- cosmic/resource_cosmic_vpc_test.go | 5 +- cosmic/resource_cosmic_vpn_connection_test.go | 16 +- ...source_cosmic_vpn_customer_gateway_test.go | 136 +--------- cosmic/resource_cosmic_vpn_gateway_test.go | 17 +- 21 files changed, 552 insertions(+), 966 deletions(-) diff --git a/cosmic/provider_test.go b/cosmic/provider_test.go index 5144089..a81b215 100644 --- a/cosmic/provider_test.go +++ b/cosmic/provider_test.go @@ -60,113 +60,38 @@ func testAccPreCheck(t *testing.T) { if v := os.Getenv("COSMIC_SECRET_KEY"); v == "" { t.Fatal("COSMIC_SECRET_KEY must be set for acceptance tests") } - if v := os.Getenv("COSMIC_2ND_NIC_IPADDRESS"); v == "" { - t.Fatal("COSMIC_2ND_NIC_IPADDRESS must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_2ND_NIC_NETWORK"); v == "" { - t.Fatal("COSMIC_2ND_NIC_NETWORK must be set for acceptance tests") - } if v := os.Getenv("COSMIC_DISK_OFFERING_1"); v == "" { t.Fatal("COSMIC_DISK_OFFERING_1 must be set for acceptance tests") } if v := os.Getenv("COSMIC_DISK_OFFERING_2"); v == "" { t.Fatal("COSMIC_DISK_OFFERING_2 must be set for acceptance tests") } - if v := os.Getenv("COSMIC_HYPERVISOR"); v == "" { - t.Fatal("COSMIC_HYPERVISOR must be set for acceptance tests") - } if v := os.Getenv("COSMIC_SERVICE_OFFERING_1"); v == "" { t.Fatal("COSMIC_SERVICE_OFFERING_1 must be set for acceptance tests") } if v := os.Getenv("COSMIC_SERVICE_OFFERING_2"); v == "" { t.Fatal("COSMIC_SERVICE_OFFERING_2 must be set for acceptance tests") } - if v := os.Getenv("COSMIC_NETWORK_1"); v == "" { - t.Fatal("COSMIC_NETWORK_1 must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_1_IPADDRESS1"); v == "" { - t.Fatal("COSMIC_NETWORK_1_IPADDRESS1 must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_1_IPADDRESS2"); v == "" { - t.Fatal("COSMIC_NETWORK_1_IPADDRESS2 must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_2"); v == "" { - t.Fatal("COSMIC_NETWORK_2 must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_2_CIDR"); v == "" { - t.Fatal("COSMIC_NETWORK_2_CIDR must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_2_GATEWAY"); v == "" { - t.Fatal("COSMIC_NETWORK_2_GATEWAY must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_2_OFFERING"); v == "" { - t.Fatal("COSMIC_NETWORK_2_OFFERING must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_NETWORK_2_IPADDRESS"); v == "" { - t.Fatal("COSMIC_NETWORK_2_IPADDRESS must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_VPC_CIDR_1"); v == "" { - t.Fatal("COSMIC_VPC_CIDR_1 must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_VPC_CIDR_2"); v == "" { - t.Fatal("COSMIC_VPC_CIDR_2 must be set for acceptance tests") + if v := os.Getenv("COSMIC_VPC_ID"); v == "" { + t.Fatal("COSMIC_VPC_ID must be set for acceptance tests") } if v := os.Getenv("COSMIC_VPC_OFFERING"); v == "" { t.Fatal("COSMIC_VPC_OFFERING must be set for acceptance tests") } - if v := os.Getenv("COSMIC_VPC_NETWORK_CIDR"); v == "" { - t.Fatal("COSMIC_VPC_NETWORK_CIDR must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_VPC_NETWORK_GATEWAY"); v == "" { - t.Fatal("COSMIC_VPC_NETWORK_GATEWAY must be set for acceptance tests") - } if v := os.Getenv("COSMIC_VPC_NETWORK_OFFERING"); v == "" { t.Fatal("COSMIC_VPC_NETWORK_OFFERING must be set for acceptance tests") } - if v := os.Getenv("COSMIC_VPC_NETWORK_IPADDRESS"); v == "" { - t.Fatal("COSMIC_VPC_NETWORK_IPADDRESS must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_PUBLIC_IPADDRESS"); v == "" { - t.Fatal("COSMIC_PUBLIC_IPADDRESS must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_SSH_PUBLIC_KEY"); v == "" { - t.Fatal("COSMIC_SSH_PUBLIC_KEY must be set for acceptance tests") - } if v := os.Getenv("COSMIC_TEMPLATE"); v == "" { t.Fatal("COSMIC_TEMPLATE must be set for acceptance tests") } - if v := os.Getenv("COSMIC_TEMPLATE_FORMAT"); v == "" { - t.Fatal("COSMIC_TEMPLATE_FORMAT must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_TEMPLATE_URL"); v == "" { - t.Fatal("COSMIC_TEMPLATE_URL must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_TEMPLATE_OS_TYPE"); v == "" { - t.Fatal("COSMIC_TEMPLATE_OS_TYPE must be set for acceptance tests") - } if v := os.Getenv("COSMIC_PROJECT_NAME"); v == "" { t.Fatal("COSMIC_PROJECT_NAME must be set for acceptance tests") } - if v := os.Getenv("COSMIC_PROJECT_NETWORK"); v == "" { - t.Fatal("COSMIC_PROJECT_NETWORK must be set for acceptance tests") - } if v := os.Getenv("COSMIC_ZONE"); v == "" { t.Fatal("COSMIC_ZONE must be set for acceptance tests") } - if v := os.Getenv("COSMIC_PRIVNW_CIDR"); v == "" { - t.Fatal("COSMIC_PRIVNW_CIDR must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_PRIVNW_OFFERING"); v == "" { - t.Fatal("COSMIC_PRIVNW_OFFERING must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_PRIVGW_IPADDRESS"); v == "" { - t.Fatal("COSMIC_PRIVGW_IPADDRESS must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_STATIC_ROUTE_CIDR"); v == "" { - t.Fatal("COSMIC_STATIC_ROUTE_CIDR must be set for acceptance tests") - } - if v := os.Getenv("COSMIC_STATIC_ROUTE_NEXTHOP"); v == "" { - t.Fatal("COSMIC_STATIC_ROUTE_NEXTHOP must be set for acceptance tests") + if v := os.Getenv("COSMIC_DEFAULT_ALLOW_ACL_ID"); v == "" { + t.Fatal("COSMIC_DEFAULT_ALLOW_ACL_ID must be set for acceptance tests") } } @@ -182,87 +107,23 @@ var COSMIC_SERVICE_OFFERING_1 = os.Getenv("COSMIC_SERVICE_OFFERING_1") // Name of a service offering that COSMIC_SERVICE_OFFERING_1 can resize to var COSMIC_SERVICE_OFFERING_2 = os.Getenv("COSMIC_SERVICE_OFFERING_2") -// Name of a network that already exists -var COSMIC_NETWORK_1 = os.Getenv("COSMIC_NETWORK_1") - -// A valid IP address in COSMIC_NETWORK_1 -var COSMIC_NETWORK_1_IPADDRESS1 = os.Getenv("COSMIC_NETWORK_1_IPADDRESS1") - -// A valid IP address in COSMIC_NETWORK_1 -var COSMIC_NETWORK_1_IPADDRESS2 = os.Getenv("COSMIC_NETWORK_1_IPADDRESS2") - -// Name for a network that will be created -var COSMIC_NETWORK_2 = os.Getenv("COSMIC_NETWORK_2") - -// Any range -var COSMIC_NETWORK_2_CIDR = os.Getenv("COSMIC_NETWORK_2_CIDR") - -// An IP address in COSMIC_NETWORK_2_CIDR to be used as the gateway -var COSMIC_NETWORK_2_GATEWAY = os.Getenv("COSMIC_NETWORK_2_GATEWAY") - -// Name of an available network offering with specifyvlan=false -var COSMIC_NETWORK_2_OFFERING = os.Getenv("COSMIC_NETWORK_2_OFFERING") - -// An IP address in COSMIC_NETWORK_2_CIDR -var COSMIC_NETWORK_2_IPADDRESS = os.Getenv("COSMIC_NETWORK_2_IPADDRESS") - -// A network that already exists and isn't COSMIC_NETWORK_1 -var COSMIC_2ND_NIC_NETWORK = os.Getenv("COSMIC_2ND_NIC_NETWORK") - -// An IP address in COSMIC_2ND_NIC_NETWORK -var COSMIC_2ND_NIC_IPADDRESS = os.Getenv("COSMIC_2ND_NIC_IPADDRESS") - -// Any range -var COSMIC_VPC_CIDR_1 = os.Getenv("COSMIC_VPC_CIDR_1") - -// Any range that doesn't overlap to COSMIC_VPC_CIDR_1, will be VPNed -var COSMIC_VPC_CIDR_2 = os.Getenv("COSMIC_VPC_CIDR_2") +// ID of an existing VPC +var COSMIC_VPC_ID = os.Getenv("COSMIC_VPC_ID") // An available VPC offering var COSMIC_VPC_OFFERING = os.Getenv("COSMIC_VPC_OFFERING") -// A sub-range of COSMIC_VPC_CIDR_1 with same starting point -var COSMIC_VPC_NETWORK_CIDR = os.Getenv("COSMIC_VPC_NETWORK_CIDR") - -// A sub-range of COSMIC_VPC_CIDR_1 with same starting point -var COSMIC_VPC_NETWORK_GATEWAY = os.Getenv("COSMIC_VPC_NETWORK_GATEWAY") - // Name of an available network offering with forvpc=true var COSMIC_VPC_NETWORK_OFFERING = os.Getenv("COSMIC_VPC_NETWORK_OFFERING") -// An IP address in the range of the COSMIC_VPC_NETWORK_CIDR -var COSMIC_VPC_NETWORK_IPADDRESS = os.Getenv("COSMIC_VPC_NETWORK_IPADDRESS") - -// Path to a public IP that exists for COSMIC_NETWORK_1 -var COSMIC_PUBLIC_IPADDRESS = os.Getenv("COSMIC_PUBLIC_IPADDRESS") - -// Path to a public key on local disk -var COSMIC_SSH_PUBLIC_KEY = os.Getenv("COSMIC_SSH_PUBLIC_KEY") - // Name of a template that exists already for building VMs var COSMIC_TEMPLATE = os.Getenv("COSMIC_TEMPLATE") -// Details of a template that will be added -var COSMIC_TEMPLATE_FORMAT = os.Getenv("COSMIC_TEMPLATE_FORMAT") -var COSMIC_HYPERVISOR = os.Getenv("COSMIC_HYPERVISOR") -var COSMIC_TEMPLATE_URL = os.Getenv("COSMIC_TEMPLATE_URL") -var COSMIC_TEMPLATE_OS_TYPE = os.Getenv("COSMIC_TEMPLATE_OS_TYPE") - // Name of a project that exists already var COSMIC_PROJECT_NAME = os.Getenv("COSMIC_PROJECT_NAME") -// Name of a network that exists already in COSMIC_PROJECT_NAME -var COSMIC_PROJECT_NETWORK = os.Getenv("COSMIC_PROJECT_NETWORK") - // Name of a zone that exists already var COSMIC_ZONE = os.Getenv("COSMIC_ZONE") -// Details of the private gateway that will be created -var COSMIC_PRIVNW_CIDR = os.Getenv("COSMIC_PRIVNW_CIDR") -var COSMIC_PRIVNW_OFFERING = os.Getenv("COSMIC_PRIVNW_OFFERING") -var COSMIC_PRIVGW_IPADDRESS = os.Getenv("COSMIC_PRIVGW_IPADDRESS") - -// Details of the static route that will be added to private gateway testing this. -// nexthop should be in COSMIC_PRIVNW_CIDR -var COSMIC_STATIC_ROUTE_CIDR = os.Getenv("COSMIC_STATIC_ROUTE_CIDR") -var COSMIC_STATIC_ROUTE_NEXTHOP = os.Getenv("COSMIC_STATIC_ROUTE_NEXTHOP") +// ID of the "default_acl" built-in ACL +var COSMIC_DEFAULT_ALLOW_ACL_ID = os.Getenv("COSMIC_DEFAULT_ALLOW_ACL_ID") diff --git a/cosmic/resource_cosmic_affinity_group_test.go b/cosmic/resource_cosmic_affinity_group_test.go index 960e2a1..d6ae20a 100644 --- a/cosmic/resource_cosmic_affinity_group_test.go +++ b/cosmic/resource_cosmic_affinity_group_test.go @@ -17,7 +17,7 @@ func TestAccCosmicAffinityGroup_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicAffinityGroupDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicAffinityGroup, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicAffinityGroupExists("cosmic_affinity_group.foo", &affinityGroup), @@ -98,8 +98,8 @@ func testAccCheckCosmicAffinityGroupDestroy(s *terraform.State) error { return nil } -var testAccCosmicAffinityGroup = fmt.Sprintf(` +const testAccCosmicAffinityGroup = ` resource "cosmic_affinity_group" "foo" { name = "terraform-affinity-group" type = "host anti-affinity" -}`) +}` diff --git a/cosmic/resource_cosmic_disk_test.go b/cosmic/resource_cosmic_disk_test.go index 224b22a..83e6007 100644 --- a/cosmic/resource_cosmic_disk_test.go +++ b/cosmic/resource_cosmic_disk_test.go @@ -17,7 +17,7 @@ func TestAccCosmicDisk_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicDiskDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicDisk_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicDiskExists( @@ -29,7 +29,7 @@ func TestAccCosmicDisk_basic(t *testing.T) { }) } -func TestAccCosmicDisk_deviceID(t *testing.T) { +func TestAccCosmicDisk_update(t *testing.T) { var disk cosmic.Volume resource.Test(t, resource.TestCase{ @@ -37,21 +37,31 @@ func TestAccCosmicDisk_deviceID(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicDiskDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicDisk_deviceID, + { + Config: testAccCosmicDisk_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicDiskExists( "cosmic_disk.foo", &disk), testAccCheckCosmicDiskAttributes(&disk), resource.TestCheckResourceAttr( - "cosmic_disk.foo", "device_id", "4"), + "cosmic_disk.foo", "size", "10"), + ), + }, + + { + Config: testAccCosmicDisk_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckCosmicDiskExists( + "cosmic_disk.foo", &disk), + resource.TestCheckResourceAttr( + "cosmic_disk.foo", "size", "20"), ), }, }, }) } -func TestAccCosmicDisk_update(t *testing.T) { +func TestAccCosmicDisk_attachBasic(t *testing.T) { var disk cosmic.Volume resource.Test(t, resource.TestCase{ @@ -59,23 +69,66 @@ func TestAccCosmicDisk_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicDiskDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicDisk_update, + { + Config: testAccCosmicDisk_attachBasic, + Check: resource.ComposeTestCheckFunc( + testAccCheckCosmicDiskExists( + "cosmic_disk.foo", &disk), + testAccCheckCosmicDiskAttributes(&disk), + ), + }, + }, + }) +} + +func TestAccCosmicDisk_attachUpdate(t *testing.T) { + var disk cosmic.Volume + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCosmicDiskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCosmicDisk_attachBasic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicDiskExists( "cosmic_disk.foo", &disk), testAccCheckCosmicDiskAttributes(&disk), + resource.TestCheckResourceAttr( + "cosmic_disk.foo", "size", "10"), ), }, - resource.TestStep{ - Config: testAccCosmicDisk_resize, + { + Config: testAccCosmicDisk_attachUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckCosmicDiskExists( + "cosmic_disk.foo", &disk), + resource.TestCheckResourceAttr( + "cosmic_disk.foo", "size", "20"), + ), + }, + }, + }) +} + +func TestAccCosmicDisk_attachDeviceID(t *testing.T) { + var disk cosmic.Volume + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCosmicDiskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCosmicDisk_attachDeviceID, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicDiskExists( "cosmic_disk.foo", &disk), - testAccCheckCosmicDiskResized(&disk), + testAccCheckCosmicDiskAttributes(&disk), resource.TestCheckResourceAttr( - "cosmic_disk.foo", "disk_offering", COSMIC_DISK_OFFERING_2), + "cosmic_disk.foo", "device_id", "4"), ), }, }, @@ -127,18 +180,6 @@ func testAccCheckCosmicDiskAttributes( } } -func testAccCheckCosmicDiskResized( - disk *cosmic.Volume) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if disk.Diskofferingname != COSMIC_DISK_OFFERING_2 { - return fmt.Errorf("Bad disk offering: %s", disk.Diskofferingname) - } - - return nil - } -} - func testAccCheckCosmicDiskDestroy(s *terraform.State) error { cs := testAccProvider.Meta().(*cosmic.CosmicClient) @@ -164,81 +205,126 @@ var testAccCosmicDisk_basic = fmt.Sprintf(` resource "cosmic_disk" "foo" { name = "terraform-disk" attach = false + size = "10" + disk_offering = "%s" + zone = "%s" +}`, + COSMIC_DISK_OFFERING_1, + COSMIC_ZONE) + +var testAccCosmicDisk_update = fmt.Sprintf(` +resource "cosmic_disk" "foo" { + name = "terraform-disk" + attach = false + size = "20" disk_offering = "%s" zone = "%s" }`, COSMIC_DISK_OFFERING_1, COSMIC_ZONE) -var testAccCosmicDisk_deviceID = fmt.Sprintf(` +var testAccCosmicDisk_attachBasic = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } resource "cosmic_disk" "foo" { name = "terraform-disk" attach = true - device_id = 4 + size = "10" disk_offering = "%s" virtual_machine_id = "${cosmic_instance.foo.id}" zone = "${cosmic_instance.foo.zone}" }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE, COSMIC_DISK_OFFERING_1) -var testAccCosmicDisk_update = fmt.Sprintf(` +var testAccCosmicDisk_attachDeviceID = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } resource "cosmic_disk" "foo" { name = "terraform-disk" attach = true + device_id = 4 + size = "10" disk_offering = "%s" virtual_machine_id = "${cosmic_instance.foo.id}" zone = "${cosmic_instance.foo.zone}" }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE, COSMIC_DISK_OFFERING_1) -var testAccCosmicDisk_resize = fmt.Sprintf(` +var testAccCosmicDisk_attachUpdate = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } resource "cosmic_disk" "foo" { name = "terraform-disk" attach = true + size = "20" disk_offering = "%s" virtual_machine_id = "${cosmic_instance.foo.id}" zone = "${cosmic_instance.foo.zone}" }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE, - COSMIC_DISK_OFFERING_2) + COSMIC_DISK_OFFERING_1) diff --git a/cosmic/resource_cosmic_instance_test.go b/cosmic/resource_cosmic_instance_test.go index 2905dab..6cfb731 100644 --- a/cosmic/resource_cosmic_instance_test.go +++ b/cosmic/resource_cosmic_instance_test.go @@ -17,7 +17,7 @@ func TestAccCosmicInstance_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicInstanceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicInstance_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( @@ -39,7 +39,7 @@ func TestAccCosmicInstance_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicInstanceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicInstance_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( @@ -50,7 +50,7 @@ func TestAccCosmicInstance_update(t *testing.T) { ), }, - resource.TestStep{ + { Config: testAccCosmicInstance_renameAndResize, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( @@ -76,13 +76,13 @@ func TestAccCosmicInstance_fixedIP(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicInstanceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicInstance_fixedIP, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( "cosmic_instance.foo", &instance), resource.TestCheckResourceAttr( - "cosmic_instance.foo", "ip_address", COSMIC_NETWORK_1_IPADDRESS_1), + "cosmic_instance.foo", "ip_address", "10.0.10.10"), ), }, }, @@ -97,7 +97,7 @@ func TestAccCosmicInstance_keyPair(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicInstanceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicInstance_keyPair, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( @@ -118,7 +118,7 @@ func TestAccCosmicInstance_project(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicInstanceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicInstance_project, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicInstanceExists( @@ -180,8 +180,14 @@ func testAccCheckCosmicInstanceAttributes( return fmt.Errorf("Bad template: %s", instance.Templatename) } - if instance.Nic[0].Networkid != COSMIC_NETWORK_1 { - return fmt.Errorf("Bad network ID: %s", instance.Nic[0].Networkid) + for _, rs := range s.RootModule().Resources { + if rs.Type != "cosmic_network" { + continue + } + + if instance.Nic[0].Networkid != rs.Primary.ID { + return fmt.Errorf("Bad network ID: %s", instance.Nic[0].Networkid) + } } return nil @@ -230,89 +236,148 @@ func testAccCheckCosmicInstanceDestroy(s *terraform.State) error { } var testAccCosmicInstance_basic = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" user_data = "foobar\nfoo\nbar" expunge = true }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, - COSMIC_ZONE) + COSMIC_TEMPLATE) var testAccCosmicInstance_renameAndResize = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-updated" display_name = "terraform-updated" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" user_data = "foobar\nfoo\nbar" expunge = true }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_2, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, - COSMIC_ZONE) + COSMIC_TEMPLATE) var testAccCosmicInstance_fixedIP = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform-test" service_offering = "%s" - network_id = "%s" - ip_address = "%s" + network_id = "${cosmic_network.foo.id}" + ip_address = "10.0.10.10" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_NETWORK_1_IPADDRESS1, - COSMIC_TEMPLATE, - COSMIC_ZONE) + COSMIC_TEMPLATE) var testAccCosmicInstance_keyPair = fmt.Sprintf(` resource "cosmic_ssh_keypair" "foo" { name = "terraform-test-keypair" } +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform-test" service_offering = "%s" - network_id = "%s" - ip_address = "%s" + network_id = "${cosmic_network.foo.id}" + ip_address = "10.0.10.10" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" keypair = "${cosmic_ssh_keypair.foo.name}" expunge = true }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_NETWORK_1_IPADDRESS1, - COSMIC_TEMPLATE, - COSMIC_ZONE) + COSMIC_TEMPLATE) var testAccCosmicInstance_project = fmt.Sprintf(` +resource "cosmic_vpc" "foo" { + name = "terraform-vpc" + display_text = "terraform-vpc-text" + cidr = "10.0.10.0/22" + vpc_offering = "%s" + network_domain = "terraform-domain" + project = "%s" + zone = "%s" +} + +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + project = "${cosmic_vpc.foo.project}" + vpc_id = "${cosmic_vpc.foo.id}" + zone = "${cosmic_vpc.foo.zone}" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - project = "%s" - zone = "%s" + project = "${cosmic_vpc.foo.project}" + zone = "${cosmic_vpc.foo.zone}" expunge = true }`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_PROJECT_NETWORK, - COSMIC_TEMPLATE, + COSMIC_VPC_OFFERING, COSMIC_PROJECT_NAME, - COSMIC_ZONE) + COSMIC_ZONE, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_SERVICE_OFFERING_1, + COSMIC_TEMPLATE) diff --git a/cosmic/resource_cosmic_ipaddress_test.go b/cosmic/resource_cosmic_ipaddress_test.go index 4e50823..5284fe8 100644 --- a/cosmic/resource_cosmic_ipaddress_test.go +++ b/cosmic/resource_cosmic_ipaddress_test.go @@ -17,7 +17,7 @@ func TestAccCosmicIPAddress_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicIPAddressDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicIPAddress_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicIPAddressExists( @@ -29,25 +29,6 @@ func TestAccCosmicIPAddress_basic(t *testing.T) { }) } -func TestAccCosmicIPAddress_vpc(t *testing.T) { - var ipaddr cosmic.PublicIpAddress - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicIPAddressDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicIPAddress_vpc, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicIPAddressExists( - "cosmic_ipaddress.foo", &ipaddr), - ), - }, - }, - }) -} - func testAccCheckCosmicIPAddressExists( n string, ipaddr *cosmic.PublicIpAddress) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -81,8 +62,14 @@ func testAccCheckCosmicIPAddressAttributes( ipaddr *cosmic.PublicIpAddress) resource.TestCheckFunc { return func(s *terraform.State) error { - if ipaddr.Associatednetworkid != COSMIC_NETWORK_1 { - return fmt.Errorf("Bad network ID: %s", ipaddr.Associatednetworkid) + for _, rs := range s.RootModule().Resources { + if rs.Type != "cosmic_vpc" { + continue + } + + if ipaddr.Vpcid != rs.Primary.ID { + return fmt.Errorf("Bad network ID: %s", ipaddr.Associatednetworkid) + } } return nil @@ -112,20 +99,8 @@ func testAccCheckCosmicIPAddressDestroy(s *terraform.State) error { var testAccCosmicIPAddress_basic = fmt.Sprintf(` resource "cosmic_ipaddress" "foo" { - network_id = "%s" -}`, COSMIC_NETWORK_1) - -var testAccCosmicIPAddress_vpc = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - -resource "cosmic_ipaddress" "foo" { - vpc_id = "${cosmic_vpc.foo.id}" + acl_id = "%s" + vpc_id = "%s" }`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE) + COSMIC_DEFAULT_ALLOW_ACL_ID, + COSMIC_VPC_ID) diff --git a/cosmic/resource_cosmic_loadbalancer_rule_test.go b/cosmic/resource_cosmic_loadbalancer_rule_test.go index 3c81974..0c8832f 100644 --- a/cosmic/resource_cosmic_loadbalancer_rule_test.go +++ b/cosmic/resource_cosmic_loadbalancer_rule_test.go @@ -16,7 +16,7 @@ func TestAccCosmicLoadBalancerRule_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicLoadBalancerRuleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicLoadBalancerRule_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", nil), @@ -42,7 +42,7 @@ func TestAccCosmicLoadBalancerRule_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicLoadBalancerRuleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicLoadBalancerRule_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", &id), @@ -57,114 +57,10 @@ func TestAccCosmicLoadBalancerRule_update(t *testing.T) { ), }, - resource.TestStep{ + { Config: testAccCosmicLoadBalancerRule_update, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", &id), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "name", "terraform-lb-update"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "algorithm", "leastconn"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "public_port", "80"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "private_port", "80"), - ), - }, - }, - }) -} - -func TestAccCosmicLoadBalancerRule_forceNew(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicLoadBalancerRuleDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicLoadBalancerRule_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", nil), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "name", "terraform-lb"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "algorithm", "roundrobin"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "public_port", "80"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "private_port", "80"), - ), - }, - - resource.TestStep{ - Config: testAccCosmicLoadBalancerRule_forcenew, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", nil), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "name", "terraform-lb-update"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "algorithm", "leastconn"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "public_port", "443"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "private_port", "443"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "protocol", "tcp-proxy"), - ), - }, - }, - }) -} - -func TestAccCosmicLoadBalancerRule_vpc(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicLoadBalancerRuleDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicLoadBalancerRule_vpc, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", nil), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "name", "terraform-lb"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "algorithm", "roundrobin"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "public_port", "80"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "private_port", "80"), - ), - }, - }, - }) -} - -func TestAccCosmicLoadBalancerRule_vpcUpdate(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicLoadBalancerRuleDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicLoadBalancerRule_vpc, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", nil), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "name", "terraform-lb"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "algorithm", "roundrobin"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "public_port", "80"), - resource.TestCheckResourceAttr( - "cosmic_loadbalancer_rule.foo", "private_port", "80"), - ), - }, - - resource.TestStep{ - Config: testAccCosmicLoadBalancerRule_vpc_update, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicLoadBalancerRuleExist("cosmic_loadbalancer_rule.foo", nil), resource.TestCheckResourceAttr( "cosmic_loadbalancer_rule.foo", "name", "terraform-lb-update"), resource.TestCheckResourceAttr( @@ -241,100 +137,18 @@ func testAccCheckCosmicLoadBalancerRuleDestroy(s *terraform.State) error { } var testAccCosmicLoadBalancerRule_basic = fmt.Sprintf(` -resource "cosmic_instance" "foo1" { - name = "terraform-server1" - display_name = "terraform" - service_offering = "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true -} - -resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb" - ip_address_id = "%s" - algorithm = "roundrobin" - public_port = 80 - private_port = 80 - member_ids = ["${cosmic_instance.foo1.id}"] -}`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, - COSMIC_ZONE, - COSMIC_PUBLIC_IPADDRESS) - -var testAccCosmicLoadBalancerRule_update = fmt.Sprintf(` -resource "cosmic_instance" "foo1" { - name = "terraform-server1" - display_name = "terraform" - service_offering = "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true -} - -resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb-update" - ip_address_id = "%s" - algorithm = "leastconn" - public_port = 80 - private_port = 80 - member_ids = ["${cosmic_instance.foo1.id}"] -}`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, - COSMIC_ZONE, - COSMIC_PUBLIC_IPADDRESS) - -var testAccCosmicLoadBalancerRule_forcenew = fmt.Sprintf(` -resource "cosmic_instance" "foo1" { - name = "terraform-server1" - display_name = "terraform" - service_offering = "%s" - network_id = "%s" - template = "%s" - zone = "%s" - expunge = true -} - -resource "cosmic_loadbalancer_rule" "foo" { - name = "terraform-lb-update" - ip_address_id = "%s" - algorithm = "leastconn" - public_port = 443 - private_port = 443 - protocol = "tcp-proxy" - member_ids = ["${cosmic_instance.foo1.id}"] -}`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, - COSMIC_ZONE, - COSMIC_PUBLIC_IPADDRESS) - -var testAccCosmicLoadBalancerRule_vpc = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network" "foo" { name = "terraform-network" - cidr = "%s" - gateway = "%s" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" network_offering = "%s" - vpc_id = "${cosmic_vpc.foo.id}" - zone = "${cosmic_vpc.foo.zone}" + vpc_id = "%s" + zone = "%s" } resource "cosmic_ipaddress" "foo" { - vpc_id = "${cosmic_vpc.foo.id}" + acl_id = "%s" + vpc_id = "${cosmic_network.foo.vpc_id}" } resource "cosmic_instance" "foo1" { @@ -356,34 +170,26 @@ resource "cosmic_loadbalancer_rule" "foo" { private_port = 80 member_ids = ["${cosmic_instance.foo1.id}"] }`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_VPC_NETWORK_CIDR, - COSMIC_VPC_NETWORK_GATEWAY, COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, + COSMIC_DEFAULT_ALLOW_ACL_ID, COSMIC_SERVICE_OFFERING_1, COSMIC_TEMPLATE) -var testAccCosmicLoadBalancerRule_vpc_update = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - +var testAccCosmicLoadBalancerRule_update = fmt.Sprintf(` resource "cosmic_network" "foo" { name = "terraform-network" - cidr = "%s" - gateway = "%s" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" network_offering = "%s" - vpc_id = "${cosmic_vpc.foo.id}" - zone = "${cosmic_vpc.foo.zone}" + vpc_id = "%s" + zone = "%s" } resource "cosmic_ipaddress" "foo" { - vpc_id = "${cosmic_vpc.foo.id}" + acl_id = "%s" + vpc_id = "${cosmic_network.foo.vpc_id}" } resource "cosmic_instance" "foo1" { @@ -399,9 +205,9 @@ resource "cosmic_instance" "foo1" { resource "cosmic_instance" "foo2" { name = "terraform-server2" display_name = "terraform" - service_offering = "%s" + service_offering = "${cosmic_instance.foo1.service_offering}" network_id = "${cosmic_network.foo.id}" - template = "%s" + template = "${cosmic_instance.foo1.template}" zone = "${cosmic_network.foo.zone}" expunge = true } @@ -415,13 +221,9 @@ resource "cosmic_loadbalancer_rule" "foo" { private_port = 443 member_ids = ["${cosmic_instance.foo1.id}", "${cosmic_instance.foo2.id}"] }`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_VPC_NETWORK_CIDR, - COSMIC_VPC_NETWORK_GATEWAY, COSMIC_VPC_NETWORK_OFFERING, - COSMIC_SERVICE_OFFERING_1, - COSMIC_TEMPLATE, + COSMIC_VPC_ID, + COSMIC_ZONE, + COSMIC_DEFAULT_ALLOW_ACL_ID, COSMIC_SERVICE_OFFERING_1, COSMIC_TEMPLATE) diff --git a/cosmic/resource_cosmic_network_acl_rule_test.go b/cosmic/resource_cosmic_network_acl_rule_test.go index 76cd4de..a61f00f 100644 --- a/cosmic/resource_cosmic_network_acl_rule_test.go +++ b/cosmic/resource_cosmic_network_acl_rule_test.go @@ -16,7 +16,7 @@ func TestAccCosmicNetworkACLRule_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNetworkACLRuleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNetworkACLRule_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkACLRulesExist("cosmic_network_acl.foo"), @@ -60,7 +60,7 @@ func TestAccCosmicNetworkACLRule_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNetworkACLRuleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNetworkACLRule_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkACLRulesExist("cosmic_network_acl.foo"), @@ -95,7 +95,7 @@ func TestAccCosmicNetworkACLRule_update(t *testing.T) { ), }, - resource.TestStep{ + { Config: testAccCosmicNetworkACLRule_update, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkACLRulesExist("cosmic_network_acl.foo"), @@ -209,17 +209,10 @@ func testAccCheckCosmicNetworkACLRuleDestroy(s *terraform.State) error { } var testAccCosmicNetworkACLRule_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network_acl" "foo" { name = "terraform-acl" description = "terraform-acl-text" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "%s" } resource "cosmic_network_acl_rule" "foo" { @@ -247,23 +240,13 @@ resource "cosmic_network_acl_rule" "foo" { ports = ["80", "443"] traffic_type = "ingress" } -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE) +}`, COSMIC_VPC_ID) var testAccCosmicNetworkACLRule_update = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network_acl" "foo" { name = "terraform-acl" description = "terraform-acl-text" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "%s" } resource "cosmic_network_acl_rule" "foo" { @@ -300,7 +283,4 @@ resource "cosmic_network_acl_rule" "foo" { ports = ["80", "1000-2000"] traffic_type = "egress" } -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE) +}`, COSMIC_VPC_ID) diff --git a/cosmic/resource_cosmic_network_acl_test.go b/cosmic/resource_cosmic_network_acl_test.go index 02f5385..405cf63 100644 --- a/cosmic/resource_cosmic_network_acl_test.go +++ b/cosmic/resource_cosmic_network_acl_test.go @@ -16,7 +16,7 @@ func TestAccCosmicNetworkACL_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNetworkACLDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNetworkACL_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkACLExists( @@ -94,18 +94,8 @@ func testAccCheckCosmicNetworkACLDestroy(s *terraform.State) error { } var testAccCosmicNetworkACL_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network_acl" "foo" { name = "terraform-acl" description = "terraform-acl-text" - vpc_id = "${cosmic_vpc.foo.id}" -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE) + vpc_id = "%s" +}`, COSMIC_VPC_ID) diff --git a/cosmic/resource_cosmic_network_test.go b/cosmic/resource_cosmic_network_test.go index 6b7fdc1..a4f1c9d 100644 --- a/cosmic/resource_cosmic_network_test.go +++ b/cosmic/resource_cosmic_network_test.go @@ -17,7 +17,7 @@ func TestAccCosmicNetwork_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNetworkDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNetwork_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkExists( @@ -30,26 +30,6 @@ func TestAccCosmicNetwork_basic(t *testing.T) { }) } -func TestAccCosmicNetwork_vpc(t *testing.T) { - var network cosmic.Network - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicNetworkDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicNetwork_vpc, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicNetworkExists( - "cosmic_network.foo", &network), - testAccCheckCosmicNetworkVPCAttributes(&network), - ), - }, - }, - }) -} - func TestAccCosmicNetwork_updateACL(t *testing.T) { var network cosmic.Network @@ -58,21 +38,21 @@ func TestAccCosmicNetwork_updateACL(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNetworkDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNetwork_acl, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkExists( "cosmic_network.foo", &network), - testAccCheckCosmicNetworkVPCAttributes(&network), + testAccCheckCosmicNetworkBasicAttributes(&network), ), }, - resource.TestStep{ + { Config: testAccCosmicNetwork_updateACL, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNetworkExists( "cosmic_network.foo", &network), - testAccCheckCosmicNetworkVPCAttributes(&network), + testAccCheckCosmicNetworkBasicAttributes(&network), ), }, }, @@ -119,11 +99,11 @@ func testAccCheckCosmicNetworkBasicAttributes(network *cosmic.Network) resource. return fmt.Errorf("Bad display name: %s", network.Displaytext) } - if network.Cidr != COSMIC_NETWORK_2_CIDR { + if network.Cidr != "10.0.10.0/24" { return fmt.Errorf("Bad CIDR: %s", network.Cidr) } - if network.Networkofferingname != COSMIC_NETWORK_2_OFFERING { + if network.Networkofferingname != COSMIC_VPC_NETWORK_OFFERING { return fmt.Errorf("Bad network offering: %s", network.Networkofferingname) } @@ -141,29 +121,6 @@ func testAccCheckNetworkTags(n *cosmic.Network, key string, value string) resour } } -func testAccCheckCosmicNetworkVPCAttributes(network *cosmic.Network) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if network.Name != "terraform-network" { - return fmt.Errorf("Bad name: %s", network.Name) - } - - if network.Displaytext != "terraform-network" { - return fmt.Errorf("Bad display name: %s", network.Displaytext) - } - - if network.Cidr != COSMIC_VPC_NETWORK_CIDR { - return fmt.Errorf("Bad CIDR: %s", network.Cidr) - } - - if network.Networkofferingname != COSMIC_VPC_NETWORK_OFFERING { - return fmt.Errorf("Bad network offering: %s", network.Networkofferingname) - } - - return nil - } -} - func testAccCheckCosmicNetworkDestroy(s *terraform.State) error { cs := testAccProvider.Meta().(*cosmic.CosmicClient) @@ -188,95 +145,54 @@ func testAccCheckCosmicNetworkDestroy(s *terraform.State) error { var testAccCosmicNetwork_basic = fmt.Sprintf(` resource "cosmic_network" "foo" { name = "terraform-network" - cidr = "%s" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" network_offering = "%s" + vpc_id = "%s" zone = "%s" tags = { terraform-tag = "true" } }`, - COSMIC_NETWORK_2_CIDR, - COSMIC_NETWORK_2_OFFERING, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, COSMIC_ZONE) -var testAccCosmicNetwork_vpc = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - -resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - gateway = "%s" - network_offering = "%s" - vpc_id = "${cosmic_vpc.foo.id}" - zone = "${cosmic_vpc.foo.zone}" -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_VPC_NETWORK_CIDR, - COSMIC_VPC_NETWORK_GATEWAY, - COSMIC_VPC_NETWORK_OFFERING) - var testAccCosmicNetwork_acl = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network_acl" "foo" { name = "foo" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "%s" } resource "cosmic_network" "foo" { name = "terraform-network" - cidr = "%s" - gateway = "%s" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" network_offering = "%s" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "${cosmic_network_acl.foo.vpc_id}" acl_id = "${cosmic_network_acl.foo.id}" - zone = "${cosmic_vpc.foo.zone}" + zone = "%s" }`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_VPC_NETWORK_CIDR, - COSMIC_VPC_NETWORK_GATEWAY, - COSMIC_VPC_NETWORK_OFFERING) + COSMIC_VPC_ID, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_ZONE) var testAccCosmicNetwork_updateACL = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network_acl" "bar" { name = "bar" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "%s" } resource "cosmic_network" "foo" { name = "terraform-network" - cidr = "%s" - gateway = "%s" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" network_offering = "%s" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "${cosmic_network_acl.bar.vpc_id}" acl_id = "${cosmic_network_acl.bar.id}" - zone = "${cosmic_vpc.foo.zone}" + zone = "%s" }`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_VPC_NETWORK_CIDR, - COSMIC_VPC_NETWORK_GATEWAY, - COSMIC_VPC_NETWORK_OFFERING) + COSMIC_VPC_ID, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_nic_test.go b/cosmic/resource_cosmic_nic_test.go index d3de679..0134d35 100644 --- a/cosmic/resource_cosmic_nic_test.go +++ b/cosmic/resource_cosmic_nic_test.go @@ -17,11 +17,11 @@ func TestAccCosmicNIC_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNICDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNIC_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNICExists( - "cosmic_instance.foo", "cosmic_nic.foo", &nic), + "cosmic_instance.foo", "cosmic_nic.bar", &nic), testAccCheckCosmicNICAttributes(&nic), ), }, @@ -37,23 +37,24 @@ func TestAccCosmicNIC_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicNICDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicNIC_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNICExists( - "cosmic_instance.foo", "cosmic_nic.foo", &nic), + "cosmic_instance.foo", "cosmic_nic.bar", &nic), testAccCheckCosmicNICAttributes(&nic), ), }, - resource.TestStep{ + { Config: testAccCosmicNIC_ipaddress, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicNICExists( - "cosmic_instance.foo", "cosmic_nic.foo", &nic), + "cosmic_instance.foo", "cosmic_nic.bar", &nic), + testAccCheckCosmicNICAttributes(&nic), testAccCheckCosmicNICIPAddress(&nic), resource.TestCheckResourceAttr( - "cosmic_nic.foo", "ip_address", COSMIC_2ND_NIC_IPADDRESS), + "cosmic_nic.bar", "ip_address", "10.0.11.10"), ), }, }, @@ -103,8 +104,8 @@ func testAccCheckCosmicNICAttributes( nic *cosmic.Nic) resource.TestCheckFunc { return func(s *terraform.State) error { - if nic.Networkid != COSMIC_2ND_NIC_NETWORK { - return fmt.Errorf("Bad network ID: %s", nic.Networkid) + if nic.Networkname != "terraform-network-bar" { + return fmt.Errorf("Bad network name: %s", nic.Networkname) } return nil @@ -115,11 +116,11 @@ func testAccCheckCosmicNICIPAddress( nic *cosmic.Nic) resource.TestCheckFunc { return func(s *terraform.State) error { - if nic.Networkid != COSMIC_2ND_NIC_NETWORK { - return fmt.Errorf("Bad network ID: %s", nic.Networkname) + if nic.Networkname != "terraform-network-bar" { + return fmt.Errorf("Bad network name: %s", nic.Networkname) } - if nic.Ipaddress != COSMIC_2ND_NIC_IPADDRESS { + if nic.Ipaddress != "10.0.11.10" { return fmt.Errorf("Bad IP address: %s", nic.Ipaddress) } @@ -150,45 +151,80 @@ func testAccCheckCosmicNICDestroy(s *terraform.State) error { } var testAccCosmicNIC_basic = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network-foo" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + +resource "cosmic_network" "bar" { + name = "terraform-network-bar" + cidr = "10.0.11.0/24" + gateway = "10.0.11.1" + network_offering = "${cosmic_network.foo.network_offering}" + vpc_id = "${cosmic_network.foo.vpc_id}" + zone = "${cosmic_network.foo.zone}" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } -resource "cosmic_nic" "foo" { - network_id = "%s" +resource "cosmic_nic" "bar" { + network_id = "${cosmic_network.bar.id}" virtual_machine_id = "${cosmic_instance.foo.id}" }`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, COSMIC_ZONE, - COSMIC_2ND_NIC_NETWORK) + COSMIC_SERVICE_OFFERING_1, + COSMIC_TEMPLATE) var testAccCosmicNIC_ipaddress = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network-foo" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + +resource "cosmic_network" "bar" { + name = "terraform-network-bar" + cidr = "10.0.11.0/24" + gateway = "10.0.11.1" + network_offering = "${cosmic_network.foo.network_offering}" + vpc_id = "${cosmic_network.foo.vpc_id}" + zone = "${cosmic_network.foo.zone}" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } -resource "cosmic_nic" "foo" { - network_id = "%s" - ip_address = "%s" +resource "cosmic_nic" "bar" { + network_id = "${cosmic_network.bar.id}" + ip_address = "10.0.11.10" virtual_machine_id = "${cosmic_instance.foo.id}" }`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, COSMIC_ZONE, - COSMIC_2ND_NIC_NETWORK, - COSMIC_2ND_NIC_IPADDRESS) + COSMIC_SERVICE_OFFERING_1, + COSMIC_TEMPLATE) diff --git a/cosmic/resource_cosmic_port_forward_test.go b/cosmic/resource_cosmic_port_forward_test.go index 80f50ef..5ff8b19 100644 --- a/cosmic/resource_cosmic_port_forward_test.go +++ b/cosmic/resource_cosmic_port_forward_test.go @@ -16,12 +16,10 @@ func TestAccCosmicPortForward_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicPortForwardDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicPortForward_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicPortForwardsExist("cosmic_port_forward.foo"), - resource.TestCheckResourceAttr( - "cosmic_port_forward.foo", "ip_address_id", COSMIC_PUBLIC_IPADDRESS), resource.TestCheckResourceAttr( "cosmic_port_forward.foo", "forward.#", "1"), ), @@ -36,23 +34,19 @@ func TestAccCosmicPortForward_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicPortForwardDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicPortForward_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicPortForwardsExist("cosmic_port_forward.foo"), - resource.TestCheckResourceAttr( - "cosmic_port_forward.foo", "ip_address_id", COSMIC_PUBLIC_IPADDRESS), resource.TestCheckResourceAttr( "cosmic_port_forward.foo", "forward.#", "1"), ), }, - resource.TestStep{ + { Config: testAccCosmicPortForward_update, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicPortForwardsExist("cosmic_port_forward.foo"), - resource.TestCheckResourceAttr( - "cosmic_port_forward.foo", "ip_address_id", COSMIC_PUBLIC_IPADDRESS), resource.TestCheckResourceAttr( "cosmic_port_forward.foo", "forward.#", "2"), ), @@ -121,17 +115,31 @@ func testAccCheckCosmicPortForwardDestroy(s *terraform.State) error { } var testAccCosmicPortForward_basic = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } +resource "cosmic_ipaddress" "foo" { + acl_id = "%s" + vpc_id = "${cosmic_network.foo.vpc_id}" +} + resource "cosmic_port_forward" "foo" { - ip_address_id = "%s" + ip_address_id = "${cosmic_ipaddress.foo.id}" forward { protocol = "tcp" @@ -140,24 +148,39 @@ resource "cosmic_port_forward" "foo" { virtual_machine_id = "${cosmic_instance.foo.id}" } }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE, - COSMIC_PUBLIC_IPADDRESS) + COSMIC_DEFAULT_ALLOW_ACL_ID) var testAccCosmicPortForward_update = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } +resource "cosmic_ipaddress" "foo" { + acl_id = "%s" + vpc_id = "${cosmic_network.foo.vpc_id}" +} + resource "cosmic_port_forward" "foo" { - ip_address_id = "%s" + ip_address_id = "${cosmic_ipaddress.foo.id}" forward { protocol = "tcp" @@ -173,8 +196,9 @@ resource "cosmic_port_forward" "foo" { virtual_machine_id = "${cosmic_instance.foo.id}" } }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE, - COSMIC_PUBLIC_IPADDRESS) + COSMIC_DEFAULT_ALLOW_ACL_ID) diff --git a/cosmic/resource_cosmic_private_gateway_test.go b/cosmic/resource_cosmic_private_gateway_test.go index 1d53deb..8c270b4 100644 --- a/cosmic/resource_cosmic_private_gateway_test.go +++ b/cosmic/resource_cosmic_private_gateway_test.go @@ -17,7 +17,7 @@ func TestAccCosmicPrivateGateway_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicPrivateGatewayDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicPrivateGateway_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicPrivateGatewayExists( @@ -60,7 +60,7 @@ func testAccCheckCosmicPrivateGatewayExists(n string, gateway *cosmic.PrivateGat func testAccCheckCosmicPrivateGatewayAttributes(gateway *cosmic.PrivateGateway) resource.TestCheckFunc { return func(s *terraform.State) error { - if gateway.Ipaddress != COSMIC_PRIVGW_IPADDRESS { + if gateway.Ipaddress != "10.0.252.254" { return fmt.Errorf("Bad Gateway: %s", gateway.Ipaddress) } @@ -90,34 +90,23 @@ func testAccCheckCosmicPrivateGatewayDestroy(s *terraform.State) error { } var testAccCosmicPrivateGateway_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_network" "foo" { name = "terraform-network" - cidr = "%s" - network_offering = "%s" - zone = "${cosmic_vpc.foo.zone}" + cidr = "10.0.252.0/24" + network_offering = "DefaultPrivateGatewayNetworkOffering" + zone = "%s" } resource "cosmic_network_acl" "foo" { name = "terraform-acl" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "%s" } resource "cosmic_private_gateway" "foo" { - ip_address = "%s" + ip_address = "10.0.252.254" network_id = "${cosmic_network.foo.id}" acl_id = "${cosmic_network_acl.foo.id}" - vpc_id = "${cosmic_vpc.foo.id}" + vpc_id = "${cosmic_network_acl.foo.vpc_id}" }`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, COSMIC_ZONE, - COSMIC_PRIVNW_CIDR, - COSMIC_PRIVNW_OFFERING, - COSMIC_PRIVGW_IPADDRESS) + COSMIC_VPC_ID) diff --git a/cosmic/resource_cosmic_secondary_ipaddress_test.go b/cosmic/resource_cosmic_secondary_ipaddress_test.go index 8093c57..96d8fbc 100644 --- a/cosmic/resource_cosmic_secondary_ipaddress_test.go +++ b/cosmic/resource_cosmic_secondary_ipaddress_test.go @@ -17,7 +17,7 @@ func TestAccCosmicSecondaryIPAddress_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicSecondaryIPAddressDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicSecondaryIPAddress_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicSecondaryIPAddressExists( @@ -36,14 +36,14 @@ func TestAccCosmicSecondaryIPAddress_fixedIP(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicSecondaryIPAddressDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicSecondaryIPAddress_fixedIP, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicSecondaryIPAddressExists( "cosmic_secondary_ipaddress.foo", &ip), testAccCheckCosmicSecondaryIPAddressAttributes(&ip), resource.TestCheckResourceAttr( - "cosmic_secondary_ipaddress.foo", "ip_address", COSMIC_NETWORK_1_IPADDRESS1), + "cosmic_secondary_ipaddress.foo", "ip_address", "10.0.10.10"), ), }, }, @@ -124,7 +124,7 @@ func testAccCheckCosmicSecondaryIPAddressAttributes( ip *cosmic.AddIpToNicResponse) resource.TestCheckFunc { return func(s *terraform.State) error { - if ip.Ipaddress != COSMIC_NETWORK_1_IPADDRESS1 { + if ip.Ipaddress != "10.0.10.10" { return fmt.Errorf("Bad IP address: %s", ip.Ipaddress) } return nil @@ -200,39 +200,58 @@ func testAccCheckCosmicSecondaryIPAddressDestroy(s *terraform.State) error { } var testAccCosmicSecondaryIPAddress_basic = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } resource "cosmic_secondary_ipaddress" "foo" { virtual_machine_id = "${cosmic_instance.foo.id}" }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, - COSMIC_ZONE) + COSMIC_TEMPLATE) var testAccCosmicSecondaryIPAddress_fixedIP = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" expunge = true } resource "cosmic_secondary_ipaddress" "foo" { - ip_address = "%s" + ip_address = "10.0.10.10" virtual_machine_id = "${cosmic_instance.foo.id}" }`, - COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, - COSMIC_TEMPLATE, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, COSMIC_ZONE, - COSMIC_NETWORK_1_IPADDRESS1) + COSMIC_SERVICE_OFFERING_1, + COSMIC_TEMPLATE) diff --git a/cosmic/resource_cosmic_ssh_keypair_test.go b/cosmic/resource_cosmic_ssh_keypair_test.go index bd7fe79..772466e 100644 --- a/cosmic/resource_cosmic_ssh_keypair_test.go +++ b/cosmic/resource_cosmic_ssh_keypair_test.go @@ -18,7 +18,7 @@ func TestAccCosmicSSHKeyPair_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicSSHKeyPairDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicSSHKeyPair_create, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicSSHKeyPairExists("cosmic_ssh_keypair.foo", &sshkey), @@ -38,15 +38,13 @@ func TestAccCosmicSSHKeyPair_register(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicSSHKeyPairDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicSSHKeyPair_register, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicSSHKeyPairExists("cosmic_ssh_keypair.foo", &sshkey), testAccCheckCosmicSSHKeyPairAttributes(&sshkey), resource.TestCheckResourceAttr( - "cosmic_ssh_keypair.foo", - "public_key", - COSMIC_SSH_PUBLIC_KEY), + "cosmic_ssh_keypair.foo", "public_key", publicKey), ), }, }, @@ -89,7 +87,7 @@ func testAccCheckCosmicSSHKeyPairAttributes( fpLen := len(keypair.Fingerprint) if fpLen != 47 { - return fmt.Errorf("SSH key: Attribute private_key expected length 47, got %d", fpLen) + return fmt.Errorf("SSH key: Attribute fingerprint expected length 47, got %d", fpLen) } return nil @@ -157,13 +155,19 @@ func testAccCheckCosmicSSHKeyPairDestroy(s *terraform.State) error { return nil } -var testAccCosmicSSHKeyPair_create = fmt.Sprintf(` +const testAccCosmicSSHKeyPair_create = ` resource "cosmic_ssh_keypair" "foo" { name = "terraform-test-keypair" -}`) +}` var testAccCosmicSSHKeyPair_register = fmt.Sprintf(` resource "cosmic_ssh_keypair" "foo" { name = "terraform-test-keypair" public_key = "%s" -}`, COSMIC_SSH_PUBLIC_KEY) +}`, publicKey) + +const publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPcjvm/QSl+dtYa1RFWqJfDZcr5GMxegiPjefHz" + + "57zvTn/FXN4V5V5pS2nmmEfztm3TLEVSCA6kRWJHFf5A9cSAqc/NqGX5qb8J8wbuLzdKA+LvMfru3HoUeWrBPgzMu2rb" + + "16JqPYM6AGTSAmh93YabuuJW4HQ3NpvphtBS3XozYL5DUUzLpUtPrkzutyfQmfC71OSIO6Lxkt/uYfZALZ4u5hOhXfGQ" + + "Gx/M9aRHQyRuoyPTXEuzY2JH5H4Z++y1g/rVrb2TaSKXyaACnmYh2/s65qSiaZZ3P9WdfzCPOUMePaSLZLSj0ZhMjlS9" + + "OBT35VHz2tZ0p4VL8uOXNGyI/P user@host" diff --git a/cosmic/resource_cosmic_static_nat_test.go b/cosmic/resource_cosmic_static_nat_test.go index 4b335c2..fd0e62a 100644 --- a/cosmic/resource_cosmic_static_nat_test.go +++ b/cosmic/resource_cosmic_static_nat_test.go @@ -17,7 +17,7 @@ func TestAccCosmicStaticNAT_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicStaticNATDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicStaticNAT_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicStaticNATExists( @@ -66,8 +66,8 @@ func testAccCheckCosmicStaticNATAttributes( ipaddr *cosmic.PublicIpAddress) resource.TestCheckFunc { return func(s *terraform.State) error { - if ipaddr.Associatednetworkid != COSMIC_NETWORK_1 { - return fmt.Errorf("Bad network ID: %s", ipaddr.Associatednetworkid) + if ipaddr.Associatednetworkname != "terraform-network" { + return fmt.Errorf("Bad network name: %s", ipaddr.Associatednetworkname) } return nil @@ -96,26 +96,38 @@ func testAccCheckCosmicStaticNATDestroy(s *terraform.State) error { } var testAccCosmicStaticNAT_basic = fmt.Sprintf(` +resource "cosmic_network" "foo" { + name = "terraform-network" + cidr = "10.0.10.0/24" + gateway = "10.0.10.1" + network_offering = "%s" + vpc_id = "%s" + zone = "%s" +} + resource "cosmic_instance" "foo" { name = "terraform-test" display_name = "terraform-test" service_offering = "%s" - network_id = "%s" + network_id = "${cosmic_network.foo.id}" template = "%s" - zone = "%s" + zone = "${cosmic_network.foo.zone}" user_data = "foobar\nfoo\nbar" expunge = true } resource "cosmic_ipaddress" "foo" { - network_id = "${cosmic_instance.foo.network_id}" + acl_id = "%s" + vpc_id = "${cosmic_network.foo.vpc_id}" } resource "cosmic_static_nat" "foo" { ip_address_id = "${cosmic_ipaddress.foo.id}" virtual_machine_id = "${cosmic_instance.foo.id}" }`, + COSMIC_VPC_NETWORK_OFFERING, + COSMIC_VPC_ID, + COSMIC_ZONE, COSMIC_SERVICE_OFFERING_1, - COSMIC_NETWORK_1, COSMIC_TEMPLATE, - COSMIC_ZONE) + COSMIC_DEFAULT_ALLOW_ACL_ID) diff --git a/cosmic/resource_cosmic_static_route_test.go b/cosmic/resource_cosmic_static_route_test.go index 62f61c9..868e827 100644 --- a/cosmic/resource_cosmic_static_route_test.go +++ b/cosmic/resource_cosmic_static_route_test.go @@ -17,7 +17,7 @@ func TestAccCosmicStaticRoute_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicStaticRouteDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicStaticRoute_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicStaticRouteExists( @@ -62,8 +62,8 @@ func testAccCheckCosmicStaticRouteAttributes( route *cosmic.StaticRoute) resource.TestCheckFunc { return func(s *terraform.State) error { - if route.Cidr != COSMIC_STATIC_ROUTE_CIDR { - return fmt.Errorf("Bad Cidr: %s", route.Cidr) + if route.Cidr != "172.16.0.0/16" { + return fmt.Errorf("Bad CIDR: %s", route.Cidr) } return nil @@ -92,43 +92,8 @@ func testAccCheckCosmicStaticRouteDestroy(s *terraform.State) error { } var testAccCosmicStaticRoute_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - -resource "cosmic_network" "foo" { - name = "terraform-network" - cidr = "%s" - network_offering = "%s" - zone = "${cosmic_vpc.foo.zone}" -} - -resource "cosmic_network_acl" "foo" { - name = "terraform-acl" - vpc_id = "${cosmic_vpc.foo.id}" -} - -resource "cosmic_private_gateway" "foo" { - ip_address = "%s" - network_id = "${cosmic_network.foo.id}" - acl_id = "${cosmic_network_acl.foo.id}" - vpc_id = "${cosmic_vpc.foo.id}" -} - resource "cosmic_static_route" "foo" { - depends_on = ["cosmic_private_gateway.foo"] - cidr = "%s" - nexthop = "%s" - vpc_id = "${cosmic_vpc.foo.id}" -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_PRIVNW_CIDR, - COSMIC_PRIVNW_OFFERING, - COSMIC_PRIVGW_IPADDRESS, - COSMIC_STATIC_ROUTE_CIDR, - COSMIC_STATIC_ROUTE_NEXTHOP) + cidr = "172.16.0.0/16" + nexthop = "10.0.252.1" + vpc_id = "%s" +}`, COSMIC_VPC_ID) diff --git a/cosmic/resource_cosmic_template_test.go b/cosmic/resource_cosmic_template_test.go index 7b66262..37fe817 100644 --- a/cosmic/resource_cosmic_template_test.go +++ b/cosmic/resource_cosmic_template_test.go @@ -17,7 +17,7 @@ func TestAccCosmicTemplate_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicTemplateDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicTemplate_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicTemplateExists("cosmic_template.foo", &template), @@ -38,7 +38,7 @@ func TestAccCosmicTemplate_update(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicTemplateDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicTemplate_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicTemplateExists("cosmic_template.foo", &template), @@ -46,7 +46,7 @@ func TestAccCosmicTemplate_update(t *testing.T) { ), }, - resource.TestStep{ + { Config: testAccCosmicTemplate_update, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicTemplateExists( @@ -97,15 +97,15 @@ func testAccCheckCosmicTemplateBasicAttributes( return fmt.Errorf("Bad name: %s", template.Name) } - if template.Format != COSMIC_TEMPLATE_FORMAT { + if template.Format != "QCOW2" { return fmt.Errorf("Bad format: %s", template.Format) } - if template.Hypervisor != COSMIC_HYPERVISOR { + if template.Hypervisor != "KVM" { return fmt.Errorf("Bad hypervisor: %s", template.Hypervisor) } - if template.Ostypename != COSMIC_TEMPLATE_OS_TYPE { + if template.Ostypename != "Other PV (64-bit)" { return fmt.Errorf("Bad os type: %s", template.Ostypename) } @@ -161,32 +161,22 @@ func testAccCheckCosmicTemplateDestroy(s *terraform.State) error { var testAccCosmicTemplate_basic = fmt.Sprintf(` resource "cosmic_template" "foo" { name = "terraform-test" - format = "%s" - hypervisor = "%s" - os_type = "%s" - url = "%s" + format = "QCOW2" + hypervisor = "KVM" + os_type = "Other PV (64-bit)" + url = "http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2" zone = "%s" -}`, - COSMIC_TEMPLATE_FORMAT, - COSMIC_HYPERVISOR, - COSMIC_TEMPLATE_OS_TYPE, - COSMIC_TEMPLATE_URL, - COSMIC_ZONE) +}`, COSMIC_ZONE) var testAccCosmicTemplate_update = fmt.Sprintf(` resource "cosmic_template" "foo" { name = "terraform-test" display_text = "terraform-updated" - format = "%s" - hypervisor = "%s" - os_type = "%s" - url = "%s" + format = "QCOW2" + hypervisor = "KVM" + os_type = "Other PV (64-bit)" + url = "http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2" zone = "%s" is_dynamically_scalable = true password_enabled = true -}`, - COSMIC_TEMPLATE_FORMAT, - COSMIC_HYPERVISOR, - COSMIC_TEMPLATE_OS_TYPE, - COSMIC_TEMPLATE_URL, - COSMIC_ZONE) +}`, COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_vpc_test.go b/cosmic/resource_cosmic_vpc_test.go index afa9b22..2667a77 100644 --- a/cosmic/resource_cosmic_vpc_test.go +++ b/cosmic/resource_cosmic_vpc_test.go @@ -72,7 +72,7 @@ func testAccCheckCosmicVPCAttributes( return fmt.Errorf("Bad display text: %s", vpc.Displaytext) } - if vpc.Cidr != COSMIC_VPC_CIDR_1 { + if vpc.Cidr != "10.0.10.0/22" { return fmt.Errorf("Bad VPC CIDR: %s", vpc.Cidr) } @@ -109,11 +109,10 @@ var testAccCosmicVPC_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { name = "terraform-vpc" display_text = "terraform-vpc-text" - cidr = "%s" + cidr = "10.0.10.0/22" vpc_offering = "%s" network_domain = "terraform-domain" zone = "%s" }`, - COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_vpn_connection_test.go b/cosmic/resource_cosmic_vpn_connection_test.go index 3a65957..46599cc 100644 --- a/cosmic/resource_cosmic_vpn_connection_test.go +++ b/cosmic/resource_cosmic_vpn_connection_test.go @@ -17,7 +17,7 @@ func TestAccCosmicVPNConnection_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicVPNConnectionDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicVPNConnection_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicVPNConnectionExists( @@ -83,14 +83,14 @@ func testAccCheckCosmicVPNConnectionDestroy(s *terraform.State) error { var testAccCosmicVPNConnection_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { name = "terraform-vpc-foo" - cidr = "%s" + cidr = "10.0.10.0/22" vpc_offering = "%s" zone = "%s" } resource "cosmic_vpc" "bar" { name = "terraform-vpc-bar" - cidr = "%s" + cidr = "10.0.20.0/22" vpc_offering = "%s" zone = "%s" } @@ -105,19 +105,19 @@ resource "cosmic_vpn_gateway" "bar" { resource "cosmic_vpn_customer_gateway" "foo" { name = "terraform-foo" - cidr = "${cosmic_vpc.foo.cidr}" + cidr_list = ["${cosmic_vpc.foo.cidr}"] esp_policy = "aes256-sha1" gateway = "${cosmic_vpn_gateway.foo.public_ip}" - ike_policy = "aes256-sha1" + ike_policy = "aes256-sha1;modp1024" ipsec_psk = "terraform" } resource "cosmic_vpn_customer_gateway" "bar" { name = "terraform-bar" - cidr = "${cosmic_vpc.bar.cidr}" + cidr_list = ["${cosmic_vpc.bar.cidr}"] esp_policy = "aes256-sha1" gateway = "${cosmic_vpn_gateway.bar.public_ip}" - ike_policy = "aes256-sha1" + ike_policy = "aes256-sha1;modp1024" ipsec_psk = "terraform" } @@ -130,9 +130,7 @@ resource "cosmic_vpn_connection" "bar-foo" { customer_gateway_id = "${cosmic_vpn_customer_gateway.bar.id}" vpn_gateway_id = "${cosmic_vpn_gateway.foo.id}" }`, - COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, COSMIC_ZONE, - COSMIC_VPC_CIDR_2, COSMIC_VPC_OFFERING, COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_vpn_customer_gateway_test.go b/cosmic/resource_cosmic_vpn_customer_gateway_test.go index 326cde3..78e5c68 100644 --- a/cosmic/resource_cosmic_vpn_customer_gateway_test.go +++ b/cosmic/resource_cosmic_vpn_customer_gateway_test.go @@ -17,7 +17,7 @@ func TestAccCosmicVPNCustomerGateway_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicVPNCustomerGatewayDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicVPNCustomerGateway_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicVPNCustomerGatewayExists( @@ -27,55 +27,10 @@ func TestAccCosmicVPNCustomerGateway_basic(t *testing.T) { "cosmic_vpn_customer_gateway.foo", "name", "terraform-foo"), resource.TestCheckResourceAttr( "cosmic_vpn_customer_gateway.bar", "name", "terraform-bar"), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.foo", "ike_policy", "aes256-sha1"), resource.TestCheckResourceAttr( "cosmic_vpn_customer_gateway.bar", "esp_policy", "aes256-sha1"), - ), - }, - }, - }) -} - -func TestAccCosmicVPNCustomerGateway_update(t *testing.T) { - var vpnCustomerGateway cosmic.VpnCustomerGateway - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCosmicVPNCustomerGatewayDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCosmicVPNCustomerGateway_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicVPNCustomerGatewayExists( - "cosmic_vpn_customer_gateway.foo", &vpnCustomerGateway), - testAccCheckCosmicVPNCustomerGatewayAttributes(&vpnCustomerGateway), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.foo", "name", "terraform-foo"), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.bar", "name", "terraform-bar"), resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.foo", "ike_policy", "aes256-sha1"), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.bar", "esp_policy", "aes256-sha1"), - ), - }, - - resource.TestStep{ - Config: testAccCosmicVPNCustomerGateway_update, - Check: resource.ComposeTestCheckFunc( - testAccCheckCosmicVPNCustomerGatewayExists( - "cosmic_vpn_customer_gateway.foo", &vpnCustomerGateway), - testAccCheckCosmicVPNCustomerGatewayUpdatedAttributes(&vpnCustomerGateway), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.foo", "name", "terraform-foo-bar"), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.bar", "name", "terraform-bar-foo"), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.foo", "ike_policy", "3des-md5"), - resource.TestCheckResourceAttr( - "cosmic_vpn_customer_gateway.bar", "esp_policy", "3des-md5"), + "cosmic_vpn_customer_gateway.foo", "ike_policy", "aes256-sha1;modp1024"), ), }, }, @@ -119,27 +74,7 @@ func testAccCheckCosmicVPNCustomerGatewayAttributes( return fmt.Errorf("Bad ESP policy: %s", vpnCustomerGateway.Esppolicy) } - if vpnCustomerGateway.Ikepolicy != "aes256-sha1" { - return fmt.Errorf("Bad IKE policy: %s", vpnCustomerGateway.Ikepolicy) - } - - if vpnCustomerGateway.Ipsecpsk != "terraform" { - return fmt.Errorf("Bad IPSEC pre-shared key: %s", vpnCustomerGateway.Ipsecpsk) - } - - return nil - } -} - -func testAccCheckCosmicVPNCustomerGatewayUpdatedAttributes( - vpnCustomerGateway *cosmic.VpnCustomerGateway) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if vpnCustomerGateway.Esppolicy != "3des-md5" { - return fmt.Errorf("Bad ESP policy: %s", vpnCustomerGateway.Esppolicy) - } - - if vpnCustomerGateway.Ikepolicy != "3des-md5" { + if vpnCustomerGateway.Ikepolicy != "aes256-sha1;modp1024" { return fmt.Errorf("Bad IKE policy: %s", vpnCustomerGateway.Ikepolicy) } @@ -175,14 +110,14 @@ func testAccCheckCosmicVPNCustomerGatewayDestroy(s *terraform.State) error { var testAccCosmicVPNCustomerGateway_basic = fmt.Sprintf(` resource "cosmic_vpc" "foo" { name = "terraform-vpc-foo" - cidr = "%s" + cidr = "10.0.10.0/22" vpc_offering = "%s" zone = "%s" } resource "cosmic_vpc" "bar" { name = "terraform-vpc-bar" - cidr = "%s" + cidr = "10.0.20.0/22" vpc_offering = "%s" zone = "%s" } @@ -197,71 +132,22 @@ resource "cosmic_vpn_gateway" "bar" { resource "cosmic_vpn_customer_gateway" "foo" { name = "terraform-foo" - cidr = "${cosmic_vpc.foo.cidr}" - esp_policy = "aes256-sha1" + cidr_list = ["${cosmic_vpc.foo.cidr}"] gateway = "${cosmic_vpn_gateway.foo.public_ip}" - ike_policy = "aes256-sha1" - ipsec_psk = "terraform" -} - -resource "cosmic_vpn_customer_gateway" "bar" { - name = "terraform-bar" - cidr = "${cosmic_vpc.bar.cidr}" esp_policy = "aes256-sha1" - gateway = "${cosmic_vpn_gateway.bar.public_ip}" - ike_policy = "aes256-sha1" - ipsec_psk = "terraform" -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE, - COSMIC_VPC_CIDR_2, - COSMIC_VPC_OFFERING, - COSMIC_ZONE) - -var testAccCosmicVPNCustomerGateway_update = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc-foo" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - -resource "cosmic_vpc" "bar" { - name = "terraform-vpc-bar" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - -resource "cosmic_vpn_gateway" "foo" { - vpc_id = "${cosmic_vpc.foo.id}" -} - -resource "cosmic_vpn_gateway" "bar" { - vpc_id = "${cosmic_vpc.bar.id}" -} - -resource "cosmic_vpn_customer_gateway" "foo" { - name = "terraform-foo-bar" - cidr = "${cosmic_vpc.foo.cidr}" - esp_policy = "3des-md5" - gateway = "${cosmic_vpn_gateway.foo.public_ip}" - ike_policy = "3des-md5" + ike_policy = "aes256-sha1;modp1024" ipsec_psk = "terraform" } resource "cosmic_vpn_customer_gateway" "bar" { - name = "terraform-bar-foo" - cidr = "${cosmic_vpc.bar.cidr}" - esp_policy = "3des-md5" + name = "terraform-bar" + cidr_list = ["${cosmic_vpc.bar.cidr}"] gateway = "${cosmic_vpn_gateway.bar.public_ip}" - ike_policy = "3des-md5" + esp_policy = "aes256-sha1" + ike_policy = "aes256-sha1;modp1024" ipsec_psk = "terraform" }`, - COSMIC_VPC_CIDR_1, COSMIC_VPC_OFFERING, COSMIC_ZONE, - COSMIC_VPC_CIDR_2, COSMIC_VPC_OFFERING, COSMIC_ZONE) diff --git a/cosmic/resource_cosmic_vpn_gateway_test.go b/cosmic/resource_cosmic_vpn_gateway_test.go index 0c3ea96..f7eecb1 100644 --- a/cosmic/resource_cosmic_vpn_gateway_test.go +++ b/cosmic/resource_cosmic_vpn_gateway_test.go @@ -17,7 +17,7 @@ func TestAccCosmicVPNGateway_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckCosmicVPNGatewayDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccCosmicVPNGateway_basic, Check: resource.ComposeTestCheckFunc( testAccCheckCosmicVPNGatewayExists( @@ -79,17 +79,6 @@ func testAccCheckCosmicVPNGatewayDestroy(s *terraform.State) error { } var testAccCosmicVPNGateway_basic = fmt.Sprintf(` -resource "cosmic_vpc" "foo" { - name = "terraform-vpc" - display_text = "terraform-vpc-text" - cidr = "%s" - vpc_offering = "%s" - zone = "%s" -} - resource "cosmic_vpn_gateway" "foo" { - vpc_id = "${cosmic_vpc.foo.id}" -}`, - COSMIC_VPC_CIDR_1, - COSMIC_VPC_OFFERING, - COSMIC_ZONE) + vpc_id = "%s" +}`, COSMIC_VPC_ID) From f13f048e5f4f482f0ec049f3b274c51f59cd8dd6 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 25 Feb 2019 16:24:26 +0100 Subject: [PATCH 7/8] Don't recreate loadbalancer_rule resources No longer need to recreate the resource when changing the member_ids, private_port, public_port or protocol options. Signed-off-by: Stephen Hoekstra --- CHANGELOG.md | 1 + cosmic/resource_cosmic_loadbalancer_rule.go | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1df9c8..15873f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## Unreleased - Add option to configure provider using `COSMIC_CONFIG` and `COSMIC_PROFILE` environment variables +- Changing `cosmic_loadbalancer_rule`'s `member_ids`, `private_port`, `public_port` or `protocol` options no longer recreates the resource - Changing `cosmic_network`'s `ip_exclusion_list` option no longer recreates the resource - Changing `cosmic_vpc`'s `vpc_offering` option no longer recreates the resource - Removed `cosmic_egress_firewall` and `cosmic_firewall` resources; no longer implemented by the Cosmic API diff --git a/cosmic/resource_cosmic_loadbalancer_rule.go b/cosmic/resource_cosmic_loadbalancer_rule.go index ea6e08a..843a362 100644 --- a/cosmic/resource_cosmic_loadbalancer_rule.go +++ b/cosmic/resource_cosmic_loadbalancer_rule.go @@ -51,20 +51,17 @@ func resourceCosmicLoadBalancerRule() *schema.Resource { "private_port": &schema.Schema{ Type: schema.TypeInt, Required: true, - ForceNew: true, }, "public_port": &schema.Schema{ Type: schema.TypeInt, Required: true, - ForceNew: true, }, "protocol": &schema.Schema{ Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { v := val.(string) switch v { @@ -80,7 +77,6 @@ func resourceCosmicLoadBalancerRule() *schema.Resource { "member_ids": &schema.Schema{ Type: schema.TypeList, Required: true, - ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, }, From 7e56909e740a941fa36e59c399fabb877e40c6e8 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 25 Feb 2019 16:29:24 +0100 Subject: [PATCH 8/8] Increase acceptance test timeout Signed-off-by: Stephen Hoekstra --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index a4226f0..6ebd85e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -14,7 +14,7 @@ test: fmtcheck xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 testacc: fmtcheck - TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 30m + TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout=60m vet: @echo "go vet ."