forked from rancher/norman
-
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.
Merge pull request rancher#128 from rawmind0/multiapp
Added rancher2_multi_cluster_app datasource and resource
- Loading branch information
Showing
26 changed files
with
2,249 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceRancher2MultiClusterApp() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceRancher2MultiClusterAppRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Multi cluster app name", | ||
}, | ||
"targets": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Multi cluster app targets", | ||
Elem: &schema.Resource{ | ||
Schema: targetFields(), | ||
}, | ||
}, | ||
"catalog_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Multi cluster app catalog name", | ||
}, | ||
"answers": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Multi cluster app answers", | ||
Elem: &schema.Resource{ | ||
Schema: answerFields(), | ||
}, | ||
}, | ||
"members": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Multi cluster app members", | ||
Elem: &schema.Resource{ | ||
Schema: memberFields(), | ||
}, | ||
}, | ||
"revision_history_limit": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Multi cluster app revision history limit", | ||
}, | ||
"revision_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Multi cluster app revision id", | ||
}, | ||
"roles": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Multi cluster app members", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"template_version": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Multi cluster app template version", | ||
}, | ||
"template_version_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Multi cluster app template version ID", | ||
}, | ||
"template_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Multi cluster app template name", | ||
}, | ||
"upgrade_strategy": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Multi cluster app upgrade strategy", | ||
Elem: &schema.Resource{ | ||
Schema: upgradeStrategyFields(), | ||
}, | ||
}, | ||
"annotations": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
"labels": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceRancher2MultiClusterAppRead(d *schema.ResourceData, meta interface{}) error { | ||
name := d.Get("name").(string) | ||
|
||
filters := map[string]interface{}{ | ||
"name": name, | ||
} | ||
|
||
listOpts := NewListOpts(filters) | ||
|
||
client, err := meta.(*Config).ManagementClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
multiClusterApps, err := client.MultiClusterApp.List(listOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
count := len(multiClusterApps.Data) | ||
if count <= 0 { | ||
return fmt.Errorf("[ERROR] multi cluster app with name \"%s\" not found", name) | ||
} | ||
if count > 1 { | ||
return fmt.Errorf("[ERROR] found %d multi cluster app with name \"%s\"", count, name) | ||
} | ||
|
||
return flattenMultiClusterApp(d, &multiClusterApps.Data[0]) | ||
} |
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,73 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
const ( | ||
testAccRancher2MultiClusterAppDataSourceType = "rancher2_multi_cluster_app" | ||
) | ||
|
||
var ( | ||
testAccCheckRancher2MultiClusterAppDataSourceConfig string | ||
) | ||
|
||
func init() { | ||
testAccCheckRancher2MultiClusterAppDataSourceConfig = ` | ||
resource "rancher2_project" "foo" { | ||
name = "foo" | ||
cluster_id = "` + testAccRancher2ClusterID + `" | ||
description = "Terraform project acceptance test" | ||
resource_quota { | ||
project_limit { | ||
limits_cpu = "2000m" | ||
limits_memory = "2000Mi" | ||
requests_storage = "2Gi" | ||
} | ||
namespace_default_limit { | ||
limits_cpu = "500m" | ||
limits_memory = "500Mi" | ||
requests_storage = "1Gi" | ||
} | ||
} | ||
} | ||
resource "rancher2_multi_cluster_app" "foo" { | ||
catalog_name = "library" | ||
name = "foo" | ||
targets { | ||
project_id = "${rancher2_project.foo.id}" | ||
} | ||
template_name = "docker-registry" | ||
template_version = "1.6.1" | ||
answers { | ||
values = { | ||
"ingress_host" = "test.xip.io" | ||
} | ||
} | ||
roles = ["project-member"] | ||
} | ||
data "` + testAccRancher2MultiClusterAppDataSourceType + `" "foo" { | ||
name = "${rancher2_multi_cluster_app.foo.name}" | ||
} | ||
` | ||
} | ||
|
||
func TestAccRancher2MultiClusterAppDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckRancher2MultiClusterAppDataSourceConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data."+testAccRancher2MultiClusterAppDataSourceType+".foo", "name", "foo"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2MultiClusterAppDataSourceType+".foo", "template_version_id", "cattle-global-data:library-docker-registry-1.6.1"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2MultiClusterAppDataSourceType+".foo", "answers.0.values.ingress_host", "test.xip.io"), | ||
resource.TestCheckResourceAttr("data."+testAccRancher2MultiClusterAppDataSourceType+".foo", "roles.0", "project-member"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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,18 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceRancher2MultiClusterAppImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
resourceID := "cattle-global-data:" + d.Id() | ||
|
||
d.SetId(resourceID) | ||
|
||
err := resourceRancher2MultiClusterAppRead(d, meta) | ||
if err != nil { | ||
return []*schema.ResourceData{}, err | ||
} | ||
|
||
return []*schema.ResourceData{d}, 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.