-
Notifications
You must be signed in to change notification settings - Fork 1
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 #12 from byteplus-sdk/Feat/organization
Feat/organization
- Loading branch information
Showing
47 changed files
with
3,184 additions
and
2 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
110 changes: 110 additions & 0 deletions
110
byteplus/organization/organization/data_source_byteplus_organizations.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,110 @@ | ||
package organization | ||
|
||
import ( | ||
bp "github.com/byteplus-sdk/terraform-provider-byteplus/common" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
) | ||
|
||
func DataSourceByteplusOrganizations() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceByteplusOrganizationsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name_regex": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringIsValidRegExp, | ||
Description: "A Name Regex of Resource.", | ||
}, | ||
"output_file": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "File name where to save data source results.", | ||
}, | ||
"total_count": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The total count of query.", | ||
}, | ||
"organizations": { | ||
Description: "The collection of query.", | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The id of the organization.", | ||
}, | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The owner id of the organization.", | ||
}, | ||
"type": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The type of the organization.", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The name of the organization.", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The description of the organization.", | ||
}, | ||
"status": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The status of the organization.", | ||
}, | ||
"delete_uk": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The delete uk of the organization.", | ||
}, | ||
"account_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The account id of the organization owner.", | ||
}, | ||
"account_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The account name of the organization owner.", | ||
}, | ||
"main_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The main name of the organization owner.", | ||
}, | ||
"created_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The created time of the organization.", | ||
}, | ||
"updated_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The updated time of the organization.", | ||
}, | ||
"deleted_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The deleted time of the organization.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceByteplusOrganizationsRead(d *schema.ResourceData, meta interface{}) error { | ||
service := NewOrganizationService(meta.(*bp.SdkClient)) | ||
return service.Dispatcher.Data(service, d, DataSourceByteplusOrganizations()) | ||
} |
125 changes: 125 additions & 0 deletions
125
byteplus/organization/organization/resource_byteplus_organization.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,125 @@ | ||
package organization | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
bp "github.com/byteplus-sdk/terraform-provider-byteplus/common" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
/* | ||
Import | ||
Organization can be imported using the id, e.g. | ||
``` | ||
$ terraform import byteplus_organization.default resource_id | ||
``` | ||
*/ | ||
|
||
func ResourceByteplusOrganization() *schema.Resource { | ||
resource := &schema.Resource{ | ||
Create: resourceByteplusOrganizationCreate, | ||
Read: resourceByteplusOrganizationRead, | ||
Delete: resourceByteplusOrganizationDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(30 * time.Minute), | ||
Delete: schema.DefaultTimeout(30 * time.Minute), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
// computed fields | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The owner id of the organization.", | ||
}, | ||
"type": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The type of the organization.", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The name of the organization.", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The description of the organization.", | ||
}, | ||
"status": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The status of the organization.", | ||
}, | ||
"delete_uk": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The delete uk of the organization.", | ||
}, | ||
"account_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The account id of the organization owner.", | ||
}, | ||
"account_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The account name of the organization owner.", | ||
}, | ||
"main_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The main name of the organization owner.", | ||
}, | ||
"created_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The created time of the organization.", | ||
}, | ||
"updated_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The updated time of the organization.", | ||
}, | ||
"deleted_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The deleted time of the organization.", | ||
}, | ||
}, | ||
} | ||
return resource | ||
} | ||
|
||
func resourceByteplusOrganizationCreate(d *schema.ResourceData, meta interface{}) (err error) { | ||
service := NewOrganizationService(meta.(*bp.SdkClient)) | ||
err = service.Dispatcher.Create(service, d, ResourceByteplusOrganization()) | ||
if err != nil { | ||
return fmt.Errorf("error on creating organization %q, %s", d.Id(), err) | ||
} | ||
return resourceByteplusOrganizationRead(d, meta) | ||
} | ||
|
||
func resourceByteplusOrganizationRead(d *schema.ResourceData, meta interface{}) (err error) { | ||
service := NewOrganizationService(meta.(*bp.SdkClient)) | ||
err = service.Dispatcher.Read(service, d, ResourceByteplusOrganization()) | ||
if err != nil { | ||
return fmt.Errorf("error on reading organization %q, %s", d.Id(), err) | ||
} | ||
return err | ||
} | ||
|
||
func resourceByteplusOrganizationDelete(d *schema.ResourceData, meta interface{}) (err error) { | ||
service := NewOrganizationService(meta.(*bp.SdkClient)) | ||
err = service.Dispatcher.Delete(service, d, ResourceByteplusOrganization()) | ||
if err != nil { | ||
return fmt.Errorf("error on deleting organization %q, %s", d.Id(), err) | ||
} | ||
return err | ||
} |
Oops, something went wrong.