Skip to content

Commit d42282e

Browse files
authored
feat: support BYOD for cloud environment (#81)
## Modifications ```diff resource "streamnative_cloud_environment" "aws_use1_test" { organization = "max" region = "us-east-1" cloud_connection_name = "shared-aws" network { cidr = "10.0.0.0/16" } + dns { + id = "CUSTOMDNSID" + name = "custom-dns.aws.snio.cloud" + } } ```
1 parent 57547f3 commit d42282e

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

cloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func init() {
171171
"rolebinding_name": "The name of rolebinding",
172172
"rolebinding_cluster_role_name": "The predefined role name",
173173
"rolebinding_service_account_names": "The list of service accounts that are role binding names ",
174+
"dns": "The DNS ID and name. Must specify together",
174175
}
175176
}
176177

cloud/resource_cloud_environment.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ func resourceCloudEnvironment() *schema.Resource {
122122
},
123123
},
124124
},
125+
"dns": {
126+
Type: schema.TypeList,
127+
Optional: true,
128+
MaxItems: 1,
129+
Description: descriptions["dns"],
130+
Elem: &schema.Resource{
131+
Schema: map[string]*schema.Schema{
132+
"id": {
133+
Type: schema.TypeString,
134+
Required: true,
135+
},
136+
"name": {
137+
Type: schema.TypeString,
138+
Required: true,
139+
},
140+
},
141+
},
142+
},
125143
"default_gateway": {
126144
Type: schema.TypeList,
127145
//Set this as optional and computed because an empty block will still create a default on the API and in the statefile
@@ -185,6 +203,7 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
185203
zone := d.Get("zone").(string)
186204
cloudConnectionName := d.Get("cloud_connection_name").(string)
187205
network := d.Get("network").([]interface{})
206+
dns := d.Get("dns").([]interface{})
188207
rawAnnotations := d.Get("annotations").(map[string]interface{})
189208
waitForCompletion := d.Get("wait_for_completion")
190209

@@ -235,6 +254,31 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
235254
return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_ENVIRONMENT: " + "One of network.id or network.cidr must be set"))
236255
}
237256

257+
expandDns := func() error {
258+
for _, l := range dns {
259+
if l == nil {
260+
continue
261+
}
262+
item := l.(map[string]interface{})
263+
264+
dnsId := item["id"].(string)
265+
dnsName := item["name"].(string)
266+
267+
if (dnsId != "" && dnsName == "") || (dnsId == "" && dnsName != "") {
268+
return fmt.Errorf("ERROR_CREATE_CLOUD_ENVIRONMENT: DNS ID and name must specify together")
269+
}
270+
271+
cloudEnvironment.Spec.DNS = &cloudv1alpha1.DNS{
272+
ID: dnsId,
273+
Name: dnsName,
274+
}
275+
}
276+
return nil
277+
}
278+
if err := expandDns(); err != nil {
279+
return diag.FromErr(err)
280+
}
281+
238282
cloudEnvironment.Spec.DefaultGateway = convertGateway(d.Get("default_gateway"))
239283

240284
ce, err := clientSet.CloudV1alpha1().CloudEnvironments(namespace).Create(ctx, cloudEnvironment, metav1.CreateOptions{

docs/resources/cloud_environment.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ description: |-
2727

2828
- `annotations` (Map of String) The metadata annotations of the resource
2929
- `default_gateway` (Block List) The default gateway of the cloud environment (see [below for nested schema](#nestedblock--default_gateway))
30+
- `dns` (Block List, Max: 1) The DNS ID and name. Must specify together (see [below for nested schema](#nestedblock--dns))
3031
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
3132
- `wait_for_completion` (Boolean) If true, will block until the status of resource has a Ready condition
3233
- `zone` (String) The zone of the cloud environment, the underlying infrastructure will only be created in this zone if configured
@@ -61,6 +62,15 @@ Optional:
6162

6263

6364

65+
<a id="nestedblock--dns"></a>
66+
### Nested Schema for `dns`
67+
68+
Required:
69+
70+
- `id` (String)
71+
- `name` (String)
72+
73+
6474
<a id="nestedblock--timeouts"></a>
6575
### Nested Schema for `timeouts`
6676

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ go 1.21
44

55
require (
66
github.com/99designs/keyring v1.2.1
7+
github.com/google/uuid v1.6.0
78
github.com/hashicorp/terraform-plugin-docs v0.16.0
89
github.com/hashicorp/terraform-plugin-log v0.9.0
910
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0
1011
github.com/lestrrat-go/jwx/v2 v2.0.21
1112
github.com/mitchellh/go-homedir v1.1.0
1213
github.com/pkg/errors v0.9.1
13-
github.com/streamnative/cloud-api-server v1.25.2-0.20241126113204-4d08d27e3122
14+
github.com/streamnative/cloud-api-server v1.29.1
1415
github.com/streamnative/cloud-cli v0.19.5
16+
github.com/stretchr/testify v1.9.0
1517
github.com/xhit/go-str2duration/v2 v2.1.0
1618
k8s.io/apimachinery v0.29.4
1719
k8s.io/cli-runtime v0.29.4
@@ -76,7 +78,6 @@ require (
7678
github.com/google/go-cmp v0.6.0 // indirect
7779
github.com/google/gofuzz v1.2.0 // indirect
7880
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
79-
github.com/google/uuid v1.6.0 // indirect
8081
github.com/googleapis/gnostic v0.5.5 // indirect
8182
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
8283
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
@@ -150,7 +151,6 @@ require (
150151
github.com/spf13/cast v1.5.0 // indirect
151152
github.com/spf13/cobra v1.7.0 // indirect
152153
github.com/spf13/pflag v1.0.5 // indirect
153-
github.com/stretchr/testify v1.9.0 // indirect
154154
github.com/stripe/stripe-go/v74 v74.5.0 // indirect
155155
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
156156
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZM
1717
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs=
1818
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs=
1919
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
20-
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v2 v2.4.0 h1:1u/K2BFv0MwkG6he8RYuUcbbeK22rkoZbg4lKa/msZU=
21-
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v2 v2.4.0/go.mod h1:U5gpsREQZE6SLk1t/cFfc1eMhYAlYpEzvaYXuDfefy8=
20+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice v1.0.0 h1:figxyQZXzZQIcP3njhC68bYUiTw45J8/SsHaLW8Ax0M=
21+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice v1.0.0/go.mod h1:TmlMW4W5OvXOmOyKNnor8nlMMiO1ctIyzmHme/VHsrA=
2222
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0 h1:z4YeiSXxnUI+PqB46Yj6MZA3nwb1CcJIkEMDrzUd8Cs=
2323
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0/go.mod h1:rko9SzMxcMk0NJsNAxALEGaTYyy79bNRwxgJfrH0Spw=
2424
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
@@ -628,8 +628,8 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y
628628
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
629629
github.com/streamnative/apiserver-builder-alpha v0.0.0-20240326220620-ce0d72b3e222 h1:shRWPOZDQCtvZERDSN3sUO5HXYSpHWFfm2sSpuhMsHo=
630630
github.com/streamnative/apiserver-builder-alpha v0.0.0-20240326220620-ce0d72b3e222/go.mod h1:hM7h0lTFQ6ZyQ8YXz9SYX613ryUlW7ILbm1Jj4PgVlc=
631-
github.com/streamnative/cloud-api-server v1.25.2-0.20241126113204-4d08d27e3122 h1:8NxYBFixXLL4/7GwP5AuBYulqblTOYg4WUt/GnDpBHg=
632-
github.com/streamnative/cloud-api-server v1.25.2-0.20241126113204-4d08d27e3122/go.mod h1:ezloI11TvplSGQPwuRIYacs8BqnqujAFiwdsRmhqWQ0=
631+
github.com/streamnative/cloud-api-server v1.29.1 h1:FKH+axMN0Ok9zo9emrbatJRYltTrcfPiDRkhxnd2dNE=
632+
github.com/streamnative/cloud-api-server v1.29.1/go.mod h1:a5Xoy6PfbV8/tLr11VHLyMhPJqkdmG0yh+Cm+WyCIRA=
633633
github.com/streamnative/cloud-cli v0.19.5 h1:oCoETQ8G3tFRu/mlThPwdvMuzNWOLY5qvSSnYfTsC0s=
634634
github.com/streamnative/cloud-cli v0.19.5/go.mod h1:YeZwO9an7qp6K6PYFbho8dfWf8Xsee4NpnjVvdRZqZo=
635635
github.com/streamnative/function-mesh/api v0.0.0-20240802074023-ee53ec49a51d h1:s0BpMQcsvRBwvlOEkTB8gavWvMjLYtdjHt3+8KzmvtQ=

0 commit comments

Comments
 (0)