Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cloud/cloud_connection_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ func flattenCloudConnectionAzure(in *cloudv1alpha1.AzureConnection) []interface{

return []interface{}{att}
}

func flattenCloudConnectionAliCloud(in *cloudv1alpha1.AliCloudConnection) []interface{} {
att := make(map[string]interface{})
if in.AccountId != "" {
att["account_id"] = in.AccountId
}

return []interface{}{att}
}
23 changes: 22 additions & 1 deletion cloud/data_source_cloud_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package cloud
import (
"context"
"fmt"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"strings"

apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -108,6 +109,19 @@ func dataSourceCloudConnection() *schema.Resource {
},
},
},
"alicloud": {
Type: schema.TypeList,
Computed: true,
Description: descriptions["alicloud"],
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -153,6 +167,13 @@ func dataSourceCloudConnectionRead(ctx context.Context, d *schema.ResourceData,
}
}

if cloudConnection.Spec.AliCloud != nil {
err = d.Set("alicloud", flattenCloudConnectionAliCloud(cloudConnection.Spec.AliCloud))
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_READ_CLOUD_CONNECTION_CONFIG: %w", err))
}
}

d.SetId(fmt.Sprintf("%s/%s", cloudConnection.Namespace, cloudConnection.Name))

return nil
Expand Down
3 changes: 2 additions & 1 deletion cloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ func init() {
"use this websocket service url. There'll be multiple service urls if the cluster attached with multiple gateways",
"pulsar_version": "The version of the pulsar cluster",
"bookkeeper_version": "The version of the bookkeeper cluster",
"type": "Type of cloud connection, one of aws or gcp",
"type": "Type of cloud connection, one of aws, gcp, azure or alicloud",
"aws": "AWS configuration for the connection",
"gcp": "GCP configuration for the connection",
"azure": "Azure configuration for the connection",
"alicloud": "Alicloud configuration for the connection",
"cloud_connection_name": "Name of the cloud connection",
"environment_type": "Type of the cloud environment, either: dev, test, staging, production, acc, qa or poc",
"cloud_environment_name": "Name of the cloud environment",
Expand Down
37 changes: 35 additions & 2 deletions cloud/resource_cloud_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ func resourceCloudConnection() *schema.Resource {
},
},
},
"alicloud": {
Type: schema.TypeList,
Optional: true,
Description: descriptions["alicloud"],
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}
}
Expand All @@ -144,6 +157,7 @@ func resourceCloudConnectionCreate(ctx context.Context, d *schema.ResourceData,
aws := d.Get("aws").([]interface{})
gcp := d.Get("gcp").([]interface{})
azure := d.Get("azure").([]interface{})
alicloud := d.Get("alicloud").([]interface{})
clientSet, err := getClientSet(getFactoryFromMeta(meta))
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_CLOUD_CONNECTION: %w", err))
Expand All @@ -164,6 +178,7 @@ func resourceCloudConnectionCreate(ctx context.Context, d *schema.ResourceData,
AWS: nil,
GCP: nil,
Azure: nil,
AliCloud: nil,
},
}

Expand Down Expand Up @@ -208,8 +223,19 @@ func resourceCloudConnectionCreate(ctx context.Context, d *schema.ResourceData,
}
}

if cloudConnection.Spec.AWS == nil && cloudConnection.Spec.GCP == nil && cloudConnection.Spec.Azure == nil {
return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_CONNECTION: " + "One of aws.account_id, gcp.project_id or azure block must be set"))
if len(alicloud) > 0 {
cloudConnection.Spec.AliCloud = &cloudv1alpha1.AliCloudConnection{}
for _, alicloudItem := range alicloud {
alicloudItemMap := alicloudItem.(map[string]interface{})
if alicloudItemMap["account_id"] != nil {
accountId := alicloudItemMap["account_id"].(string)
cloudConnection.Spec.AliCloud.AccountId = accountId
}
}
}

if cloudConnection.Spec.AWS == nil && cloudConnection.Spec.GCP == nil && cloudConnection.Spec.Azure == nil && cloudConnection.Spec.AliCloud == nil {
return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_CONNECTION: " + "One of aws.account_id, gcp.project_id, azure block or alicloud.account_id must be set"))
}

cc, err := clientSet.CloudV1alpha1().CloudConnections(namespace).Create(ctx, cloudConnection, metav1.CreateOptions{
Expand Down Expand Up @@ -281,6 +307,13 @@ func resourceCloudConnectionRead(ctx context.Context, d *schema.ResourceData, me
}
}

if cloudConnection.Spec.AliCloud != nil {
err = d.Set("alicloud", flattenCloudConnectionAliCloud(cloudConnection.Spec.AliCloud))
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_READ_CLOUD_CONNECTION_ALICLOUD: %w", err))
}
}

d.SetId(fmt.Sprintf("%s/%s", cloudConnection.Namespace, cloudConnection.Name))
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/lestrrat-go/jwx/v2 v2.0.21
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/streamnative/cloud-api-server v1.35.2
github.com/streamnative/cloud-api-server v1.36.1
github.com/streamnative/cloud-cli v0.22.0-rc.1
github.com/stretchr/testify v1.10.0
github.com/xhit/go-str2duration/v2 v2.1.0
Expand Down
36 changes: 34 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMb
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/99designs/keyring v1.2.1 h1:tYLp1ULvO7i3fI5vE21ReQuj99QFSs7lGm0xWyJo87o=
github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/AliyunContainerService/ack-ram-tool v0.19.0 h1:30TON3d0zOFxHJb9HmUC91FEBciBJ1xt09YJ1yv1EyA=
github.com/AliyunContainerService/ack-ram-tool v0.19.0/go.mod h1:4kb+Z8e6eCyqZtosQpj+etrIJOKxOyzcbYhNX+D37Y8=
github.com/AthenZ/athenz v1.10.39 h1:mtwHTF/v62ewY2Z5KWhuZgVXftBej1/Tn80zx4DcawY=
github.com/AthenZ/athenz v1.10.39/go.mod h1:3Tg8HLsiQZp81BJY58JBeU2BR6B/H4/0MQGfCwhHNEA=
github.com/Azure/azure-sdk-for-go v56.2.0+incompatible h1:2GrG1JkTSMqLquy1pqVsjeRJhNtZLjss2+rx8ogZXx4=
Expand Down Expand Up @@ -660,6 +662,30 @@ github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM=
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 h1:zE8vH9C7JiZLNJJQ5OwjU9mSi4T9ef9u3BURT6LCLC8=
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5/go.mod h1:tWnyE9AjF8J8qqLk645oUmVUnFybApTQWklQmi5tY6g=
github.com/alibabacloud-go/cs-20151215/v5 v5.9.2 h1:8M4EgqDxGrTmUzH1EmF3QchTqEjujn1dim1r7gxYDDU=
github.com/alibabacloud-go/cs-20151215/v5 v5.9.2/go.mod h1:upN5yBSmZGGM0RZc2OzS3hIVc4mtHdjA7IaE0QqdtYQ=
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.11 h1:GkVQ9AphMCmgAYakcTpH/OuFz0mQUypO/JiOvo0wgVA=
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.11/go.mod h1:wHxkgZT1ClZdcwEVP/pDgYK/9HucsnCfMipmJgCz4xY=
github.com/alibabacloud-go/debug v1.0.1 h1:MsW9SmUtbb1Fnt3ieC6NNZi6aEwrXfDksD4QA6GSbPg=
github.com/alibabacloud-go/debug v1.0.1/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
github.com/alibabacloud-go/openapi-util v0.1.1 h1:ujGErJjG8ncRW6XtBBMphzHTvCxn4DjrVw4m04HsS28=
github.com/alibabacloud-go/openapi-util v0.1.1/go.mod h1:/UehBSE2cf1gYT43GV4E+RxTdLRzURImCYY0aRmlXpw=
github.com/alibabacloud-go/sts-20150401/v2 v2.0.3 h1:RQRmj1BZUwWKrejdTI4+W8IIW7roju1AAxMTF8ZJ8Ik=
github.com/alibabacloud-go/sts-20150401/v2 v2.0.3/go.mod h1:A0TGi5oeSYGs2xhWnqjDeCkPc+uJCRQzkjriekg/KoQ=
github.com/alibabacloud-go/tea v1.3.8 h1:Sk2+BDJC//xJ1/Eljf+Dlg2u2tgWpA9P7mlb87AEcEs=
github.com/alibabacloud-go/tea v1.3.8/go.mod h1:A560v/JTQ1n5zklt2BEpurJzZTI8TUT+Psg2drWlxRg=
github.com/alibabacloud-go/tea-utils v1.4.5 h1:h0/6Xd2f3bPE4XHTvkpjwxowIwRCJAJOqY6Eq8f3zfA=
github.com/alibabacloud-go/tea-utils v1.4.5/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw=
github.com/alibabacloud-go/tea-utils/v2 v2.0.7 h1:WDx5qW3Xa5ZgJ1c8NfqJkF6w+AU5wB8835UdhPr6Ax0=
github.com/alibabacloud-go/tea-utils/v2 v2.0.7/go.mod h1:qxn986l+q33J5VkialKMqT/TTs3E+U9MJpd001iWQ9I=
github.com/alibabacloud-go/tea-xml v1.1.3 h1:7LYnm+JbOq2B+T/B0fHC4Ies4/FofC4zHzYtqw7dgt0=
github.com/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
github.com/aliyun/credentials-go v1.4.5 h1:O76WYKgdy1oQYYiJkERjlA2dxGuvLRrzuO2ScrtGWSk=
github.com/aliyun/credentials-go v1.4.5/go.mod h1:Jm6d+xIgwJVLVWT561vy67ZRP4lPTQxMbEYRuT2Ti1U=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
Expand Down Expand Up @@ -710,6 +736,8 @@ github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHe
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
Expand Down Expand Up @@ -1289,8 +1317,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/streamnative/cloud-api-server v1.35.2 h1:Ge+ZSRwsCdgc+u+IzYNLLZwhzz88d6ZhHuvCRO6+47Q=
github.com/streamnative/cloud-api-server v1.35.2/go.mod h1:Sg+u83FA3elLyvzjmYjwuf8OjEDUaPqIxS11badeqtw=
github.com/streamnative/cloud-api-server v1.36.1 h1:mbZyWDFk0kWFlECFl8kI56bF2UzrjLLnBnd3Car+638=
github.com/streamnative/cloud-api-server v1.36.1/go.mod h1:R1+Y5EXsKtbWmJ0D1/G9tYO2TwOMmQ3lJfyNL0Ze9To=
github.com/streamnative/cloud-cli v0.22.0-rc.1 h1:I1CHsQf4joFNnDvNwwW60W9c2VcJnRuNPBMxTdEf6N8=
github.com/streamnative/cloud-cli v0.22.0-rc.1/go.mod h1:LocRogsIAggk1yso5WX0ucYuaYt8GwXvrOzWjHzdNN8=
github.com/streamnative/function-mesh/api v0.0.0-20240802074023-ee53ec49a51d h1:s0BpMQcsvRBwvlOEkTB8gavWvMjLYtdjHt3+8KzmvtQ=
Expand Down Expand Up @@ -1328,6 +1356,8 @@ github.com/stripe/stripe-go/v74 v74.5.0 h1:YyqTvVQdS34KYGCfVB87EMn9eDV3FCFkSwfdO
github.com/stripe/stripe-go/v74 v74.5.0/go.mod h1:5PoXNp30AJ3tGq57ZcFuaMylzNi8KpwlrYAFmO1fHZw=
github.com/testcontainers/testcontainers-go v0.32.0 h1:ug1aK08L3gCHdhknlTTwWjPHPS+/alvLJU/DRxTD/ME=
github.com/testcontainers/testcontainers-go v0.32.0/go.mod h1:CRHrzHLQhlXUsa5gXjTOfqIEJcrK5+xMDmBr/WMI88E=
github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho=
github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
Expand Down Expand Up @@ -2029,6 +2059,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
Expand Down