Skip to content

Commit

Permalink
Add st-alicloud_service_mesh_user_permission resource. (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
chihong99 authored Jan 12, 2024
1 parent 262ad8d commit 0824242
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 22 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ scenario. The reason behind every resources and data sources are stated as below
This resource is designed to attach a list of clusters' kubernetes role permissions (CS) with a (RAM) user, and to replace the official Alicloud Terraform Provider's resource [*alicloud_cs_kubernetes_permissions*](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_kubernetes_permissions).
The official resource will overwrite all the permissions which is attached with the user, which means it will remove the permissions from other clusters.
- **st-alicloud_service_mesh_user_permission**
This resource is designed to attach a list of ASM clusters' permissions with a (RAM) user, and to replace the official Alicloud Terraform Provider's resource [*alicloud_service_mesh_user_permission*](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/service_mesh_user_permission).
The official resource will overwrite all the permissions which is attached with the user, which means it will remove the permissions from other ASM clusters.
### Data Sources
- **st-alicloud_ddoscoo_domain_resources**
Expand Down
63 changes: 41 additions & 22 deletions alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@ import (
alicloudRamClient "github.com/alibabacloud-go/ram-20150501/v2/client"
alicloudSlbClient "github.com/alibabacloud-go/slb-20140515/v4/client"
alicloudEssClient "github.com/alibabacloud-go/ess-20220222/v2/client"
alicloudServicemeshClient "github.com/alibabacloud-go/servicemesh-20200111/v4/client"

"github.com/alibabacloud-go/tea/tea"
)

// Wrapper of AliCloud client
type alicloudClients struct {
baseClient *alicloudBaseClient.Client
cdnClient *alicloudCdnClient.Client
antiddosClient *alicloudAntiddosClient.Client
slbClient *alicloudSlbClient.Client
dnsClient *alicloudDnsClient.Client
ramClient *alicloudRamClient.Client
cmsClient *alicloudCmsClient.Client
adbClient *alicloudAdbClient.Client
emrClient *alicloudEmrClient.Client
csClient *alicloudCsClient.Client
essClient *alicloudEssClient.Client
baseClient *alicloudBaseClient.Client
cdnClient *alicloudCdnClient.Client
antiddosClient *alicloudAntiddosClient.Client
slbClient *alicloudSlbClient.Client
dnsClient *alicloudDnsClient.Client
ramClient *alicloudRamClient.Client
cmsClient *alicloudCmsClient.Client
adbClient *alicloudAdbClient.Client
emrClient *alicloudEmrClient.Client
csClient *alicloudCsClient.Client
essClient *alicloudEssClient.Client
servicemeshClient *alicloudServicemeshClient.Client
}

// Ensure the implementation satisfies the expected interfaces
Expand Down Expand Up @@ -358,19 +360,35 @@ func (p *alicloudProvider) Configure(ctx context.Context, req provider.Configure
return
}

// AliCloud Servicemesh Client
servicemeshClientConfig := clientCredentialsConfig
servicemeshClientConfig.Endpoint = tea.String("servicemesh.aliyuncs.com")
servicemeshClient, err := alicloudServicemeshClient.NewClient(servicemeshClientConfig)

if err != nil {
resp.Diagnostics.AddError(
"Unable to Create AliCloud Servicemesh API Client",
"An unexpected error occurred when creating the AliCloud Servicemesh API client. "+
"If the error is not clear, please contact the provider developers.\n\n"+
"AliCloud Servicemesh Client Error: "+err.Error(),
)
return
}

// AliCloud clients wrapper
alicloudClients := alicloudClients{
baseClient: baseClient,
cdnClient: cdnClient,
antiddosClient: antiddosClient,
slbClient: slbClient,
dnsClient: dnsClient,
ramClient: ramClient,
cmsClient: cmsClient,
adbClient: adbClient,
emrClient: emrClient,
csClient: csClient,
essClient: essClient,
baseClient: baseClient,
cdnClient: cdnClient,
antiddosClient: antiddosClient,
slbClient: slbClient,
dnsClient: dnsClient,
ramClient: ramClient,
cmsClient: cmsClient,
adbClient: adbClient,
emrClient: emrClient,
csClient: csClient,
essClient: essClient,
servicemeshClient: servicemeshClient,
}

resp.DataSourceData = alicloudClients
Expand Down Expand Up @@ -403,5 +421,6 @@ func (p *alicloudProvider) Resources(_ context.Context) []func() resource.Resour
NewDdosCooWebAIProtectConfigResource,
NewEssClbDefaultServerGroupAttachmentResource,
NewCsKubernetesPermissionsResource,
NewServicemeshUserPermissionResource,
}
}
Loading

0 comments on commit 0824242

Please sign in to comment.