forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resource openstack_orchestration_stack_v1 (gophercloud#944)
* Add resource openstack_orchestration_stack_v1 With stack support, you will be able to create stack and create any resource types from OpenStack heat if that type is supported with your Orchestraion service. * Add website docs for orchestration_stack_v1 resource
- Loading branch information
1 parent
5544a23
commit a54ff36
Showing
20 changed files
with
2,662 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package openstack | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccOrchestrationStackV1_importBasic(t *testing.T) { | ||
resourceName := "openstack_orchestration_stack_v1.stack_1" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckOrchestrationV1StackDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOrchestrationV1Stack_basic, | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"environment_opts", | ||
"template_opts", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package openstack | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/gophercloud/gophercloud" | ||
"github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func buildTE(t map[string]interface{}) stacks.TE { | ||
log.Printf("[DEBUG] Start to build TE structure") | ||
te := stacks.TE{} | ||
if t["Bin"] != nil { | ||
te.Bin = []byte(t["Bin"].(string)) | ||
} | ||
if t["URL"] != nil { | ||
te.URL = t["URL"].(string) | ||
} | ||
if t["Files"] != nil { | ||
te.Files = t["Files"].(map[string]string) | ||
} | ||
log.Printf("[DEBUG] TE structure builded") | ||
return te | ||
} | ||
|
||
func buildTemplateOpts(d *schema.ResourceData) *stacks.Template { | ||
log.Printf("[DEBUG] Start building TemplateOpts") | ||
template := &stacks.Template{} | ||
template.TE = buildTE(d.Get("template_opts").(map[string]interface{})) | ||
log.Printf("[DEBUG] Return TemplateOpts") | ||
return template | ||
} | ||
|
||
func buildEnvironmentOpts(d *schema.ResourceData) *stacks.Environment { | ||
log.Printf("[DEBUG] Start building EnvironmentOpts") | ||
environment := &stacks.Environment{} | ||
if d.Get("environment_opts") != nil { | ||
t := d.Get("environment_opts").(map[string]interface{}) | ||
environment.TE = buildTE(t) | ||
log.Printf("[DEBUG] Return EnvironmentOpts") | ||
return environment | ||
} | ||
return nil | ||
} | ||
|
||
func orchestrationStackV1StateRefreshFunc(client *gophercloud.ServiceClient, stackID string, isdelete bool) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
log.Printf("[DEBUG] Refresh Stack status %s", stackID) | ||
stack, err := stacks.Find(client, stackID).Extract() | ||
if err != nil { | ||
if _, ok := err.(gophercloud.ErrDefault404); ok && isdelete { | ||
return stack, "DELETE_COMPLETE", nil | ||
} | ||
|
||
return nil, "", err | ||
} | ||
|
||
if strings.Contains(stack.Status, "FAILED") { | ||
return stack, stack.Status, fmt.Errorf("The stack is in error status. " + | ||
"Please check with your cloud admin or check the orchestration " + | ||
"API logs to see why this error occurred.") | ||
} | ||
|
||
return stack, stack.Status, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.