diff --git a/cloud/provider.go b/cloud/provider.go index b9515f7..53f7e8b 100644 --- a/cloud/provider.go +++ b/cloud/provider.go @@ -171,6 +171,7 @@ func init() { "rolebinding_name": "The name of rolebinding", "rolebinding_cluster_role_name": "The predefined role name", "rolebinding_service_account_names": "The list of service accounts that are role binding names ", + "dns": "The DNS ID and name. Must specify together", } } diff --git a/cloud/resource_cloud_environment.go b/cloud/resource_cloud_environment.go index 513a513..fd0f68f 100644 --- a/cloud/resource_cloud_environment.go +++ b/cloud/resource_cloud_environment.go @@ -122,6 +122,24 @@ func resourceCloudEnvironment() *schema.Resource { }, }, }, + "dns": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Description: descriptions["dns"], + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, "default_gateway": { Type: schema.TypeList, //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, zone := d.Get("zone").(string) cloudConnectionName := d.Get("cloud_connection_name").(string) network := d.Get("network").([]interface{}) + dns := d.Get("dns").([]interface{}) rawAnnotations := d.Get("annotations").(map[string]interface{}) waitForCompletion := d.Get("wait_for_completion") @@ -235,6 +254,31 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_ENVIRONMENT: " + "One of network.id or network.cidr must be set")) } + expandDns := func() error { + for _, l := range dns { + if l == nil { + continue + } + item := l.(map[string]interface{}) + + dnsId := item["id"].(string) + dnsName := item["name"].(string) + + if (dnsId != "" && dnsName == "") || (dnsId == "" && dnsName != "") { + return fmt.Errorf("ERROR_CREATE_CLOUD_ENVIRONMENT: DNS ID and name must specify together") + } + + cloudEnvironment.Spec.DNS = &cloudv1alpha1.DNS{ + ID: dnsId, + Name: dnsName, + } + } + return nil + } + if err := expandDns(); err != nil { + return diag.FromErr(err) + } + cloudEnvironment.Spec.DefaultGateway = convertGateway(d.Get("default_gateway")) ce, err := clientSet.CloudV1alpha1().CloudEnvironments(namespace).Create(ctx, cloudEnvironment, metav1.CreateOptions{ diff --git a/docs/resources/cloud_environment.md b/docs/resources/cloud_environment.md index fe9dddd..dd9a8f6 100644 --- a/docs/resources/cloud_environment.md +++ b/docs/resources/cloud_environment.md @@ -27,6 +27,7 @@ description: |- - `annotations` (Map of String) The metadata annotations of the resource - `default_gateway` (Block List) The default gateway of the cloud environment (see [below for nested schema](#nestedblock--default_gateway)) +- `dns` (Block List, Max: 1) The DNS ID and name. Must specify together (see [below for nested schema](#nestedblock--dns)) - `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) - `wait_for_completion` (Boolean) If true, will block until the status of resource has a Ready condition - `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: + +### Nested Schema for `dns` + +Required: + +- `id` (String) +- `name` (String) + + ### Nested Schema for `timeouts` diff --git a/go.mod b/go.mod index 15acfc7..d417d22 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,16 @@ go 1.21 require ( github.com/99designs/keyring v1.2.1 + github.com/google/uuid v1.6.0 github.com/hashicorp/terraform-plugin-docs v0.16.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0 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.25.2-0.20241126113204-4d08d27e3122 + github.com/streamnative/cloud-api-server v1.29.1 github.com/streamnative/cloud-cli v0.19.5 + github.com/stretchr/testify v1.9.0 github.com/xhit/go-str2duration/v2 v2.1.0 k8s.io/apimachinery v0.29.4 k8s.io/cli-runtime v0.29.4 @@ -76,7 +78,6 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/googleapis/gnostic v0.5.5 // indirect github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect @@ -150,7 +151,6 @@ require ( github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/stretchr/testify v1.9.0 // indirect github.com/stripe/stripe-go/v74 v74.5.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect diff --git a/go.sum b/go.sum index ca9fa83..9cdd2f4 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZM github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v2 v2.4.0 h1:1u/K2BFv0MwkG6he8RYuUcbbeK22rkoZbg4lKa/msZU= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v2 v2.4.0/go.mod h1:U5gpsREQZE6SLk1t/cFfc1eMhYAlYpEzvaYXuDfefy8= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice v1.0.0 h1:figxyQZXzZQIcP3njhC68bYUiTw45J8/SsHaLW8Ax0M= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice v1.0.0/go.mod h1:TmlMW4W5OvXOmOyKNnor8nlMMiO1ctIyzmHme/VHsrA= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0 h1:z4YeiSXxnUI+PqB46Yj6MZA3nwb1CcJIkEMDrzUd8Cs= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0/go.mod h1:rko9SzMxcMk0NJsNAxALEGaTYyy79bNRwxgJfrH0Spw= 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 github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/streamnative/apiserver-builder-alpha v0.0.0-20240326220620-ce0d72b3e222 h1:shRWPOZDQCtvZERDSN3sUO5HXYSpHWFfm2sSpuhMsHo= github.com/streamnative/apiserver-builder-alpha v0.0.0-20240326220620-ce0d72b3e222/go.mod h1:hM7h0lTFQ6ZyQ8YXz9SYX613ryUlW7ILbm1Jj4PgVlc= -github.com/streamnative/cloud-api-server v1.25.2-0.20241126113204-4d08d27e3122 h1:8NxYBFixXLL4/7GwP5AuBYulqblTOYg4WUt/GnDpBHg= -github.com/streamnative/cloud-api-server v1.25.2-0.20241126113204-4d08d27e3122/go.mod h1:ezloI11TvplSGQPwuRIYacs8BqnqujAFiwdsRmhqWQ0= +github.com/streamnative/cloud-api-server v1.29.1 h1:FKH+axMN0Ok9zo9emrbatJRYltTrcfPiDRkhxnd2dNE= +github.com/streamnative/cloud-api-server v1.29.1/go.mod h1:a5Xoy6PfbV8/tLr11VHLyMhPJqkdmG0yh+Cm+WyCIRA= github.com/streamnative/cloud-cli v0.19.5 h1:oCoETQ8G3tFRu/mlThPwdvMuzNWOLY5qvSSnYfTsC0s= github.com/streamnative/cloud-cli v0.19.5/go.mod h1:YeZwO9an7qp6K6PYFbho8dfWf8Xsee4NpnjVvdRZqZo= github.com/streamnative/function-mesh/api v0.0.0-20240802074023-ee53ec49a51d h1:s0BpMQcsvRBwvlOEkTB8gavWvMjLYtdjHt3+8KzmvtQ=