diff --git a/docs/resources/private_endpoint.md b/docs/resources/private_endpoint.md index 2fbd2c2..d97768f 100644 --- a/docs/resources/private_endpoint.md +++ b/docs/resources/private_endpoint.md @@ -93,6 +93,7 @@ resource "oasis_private_endpoint" "my_aws_private_endpoint" { name = "tf-private-endpoint-test" description = "Terraform generated AWS private endpoint" deployment = oasis_deployment.my_aws_oneshard_deployment.id + enable_private_dns = true dns_names = ["test.example.com", "test2.example.com"] aws { principal { @@ -117,6 +118,7 @@ resource "oasis_private_endpoint" "my_aws_private_endpoint" { - `aks` (Block List, Max: 1) Private Endpoint Resource Private Endpoint AKS field (see [below for nested schema](#nestedblock--aks)) - `aws` (Block List, Max: 1) Private Endpoint Resource Private Endpoint AWS field (see [below for nested schema](#nestedblock--aws)) - `description` (String) Private Endpoint Resource Private Endpoint Description field +- `enable_private_dns` (Bool) If set, private DNS zone integration is enabled for this private endpoint service. For GCP this bool is immutable, so can only be set during the creation. For AKS this boolean cannot be set. - `dns_names` (List of String) Private Endpoint Resource Private Endpoint DNS Names field (list of dns names) - `gcp` (Block List, Max: 1) Private Endpoint Resource Private Endpoint GCP field (see [below for nested schema](#nestedblock--gcp)) diff --git a/internal/resource_private_endpoint.go b/internal/resource_private_endpoint.go index c4ff2f2..6b982b8 100644 --- a/internal/resource_private_endpoint.go +++ b/internal/resource_private_endpoint.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2022-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,10 +33,11 @@ import ( const ( // Private Endpoint field names - privateEndpointNameFieldName = "name" - privateEndpointDescriptionFieldName = "description" - privateEndpointDeploymentFieldName = "deployment" - privateEndpointDNSNamesFieldName = "dns_names" + privateEndpointNameFieldName = "name" + privateEndpointDescriptionFieldName = "description" + privateEndpointDeploymentFieldName = "deployment" + prirvateEndpointEnablePrivateDNSFieldName = "enable_private_dns" + privateEndpointDNSNamesFieldName = "dns_names" // AKS field names privateEndpointAKSFieldName = "aks" @@ -79,6 +80,11 @@ func resourcePrivateEndpoint() *schema.Resource { Description: "Private Endpoint Resource Private Endpoint Deployment ID field", Required: true, }, + prirvateEndpointEnablePrivateDNSFieldName: { + Type: schema.TypeBool, + Description: "Private Endpoint Resource Private Endpoint Enable Private DNS field", + Optional: true, + }, privateEndpointDNSNamesFieldName: { Type: schema.TypeList, Description: "Private Endpoint Resource Private Endpoint DNS Names field (list of dns names)", @@ -200,13 +206,14 @@ func resourcePrivateEndpointRead(ctx context.Context, d *schema.ResourceData, m // flattenPrivateEndpointResource will take a Private Endpoint object and turn it into a flat map for terraform digestion. func flattenPrivateEndpointResource(privateEndpoint *network.PrivateEndpointService) map[string]interface{} { return map[string]interface{}{ - privateEndpointNameFieldName: privateEndpoint.GetName(), - privateEndpointDescriptionFieldName: privateEndpoint.GetDescription(), - privateEndpointDeploymentFieldName: privateEndpoint.GetDeploymentId(), - privateEndpointDNSNamesFieldName: privateEndpoint.GetAlternateDnsNames(), - privateEndpointAKSFieldName: flattenAKSResource(privateEndpoint.GetAks()), - privateEndpointAWSFieldName: flattenAWSResource(privateEndpoint.GetAws()), - privateEndpointGCPFieldName: flattenGCPResource(privateEndpoint.GetGcp()), + privateEndpointNameFieldName: privateEndpoint.GetName(), + privateEndpointDescriptionFieldName: privateEndpoint.GetDescription(), + privateEndpointDeploymentFieldName: privateEndpoint.GetDeploymentId(), + prirvateEndpointEnablePrivateDNSFieldName: privateEndpoint.GetEnablePrivateDns(), + privateEndpointDNSNamesFieldName: privateEndpoint.GetAlternateDnsNames(), + privateEndpointAKSFieldName: flattenAKSResource(privateEndpoint.GetAks()), + privateEndpointAWSFieldName: flattenAWSResource(privateEndpoint.GetAws()), + privateEndpointGCPFieldName: flattenGCPResource(privateEndpoint.GetGcp()), } } @@ -308,6 +315,9 @@ func expandPrivateEndpointResource(d *schema.ResourceData) (*network.PrivateEndp } else { return nil, fmt.Errorf("unable to find parse field %s", privateEndpointDeploymentFieldName) } + if v, ok := d.GetOk(prirvateEndpointEnablePrivateDNSFieldName); ok { + ret.EnablePrivateDns = v.(bool) + } if v, ok := d.GetOk(privateEndpointDNSNamesFieldName); ok { dnsNames, err := expandPrivateEndpointStringList(v.([]interface{})) if err != nil { @@ -455,6 +465,9 @@ func resourcePrivateEndpointUpdate(ctx context.Context, d *schema.ResourceData, if d.HasChange(privateEndpointDescriptionFieldName) { privateEndpoint.Description = d.Get(privateEndpointDescriptionFieldName).(string) } + if d.HasChange(prirvateEndpointEnablePrivateDNSFieldName) { + privateEndpoint.EnablePrivateDns = d.Get(prirvateEndpointEnablePrivateDNSFieldName).(bool) + } if d.HasChange(privateEndpointDNSNamesFieldName) { dnsNames, err := expandPrivateEndpointStringList(d.Get(privateEndpointDNSNamesFieldName).([]interface{})) if err != nil { diff --git a/internal/resource_private_endpoint_test.go b/internal/resource_private_endpoint_test.go index 2ad7ac1..718d6ef 100644 --- a/internal/resource_private_endpoint_test.go +++ b/internal/resource_private_endpoint_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2022-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -92,14 +92,16 @@ func TestFlattenPrivateEndpoint(t *testing.T) { Name: "test-private-endpoint", Description: "test-description", DeploymentId: deploymentId, + EnablePrivateDns: true, AlternateDnsNames: []string{"test.example.com"}, } expected := map[string]interface{}{ - privateEndpointNameFieldName: "test-private-endpoint", - privateEndpointDescriptionFieldName: "test-description", - privateEndpointDeploymentFieldName: deploymentId, - privateEndpointDNSNamesFieldName: []string{"test.example.com"}, + privateEndpointNameFieldName: "test-private-endpoint", + privateEndpointDescriptionFieldName: "test-description", + privateEndpointDeploymentFieldName: deploymentId, + prirvateEndpointEnablePrivateDNSFieldName: true, + privateEndpointDNSNamesFieldName: []string{"test.example.com"}, } t.Run("flattening with aks field", func(tt *testing.T) {