-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CCE service #19
Merged
Merged
Add CCE service #19
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
765d547
add cce cluster and node resources
1ce29ac
add cce cluster and node resource docs
f5e232b
changed file name in .erb file
frisky-dis 4a5a125
add cce resources to changelog
Savasw 68c93b0
resolve PR #19 conflicts
f8e983f
Merge remote-tracking branch 'origin/cce-dev' into cce-dev
6cde3c4
update CHANGELOG.md
c1c1b65
gofmt provider.go file
005ecf1
resolve PR #19 conflict
simrannagra d6bdeb2
update cce cluster and node resource docs
simrannagra 5eefa4d
update changelog to move cce resources to proper version
Savasw 760c5f1
skip acceptance test for cce node if env var is empty
Savasw 382df43
modify cce node create interface
ninja-vlogs 808c745
resolved PR #19 merge conflicts
ninja-vlogs 6d5d823
apply gofmt
ninja-vlogs 8ce94b9
Update resource_huaweicloud_cce_node_v3_test.go
niuzhenguo 09a4b40
changed OS_SUBNET_ID to OS_NETWORK_ID in acceptance test files
ninja-vlogs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters" | ||
) | ||
|
||
func dataSourceCCEClusterV3() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCCEClusterV3Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"flavor": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"cluster_version": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"cluster_type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"billing_mode": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"vpc_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"subnet_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"highway_subnet_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"container_network_type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"container_network_cidr": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"endpoints": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
cceClient, err := config.cceV3Client(GetRegion(d, config)) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Unable to create HuaweiCloud CCE client : %s", err) | ||
} | ||
|
||
listOpts := clusters.ListOpts{ | ||
ID: d.Get("id").(string), | ||
Name: d.Get("name").(string), | ||
Type: d.Get("cluster_type").(string), | ||
Phase: d.Get("status").(string), | ||
VpcID: d.Get("vpc_id").(string), | ||
} | ||
|
||
refinedClusters, err := clusters.List(cceClient, listOpts) | ||
log.Printf("[DEBUG] Value of allClusters: %#v", refinedClusters) | ||
if err != nil { | ||
return fmt.Errorf("Unable to retrieve clusters: %s", err) | ||
} | ||
|
||
if len(refinedClusters) < 1 { | ||
return fmt.Errorf("Your query returned no results. " + | ||
"Please change your search criteria and try again.") | ||
} | ||
|
||
if len(refinedClusters) > 1 { | ||
return fmt.Errorf("Your query returned more than one result." + | ||
" Please try a more specific search criteria") | ||
} | ||
|
||
Cluster := refinedClusters[0] | ||
|
||
log.Printf("[DEBUG] Retrieved Clusters using given filter %s: %+v", Cluster.Metadata.Id, Cluster) | ||
var v []map[string]interface{} | ||
for _, endpoint := range Cluster.Status.Endpoints { | ||
|
||
mapping := map[string]interface{}{ | ||
"url": endpoint.Url, | ||
"type": endpoint.Type, | ||
} | ||
v = append(v, mapping) | ||
} | ||
|
||
d.SetId(Cluster.Metadata.Id) | ||
|
||
d.Set("name", Cluster.Metadata.Name) | ||
d.Set("flavor", Cluster.Spec.Flavor) | ||
d.Set("description", Cluster.Spec.Description) | ||
d.Set("cluster_version", Cluster.Spec.Version) | ||
d.Set("cluster_type", Cluster.Spec.Type) | ||
d.Set("billing_mode", Cluster.Spec.BillingMode) | ||
d.Set("vpc_id", Cluster.Spec.HostNetwork.VpcId) | ||
d.Set("subnet_id", Cluster.Spec.HostNetwork.SubnetId) | ||
d.Set("highway_subnet_id", Cluster.Spec.HostNetwork.HighwaySubnet) | ||
d.Set("container_network_cidr", Cluster.Spec.ContainerNetwork.Cidr) | ||
d.Set("container_network_type", Cluster.Spec.ContainerNetwork.Mode) | ||
d.Set("status", Cluster.Status.Phase) | ||
if err := d.Set("endpoints", v); err != nil { | ||
return err | ||
} | ||
d.Set("region", GetRegion(d, config)) | ||
|
||
return nil | ||
} |
62 changes: 62 additions & 0 deletions
62
huaweicloud/data_source_huaweicloud_cce_cluster_v3_test.go
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,62 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
"testing" | ||
) | ||
|
||
func TestAccCCEClusterV3DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheckCCE(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccCCEClusterV3DataSource_cluster, | ||
}, | ||
resource.TestStep{ | ||
Config: testAccCCEClusterV3DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCCEClusterV3DataSourceID("data.huaweicloud_cce_cluster_v3.clusters"), | ||
resource.TestCheckResourceAttr("data.huaweicloud_cce_cluster_v3.clusters", "name", "huaweicloud-cce"), | ||
resource.TestCheckResourceAttr("data.huaweicloud_cce_cluster_v3.clusters", "status", "Available"), | ||
resource.TestCheckResourceAttr("data.huaweicloud_cce_cluster_v3.clusters", "cluster_type", "VirtualMachine"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCCEClusterV3DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find cluster data source: %s ", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("cluster data source ID not set ") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccCCEClusterV3DataSource_cluster = fmt.Sprintf(` | ||
resource "huaweicloud_cce_cluster_v3" "cluster_1" { | ||
name = "huaweicloud-cce" | ||
cluster_type = "VirtualMachine" | ||
flavor = "cce.s1.small" | ||
cluster_version = "v1.7.3-r10" | ||
vpc_id = "%s" | ||
subnet_id = "%s" | ||
container_network_type = "overlay_l2" | ||
}`, OS_VPC_ID, OS_SUBNET_ID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all such OS_SUBNET_ID should be changed to OS_NETWORK_ID which we already added. |
||
|
||
var testAccCCEClusterV3DataSource_basic = fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_cce_cluster_v3" "clusters" { | ||
name = "${huaweicloud_cce_cluster_v3.cluster_1.name}" | ||
} | ||
`, testAccCCEClusterV3DataSource_cluster) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why adding a new release stanza 1.1.2? You should not manually changed the v1.1.1 below to released which should be triggered by hashicorp release bot.