Skip to content

Commit

Permalink
Add resource openstack_orchestration_stack_v1 (gophercloud#944)
Browse files Browse the repository at this point in the history
* 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
ricolin authored and ozerovandrei committed Dec 20, 2019
1 parent 5544a23 commit a54ff36
Show file tree
Hide file tree
Showing 20 changed files with 2,662 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/terraform-providers/terraform-provider-openstack

require (
github.com/gophercloud/gophercloud v0.7.1-0.20191211202411-f940f50ff1f7
github.com/gophercloud/utils v0.0.0-20191129022341-463e26ffa30d
github.com/gophercloud/utils v0.0.0-20191212191830-4533a07bd492
github.com/hashicorp/terraform-plugin-sdk v1.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/stretchr/testify v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/gophercloud/gophercloud v0.0.0-20190212181753-892256c46858/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gophercloud/gophercloud v0.7.1-0.20191211202411-f940f50ff1f7 h1:iYD//82P8YSpKrCUaYhLMoxnIXmT5qvNNKTy5iGgc30=
github.com/gophercloud/gophercloud v0.7.1-0.20191211202411-f940f50ff1f7/go.mod h1:gmC5oQqMDOMO1t1gq5DquX/yAU808e/4mzjjDA76+Ss=
github.com/gophercloud/utils v0.0.0-20191129022341-463e26ffa30d h1:lHwkWOlNjHUNDVdoOacrVD/UKqLn/xsEGyD8JBATv9Y=
github.com/gophercloud/utils v0.0.0-20191129022341-463e26ffa30d/go.mod h1:SZ9FTKibIotDtCrxAU/evccoyu1yhKST6hgBvwTB5Eg=
github.com/gophercloud/utils v0.0.0-20191212191830-4533a07bd492 h1:NAwq2GgRiqbNLw1cA7KUdt7lDR/NzJtk4EXGxO3gqas=
github.com/gophercloud/utils v0.0.0-20191212191830-4533a07bd492/go.mod h1:SZ9FTKibIotDtCrxAU/evccoyu1yhKST6hgBvwTB5Eg=
github.com/hashicorp/errwrap v0.0.0-20180715044906-d6c0cd880357/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
2 changes: 1 addition & 1 deletion openstack/containerinfra_shared_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func containerInfraClusterV1MasterFlavor(d *schema.ResourceData) (string, error)
return flavor, nil
}

// Try the OS_MAGNUM_FLAVOR environment variable
// Try the OS_MAGNUM_MASTER_FLAVOR environment variable
if v := os.Getenv("OS_MAGNUM_MASTER_FLAVOR"); v != "" {
return v, nil
}
Expand Down
31 changes: 31 additions & 0 deletions openstack/import_openstack_orchestration_stack_v1_test.go
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",
},
},
},
})
}
71 changes: 71 additions & 0 deletions openstack/orchestration_stack_v1.go
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
}
}
1 change: 1 addition & 0 deletions openstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func Provider() terraform.ResourceProvider {
"openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(),
"openstack_objectstorage_object_v1": resourceObjectStorageObjectV1(),
"openstack_objectstorage_tempurl_v1": resourceObjectstorageTempurlV1(),
"openstack_orchestration_stack_v1": resourceOrchestrationStackV1(),
"openstack_vpnaas_ipsec_policy_v2": resourceIPSecPolicyV2(),
"openstack_vpnaas_service_v2": resourceServiceV2(),
"openstack_vpnaas_ike_policy_v2": resourceIKEPolicyV2(),
Expand Down

0 comments on commit a54ff36

Please sign in to comment.