Skip to content

Commit

Permalink
CDPCP-11620 - include encryptionAtHost parameter for Azure environmen…
Browse files Browse the repository at this point in the history
…t creation (#93)
  • Loading branch information
gregito authored Mar 14, 2024
1 parent d685502 commit 3228495
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 4 deletions.
2 changes: 2 additions & 0 deletions resources/environments/model_azure_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type azureEnvironmentResourceModel struct {

EncryptionKeyURL types.String `tfsdk:"encryption_key_url"`

EncryptionAtHost types.Bool `tfsdk:"encryption_at_host"`

EnvironmentName types.String `tfsdk:"environment_name"`

ExistingNetworkParams types.Object `tfsdk:"existing_network_params"`
Expand Down
11 changes: 7 additions & 4 deletions resources/environments/resource_azure_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import (
"errors"
"testing"

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/cdp"
"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/client/operations"
"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/models"
mocks "github.com/cloudera/terraform-provider-cdp/mocks/github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/client/operations"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/cdp"
"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/client/operations"
"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/models"
mocks "github.com/cloudera/terraform-provider-cdp/mocks/github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/client/operations"
)

func createRawAzureEnvironmentResource() tftypes.Value {
Expand All @@ -46,6 +47,7 @@ func createRawAzureEnvironmentResource() tftypes.Value {
"credential_name": tftypes.String,
"description": tftypes.String,
"encryption_key_resource_group_name": tftypes.String,
"encryption_at_host": tftypes.Bool,
"public_key": tftypes.String,
"status": tftypes.String,
"enable_tunnel": tftypes.Bool,
Expand Down Expand Up @@ -124,6 +126,7 @@ func createRawAzureEnvironmentResource() tftypes.Value {
"credential_name": tftypes.NewValue(tftypes.String, ""),
"description": tftypes.NewValue(tftypes.String, ""),
"encryption_key_resource_group_name": tftypes.NewValue(tftypes.String, ""),
"encryption_at_host": tftypes.NewValue(tftypes.Bool, false),
"public_key": tftypes.NewValue(tftypes.String, ""),
"status": tftypes.NewValue(tftypes.String, ""),
"enable_tunnel": tftypes.NewValue(tftypes.Bool, false),
Expand Down
5 changes: 5 additions & 0 deletions resources/environments/schema_azure_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ var AzureEnvironmentSchema = schema.Schema{
"encryption_key_url": schema.StringAttribute{
Optional: true,
},
"encryption_at_host": schema.BoolAttribute{
Optional: true,
Default: booldefault.StaticBool(false),
},
"environment_name": schema.StringAttribute{
Required: true,
},
Expand Down Expand Up @@ -279,6 +283,7 @@ func ToAzureEnvironmentRequest(ctx context.Context, model *azureEnvironmentResou
req.EnvironmentName = model.EnvironmentName.ValueStringPointer()
req.EndpointAccessGatewayScheme = model.EndpointAccessGatewayScheme.ValueString()
req.EndpointAccessGatewaySubnetIds = utils.FromSetValueToStringList(model.EndpointAccessGatewaySubnetIds)
req.EncryptionAtHost = model.EncryptionAtHost.ValueBool()
if !model.ExistingNetworkParams.IsNull() && !model.ExistingNetworkParams.IsUnknown() {
tflog.Debug(ctx, "existing network params")
var existingNetworkParams existingAzureNetwork
Expand Down
214 changes: 214 additions & 0 deletions resources/environments/schema_azure_environment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// Copyright 2024 Cloudera. All Rights Reserved.
//
// This file is licensed under the Apache License Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
//
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. Refer to the License for the specific
// permissions and limitations governing your use of the file.

package environments

import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"testing"
)

var schemaElements = []SchemaTestCaseStructure{
{
name: "id field must exist and be valid",
field: "id",
computed: true,
shouldBeRequired: false,
},
{
name: "polling_options should exist and be valid",
field: "polling_options",
computed: false,
shouldBeRequired: false,
},
{
name: "crn should exist and be valid",
field: "crn",
computed: true,
shouldBeRequired: false,
},
{
name: "create_private_endpoints should exist and be valid",
field: "create_private_endpoints",
computed: false,
shouldBeRequired: false,
},
{
name: "credential_name must exist and be valid",
field: "credential_name",
computed: false,
shouldBeRequired: true,
},
{
name: "description should exist and be valid",
field: "description",
computed: true,
shouldBeRequired: false,
},
{
name: "enable_outbound_load_balancer should exist and be valid",
field: "enable_outbound_load_balancer",
computed: false,
shouldBeRequired: false,
},
{
name: "enable_tunnel should exist and be valid",
field: "enable_tunnel",
computed: true,
shouldBeRequired: false,
},
{
name: "endpoint_access_gateway_scheme should exist and be valid",
field: "endpoint_access_gateway_scheme",
computed: false,
shouldBeRequired: false,
},
{
name: "endpoint_access_gateway_subnet_ids should exist and be valid",
field: "endpoint_access_gateway_subnet_ids",
computed: false,
shouldBeRequired: false,
},
{
name: "encryption_key_resource_group_name should exist and be valid",
field: "encryption_key_resource_group_name",
computed: false,
shouldBeRequired: false,
},
{
name: "encryption_key_url should exist and be valid",
field: "encryption_key_url",
computed: false,
shouldBeRequired: false,
},
{
name: "encryption_at_host should exist and be valid",
field: "encryption_at_host",
computed: false,
shouldBeRequired: false,
},
{
name: "environment_name should exist and be valid",
field: "environment_name",
computed: false,
shouldBeRequired: true,
},
{
name: "existing_network_params should exist and be valid",
field: "existing_network_params",
computed: true,
shouldBeRequired: false,
},
{
name: "freeipa should exist and be valid",
field: "freeipa",
computed: true,
shouldBeRequired: false,
},
{
name: "log_storage should exist and be valid",
field: "log_storage",
computed: false,
shouldBeRequired: true,
},
{
name: "new_network_params should exist and be valid",
field: "new_network_params",
computed: true,
shouldBeRequired: false,
},
{
name: "proxy_config_name should exist and be valid",
field: "proxy_config_name",
computed: false,
shouldBeRequired: false,
},
{
name: "public_key should exist and be valid",
field: "public_key",
computed: false,
shouldBeRequired: true,
},
{
name: "region should exist and be valid",
field: "region",
computed: false,
shouldBeRequired: true,
},
{
name: "report_deployment_logs should exist and be valid",
field: "report_deployment_logs",
computed: true,
shouldBeRequired: false,
},
{
name: "resource_group_name should exist and be valid",
field: "resource_group_name",
computed: true,
shouldBeRequired: false,
},
{
name: "security_access should exist and be valid",
field: "security_access",
computed: false,
shouldBeRequired: true,
},
{
name: "status should exist and be valid",
field: "status",
computed: true,
shouldBeRequired: false,
},
{
name: "status_reason should exist and be valid",
field: "status_reason",
computed: true,
shouldBeRequired: false,
},
{
name: "tags should exist and be valid",
field: "tags",
computed: true,
shouldBeRequired: false,
},
{
name: "use_public_ip should exist and be valid",
field: "use_public_ip",
computed: false,
shouldBeRequired: true,
},
{
name: "workload_analytics should exist and be valid",
field: "workload_analytics",
computed: true,
shouldBeRequired: false,
},
}

func TestSchemaContainsElements(t *testing.T) {
for _, test := range schemaElements {
performValidation(t, test, AzureEnvironmentSchema.Attributes[test.field])
}
}

func performValidation(t *testing.T, test SchemaTestCaseStructure, attr schema.Attribute) {
t.Run(test.name, func(t *testing.T) {
if attr == nil {
t.Errorf("The following field does not exists, however it should: " + test.field)
t.FailNow()
}
if attr.IsRequired() != test.shouldBeRequired {
t.Errorf("The '%s' filed's >required< property should be: %t", test.field, test.shouldBeRequired)
}
if attr.IsComputed() != test.computed {
t.Errorf("The '%s' filed's >computed< property should be: %t", test.field, test.computed)
}
})
}
18 changes: 18 additions & 0 deletions resources/environments/schema_test_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 Cloudera. All Rights Reserved.
//
// This file is licensed under the Apache License Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
//
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied. Refer to the License for the specific
// permissions and limitations governing your use of the file.

package environments

type SchemaTestCaseStructure struct {
name string
field string
computed bool
shouldBeRequired bool
}

0 comments on commit 3228495

Please sign in to comment.