Skip to content

Commit

Permalink
Merge pull request #90 from arangodb-managed/OAS-8726
Browse files Browse the repository at this point in the history
OAS-8725 | add enable-private-dns setting
  • Loading branch information
Robert-Stam authored Nov 22, 2023
2 parents ccd0518 + 00cae87 commit cdec05c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/resources/private_endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))

Expand Down
37 changes: 25 additions & 12 deletions internal/resource_private_endpoint.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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()),
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions internal/resource_private_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cdec05c

Please sign in to comment.