Skip to content

Commit

Permalink
add enterprise_project_id to cce_cluster, rds, obs, sfs_file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Oct 21, 2020
1 parent ba34e0c commit 1842fb4
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/resources/cce_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ versions are available, choose Dashboard > Buy Cluster on the CCE console. Chang
- iptables: Traditional kube-proxy uses iptables rules to implement service load balancing. In this mode, too many iptables rules will be generated when many services are deployed. In addition, non-incremental updates will cause a latency and even obvious performance issues in the case of heavy service traffic.
- ipvs: Optimized kube-proxy mode with higher throughput and faster speed. This mode supports incremental updates and can keep connections uninterrupted during service updates. It is suitable for large-sized clusters.

* `enterprise_project_id` - (Optional) The enterprise project id of the cce cluster. Changing this creates a new cluster.

## Attributes Reference

All above argument parameters can be exported as attribute parameters along with attribute reference.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/obs_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ The `noncurrent_version_transition` object supports the following
* `days` (Required) Specifies the number of days when noncurrent object versions are automatically transitioned to the specified storage class.
* `storage_class` - (Required) The class of storage used to store the object. Only `WARM` and `COLD` are supported.

* `enterprise_project_id` - (Optional) The enterprise project id of the OBS bucket. Changing this creates a OBS bucket.

## Attributes Reference

The following attributes are exported:
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/rds_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ The following arguments are supported:
(Optional)
Specifies the parameter group ID. Changing this parameter will create a new resource.

* `enterprise_project_id` -
(Optional)
The enterprise project id of the RDS. Changing this creates a new RDS.

The `db` block supports:

* `password` -
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/sfs_file_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The following arguments are supported:
* `access_type` - (Optional) Specifies the type of the share access rule. The default value is *cert*.
Changing this will create a new access rule.

* `enterprise_project_id` - (Optional) The enterprise project id of the SFS. Changing this creates a new SFS.

* `access_to` - (Optional) Specifies the value that defines the access rule. The value contains 1 to 255 characters.
Changing this will create a new access rule. The value varies according to the scenario:
- Set the VPC ID in VPC authorization scenarios.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/vpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ The following arguments are supported:

* `tags` - (Optional) The key/value pairs to associate with the vpc.

* `enterprise_project_id` - (Optional) The enterprise project id of the vpc. Changing this creates a new vpc.

## Attributes Reference

The following attributes are exported:
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/vpc_eip.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The following arguments are supported:

* `bandwidth` - (Required) The bandwidth object.

* `enterprise_project_id` - (Optional) The enterprise project id of the elastic IP. Changing this creates a new eip.


The `publicip` block supports:

Expand Down
17 changes: 15 additions & 2 deletions huaweicloud/resource_huaweicloud_cce_cluster_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ func resourceCCEClusterV3() *schema.Resource {
Optional: true,
ForceNew: true,
},
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -209,7 +215,7 @@ func resourceClusterAnnotationsV3(d *schema.ResourceData) map[string]string {
}
return m
}
func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string {
func resourceClusterExtendParamV3(d *schema.ResourceData, config *Config) map[string]string {
m := make(map[string]string)
for key, val := range d.Get("extend_param").(map[string]interface{}) {
m[key] = val.(string)
Expand All @@ -223,6 +229,12 @@ func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string {
if eip, ok := d.GetOk("eip"); ok {
m["clusterExternalIP"] = eip.(string)
}

epsID := GetEnterpriseProjectID(d, config)

if epsID != "" {
m["enterpriseProjectId"] = epsID
}
return m
}

Expand Down Expand Up @@ -263,7 +275,7 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error
AuthenticatingProxy: authenticating_proxy,
},
BillingMode: d.Get("billing_mode").(int),
ExtendParam: resourceClusterExtendParamV3(d),
ExtendParam: resourceClusterExtendParamV3(d, config),
},
}

Expand Down Expand Up @@ -326,6 +338,7 @@ func resourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error {
d.Set("authentication_mode", n.Spec.Authentication.Mode)
d.Set("security_group_id", n.Spec.HostNetwork.SecurityGroup)
d.Set("region", GetRegion(d, config))
d.Set("enterprise_project_id", n.Spec.ExtendParam["enterpriseProjectId"])

r := clusters.GetCert(cceClient, d.Id())

Expand Down
38 changes: 38 additions & 0 deletions huaweicloud/resource_huaweicloud_cce_cluster_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ func TestAccCCEClusterV3_withEip(t *testing.T) {
})
}

func TestAccCCEClusterV3_withEpsId(t *testing.T) {
var cluster clusters.Clusters

rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "huaweicloud_cce_cluster.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEpsID(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCCEClusterV3Destroy,
Steps: []resource.TestStep{
{
Config: testAccCCEClusterV3_withEpsId(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCCEClusterV3Exists(resourceName, &cluster),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID),
),
},
},
})
}

func testAccCheckCCEClusterV3Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
cceClient, err := config.cceV3Client(OS_REGION_NAME)
Expand Down Expand Up @@ -209,3 +231,19 @@ resource "huaweicloud_cce_cluster_v3" "test" {
}
`, testAccCCEClusterV3_Base(rName), rName)
}

func testAccCCEClusterV3_withEpsId(rName string) string {
return fmt.Sprintf(`
%s
resource "huaweicloud_cce_cluster" "test" {
name = "%s"
flavor_id = "cce.s1.small"
vpc_id = huaweicloud_vpc_v1.test.id
subnet_id = huaweicloud_vpc_subnet_v1.test.id
container_network_type = "overlay_l2"
enterprise_project_id = "%s"
}
`, testAccCCEClusterV3_Base(rName), rName, OS_ENTERPRISE_PROJECT_ID)
}
30 changes: 30 additions & 0 deletions huaweicloud/resource_huaweicloud_obs_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ func resourceObsBucket() *schema.Resource {
Computed: true,
},

"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"bucket_domain_name": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -289,6 +296,7 @@ func resourceObsBucketCreate(d *schema.ResourceData, meta interface{}) error {
Bucket: bucket,
ACL: obs.AclType(acl),
StorageClass: obs.StorageClassType(class),
Epid: GetEnterpriseProjectID(d, config),
}
opts.Location = region
log.Printf("[DEBUG] OBS bucket create opts: %#v", opts)
Expand Down Expand Up @@ -415,6 +423,11 @@ func resourceObsBucketRead(d *schema.ResourceData, meta interface{}) error {
return err
}

// Read enterprise project id
if err := setObsBucketEnterpriseProjectID(obsClient, d); err != nil {
return err
}

// Read the versioning
if err := setObsBucketVersioning(obsClient, d); err != nil {
return err
Expand Down Expand Up @@ -910,6 +923,23 @@ func setObsBucketStorageClass(obsClient *obs.ObsClient, d *schema.ResourceData)
return nil
}

func setObsBucketEnterpriseProjectID(obsClient *obs.ObsClient, d *schema.ResourceData) error {
bucket := d.Id()
input := &obs.GetBucketMetadataInput{
Bucket: bucket,
}
output, err := obsClient.GetBucketMetadata(input)
if err != nil {
return getObsError("Error getting metadata of OBS bucket", bucket, err)
}

epsId := string(output.Epid)
log.Printf("[DEBUG] getting enterprise project id of OBS bucket %s: %s", bucket, epsId)
d.Set("enterprise_project_id", epsId)

return nil
}

func setObsBucketPolicy(obsClient *obs.ObsClient, d *schema.ResourceData) error {
bucket := d.Id()
output, err := obsClient.GetBucketPolicy(bucket)
Expand Down
34 changes: 34 additions & 0 deletions huaweicloud/resource_huaweicloud_obs_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ func TestAccObsBucket_basic(t *testing.T) {
})
}

func TestAccObsBucket_withEpsId(t *testing.T) {
rInt := acctest.RandInt()
resourceName := "huaweicloud_obs_bucket.bucket"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEpsID(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckObsBucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccObsBucket_epsId(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObsBucketExists(resourceName),
resource.TestCheckResourceAttr(
resourceName, "bucket", testAccObsBucketName(rInt)),
resource.TestCheckResourceAttr(
resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID),
),
},
},
})
}

func TestAccObsBucket_tags(t *testing.T) {
rInt := acctest.RandInt()
resourceName := "huaweicloud_obs_bucket.bucket"
Expand Down Expand Up @@ -337,6 +360,17 @@ resource "huaweicloud_obs_bucket" "bucket" {
`, randInt)
}

func testAccObsBucket_epsId(randInt int) string {
return fmt.Sprintf(`
resource "huaweicloud_obs_bucket" "bucket" {
bucket = "tf-test-bucket-%d"
storage_class = "STANDARD"
acl = "private"
enterprise_project_id = "%s"
}
`, randInt, OS_ENTERPRISE_PROJECT_ID)
}

func testAccObsBucket_basic_update(randInt int) string {
return fmt.Sprintf(`
resource "huaweicloud_obs_bucket" "bucket" {
Expand Down
26 changes: 26 additions & 0 deletions huaweicloud/resource_huaweicloud_rds_instance_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func resourceRdsInstanceV3() *schema.Resource {
},
},

"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"ha_replication_mode": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -264,6 +271,7 @@ func resourceRdsInstanceV3Create(d *schema.ResourceData, meta interface{}) error

opts := resourceRdsInstanceV3UserInputParams(d)
opts["region"] = GetRegion(d, config)
opts["enterprise_project_id"] = GetEnterpriseProjectID(d, config)

arrayIndex := map[string]int{
"backup_strategy": 0,
Expand Down Expand Up @@ -559,6 +567,16 @@ func buildRdsInstanceV3CreateParameters(opts map[string]interface{}, arrayIndex
params["configuration_id"] = v
}

v, err = navigateValue(opts, []string{"enterprise_project_id"}, arrayIndex)
if err != nil {
return nil, err
}
if e, err := isEmptyValue(reflect.ValueOf(v)); err != nil {
return nil, err
} else if !e {
params["enterprise_project_id"] = v
}

v, err = expandRdsInstanceV3CreateDatastore(opts, arrayIndex)
if err != nil {
return nil, err
Expand Down Expand Up @@ -963,6 +981,14 @@ func setRdsInstanceV3Properties(d *schema.ResourceData, response map[string]inte
return fmt.Errorf("Error setting Instance:created, err: %s", err)
}

v, err = navigateValue(response, []string{"list", "enterprise_project_id"}, nil)
if err != nil {
return fmt.Errorf("Error reading Instance:enterprise_project_id, err: %s", err)
}
if err = d.Set("enterprise_project_id", v); err != nil {
return fmt.Errorf("Error setting Instance:enterprise_project_id, err: %s", err)
}

v, _ = opts["db"]
v, err = flattenRdsInstanceV3Db(response, nil, v)
if err != nil {
Expand Down
Loading

0 comments on commit 1842fb4

Please sign in to comment.