Skip to content

Commit e9f85e9

Browse files
authored
CDPCP-11472 - Add support for compute cluster enabled environments (#223)
1 parent 88e194f commit e9f85e9

23 files changed

+762
-65
lines changed

deadcode-output.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/data-sources/environments_config.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ Read-Only:
216216
- `existing_network_params` (Attributes) (see [below for nested schema](#nestedatt--azure--existing_network_params))
217217
- `freeipa` (Attributes) (see [below for nested schema](#nestedatt--azure--freeipa))
218218
- `log_storage` (Attributes) (see [below for nested schema](#nestedatt--azure--log_storage))
219-
- `new_network_params` (Attributes) (see [below for nested schema](#nestedatt--azure--new_network_params))
220219
- `proxy_config_name` (String)
221220
- `public_key` (String)
222221
- `region` (String)
@@ -287,14 +286,6 @@ Read-Only:
287286
- `storage_location_base` (String)
288287

289288

290-
<a id="nestedatt--azure--new_network_params"></a>
291-
### Nested Schema for `azure.new_network_params`
292-
293-
Read-Only:
294-
295-
- `network_cidr` (String)
296-
297-
298289
<a id="nestedatt--azure--security_access"></a>
299290
### Nested Schema for `azure.security_access`
300291

docs/resources/environments_aws_environment.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "cdp_environments_aws_credential" "example" {
3131
resource "cdp_environments_aws_environment" "example" {
3232
environment_name = "example-environment"
3333
credential_name = cdp_environments_aws_credential.example.credential_name
34-
region = "us-west"
34+
region = "<your-region>"
3535
security_access = {
3636
cidr = "0.0.0.0/0"
3737
}
@@ -44,14 +44,21 @@ resource "cdp_environments_aws_environment" "example" {
4444
}
4545
vpc_id = "vpc-1"
4646
subnet_ids = [ "<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>" ]
47+
compute_cluster = {
48+
enabled = false
49+
configuration = {
50+
kube_api_authorized_ip_ranges = ["0.0.0.0/0"]
51+
worker_node_subnets = [ "<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>" ]
52+
}
53+
}
4754
}
4855
49-
output "environment_name" {
50-
value = cdp_environments_aws_environment.example.environment_name
56+
output "credential" {
57+
value = cdp_environments_aws_credential.example
5158
}
5259
53-
output "crn" {
54-
value = cdp_environments_aws_environment.example.crn
60+
output "environment" {
61+
value = cdp_environments_aws_environment.example
5562
}
5663
```
5764

@@ -72,6 +79,7 @@ output "crn" {
7279
### Optional
7380

7481
- `cascading_delete` (Boolean)
82+
- `compute_cluster` (Attributes) Option to set up Externalized compute cluster for the environment. (see [below for nested schema](#nestedatt--compute_cluster))
7583
- `create_private_subnets` (Boolean)
7684
- `create_service_endpoints` (Boolean)
7785
- `description` (String)
@@ -129,6 +137,28 @@ Optional:
129137
- `security_group_ids_for_knox` (Set of String)
130138

131139

140+
<a id="nestedatt--compute_cluster"></a>
141+
### Nested Schema for `compute_cluster`
142+
143+
Required:
144+
145+
- `enabled` (Boolean)
146+
147+
Optional:
148+
149+
- `configuration` (Attributes) The Externalized k8s configuration for the environment. (see [below for nested schema](#nestedatt--compute_cluster--configuration))
150+
151+
<a id="nestedatt--compute_cluster--configuration"></a>
152+
### Nested Schema for `compute_cluster.configuration`
153+
154+
Optional:
155+
156+
- `kube_api_authorized_ip_ranges` (Set of String) Kubernetes API authorized IP ranges in CIDR notation. Mutually exclusive with privateCluster.
157+
- `private_cluster` (Boolean) If true, creates private cluster. False, if not specified
158+
- `worker_node_subnets` (Set of String) Specify subnets for Kubernetes Worker Nodes. If not specified, then the environment's subnet(s) will be used.
159+
160+
161+
132162
<a id="nestedatt--freeipa"></a>
133163
### Nested Schema for `freeipa`
134164

docs/resources/environments_azure_environment.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ resource "cdp_environments_azure_credential" "example-cred" {
3636
resource "cdp_environments_azure_environment" "example-env" {
3737
environment_name = "example-cdp-azure-environment"
3838
credential_name = cdp_environments_azure_credential.example-cred.credential_name
39-
region = "us-west"
39+
region = "<your-region>"
4040
security_access = {
4141
cidr = "0.0.0.0/0"
4242
}
4343
existing_network_params = {
4444
network_id = "network-name"
4545
resource_group_name = "rg-name"
46-
subnet_ids = ["subnet.id"]
46+
subnet_ids = ["<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>"]
4747
}
4848
public_key = "my-key"
4949
log_storage = {
@@ -53,14 +53,23 @@ resource "cdp_environments_azure_environment" "example-env" {
5353
resource_group_name = "rg-name"
5454
encryption_user_managed_identity = "some-identity"
5555
use_public_ip = true
56+
compute_cluster = {
57+
enabled = false
58+
configuration = {
59+
private_cluster = false
60+
outbound_type = "udr"
61+
kube_api_authorized_ip_ranges = ["0.0.0.0/0"]
62+
worker_node_subnets = ["<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>"]
63+
}
64+
}
5665
}
5766
58-
output "environment_name" {
59-
value = cdp_environments_azure_environment.example-env.environment_name
67+
output "credential" {
68+
value = cdp_environments_azure_credential.example-cred
6069
}
6170
62-
output "crn" {
63-
value = cdp_environments_azure_environment.example-env.crn
71+
output "environment" {
72+
value = cdp_environments_azure_environment.example-env
6473
}
6574
```
6675

@@ -81,6 +90,7 @@ output "crn" {
8190
### Optional
8291

8392
- `cascading_delete` (Boolean)
93+
- `compute_cluster` (Attributes) Option to set up Externalized compute cluster for the environment. (see [below for nested schema](#nestedatt--compute_cluster))
8494
- `create_private_endpoints` (Boolean)
8595
- `description` (String)
8696
- `enable_outbound_load_balancer` (Boolean)
@@ -147,6 +157,29 @@ Optional:
147157
- `security_group_ids_for_knox` (Set of String)
148158

149159

160+
<a id="nestedatt--compute_cluster"></a>
161+
### Nested Schema for `compute_cluster`
162+
163+
Required:
164+
165+
- `enabled` (Boolean)
166+
167+
Optional:
168+
169+
- `configuration` (Attributes) The Externalized k8s configuration for the environment. (see [below for nested schema](#nestedatt--compute_cluster--configuration))
170+
171+
<a id="nestedatt--compute_cluster--configuration"></a>
172+
### Nested Schema for `compute_cluster.configuration`
173+
174+
Optional:
175+
176+
- `kube_api_authorized_ip_ranges` (Set of String) Kubernetes API authorized IP ranges in CIDR notation. Mutually exclusive with privateCluster.
177+
- `outbound_type` (String) Customize cluster egress with defined outbound type in Azure Kubernetes Service. Possible value(s): udr
178+
- `private_cluster` (Boolean) If true, creates private cluster. False, if not specified
179+
- `worker_node_subnets` (Set of String) Specify subnets for Kubernetes Worker Nodes. If not specified, then the environment's subnet(s) will be used.
180+
181+
182+
150183
<a id="nestedatt--freeipa"></a>
151184
### Nested Schema for `freeipa`
152185

examples/resources/cdp_environments_aws_environment/resource.tf

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ resource "cdp_environments_aws_credential" "example" {
1717
resource "cdp_environments_aws_environment" "example" {
1818
environment_name = "example-environment"
1919
credential_name = cdp_environments_aws_credential.example.credential_name
20-
region = "us-west"
20+
region = "<your-region>"
2121
security_access = {
2222
cidr = "0.0.0.0/0"
2323
}
@@ -30,12 +30,19 @@ resource "cdp_environments_aws_environment" "example" {
3030
}
3131
vpc_id = "vpc-1"
3232
subnet_ids = [ "<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>" ]
33+
compute_cluster = {
34+
enabled = false
35+
configuration = {
36+
kube_api_authorized_ip_ranges = ["0.0.0.0/0"]
37+
worker_node_subnets = [ "<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>" ]
38+
}
39+
}
3340
}
3441

35-
output "environment_name" {
36-
value = cdp_environments_aws_environment.example.environment_name
42+
output "credential" {
43+
value = cdp_environments_aws_credential.example
3744
}
3845

39-
output "crn" {
40-
value = cdp_environments_aws_environment.example.crn
41-
}
46+
output "environment" {
47+
value = cdp_environments_aws_environment.example
48+
}

examples/resources/cdp_environments_azure_environment/resource.tf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ resource "cdp_environments_azure_credential" "example-cred" {
2222
resource "cdp_environments_azure_environment" "example-env" {
2323
environment_name = "example-cdp-azure-environment"
2424
credential_name = cdp_environments_azure_credential.example-cred.credential_name
25-
region = "us-west"
25+
region = "<your-region>"
2626
security_access = {
2727
cidr = "0.0.0.0/0"
2828
}
2929
existing_network_params = {
3030
network_id = "network-name"
3131
resource_group_name = "rg-name"
32-
subnet_ids = ["subnet.id"]
32+
subnet_ids = ["<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>"]
3333
}
3434
public_key = "my-key"
3535
log_storage = {
@@ -39,12 +39,21 @@ resource "cdp_environments_azure_environment" "example-env" {
3939
resource_group_name = "rg-name"
4040
encryption_user_managed_identity = "some-identity"
4141
use_public_ip = true
42+
compute_cluster = {
43+
enabled = false
44+
configuration = {
45+
private_cluster = false
46+
outbound_type = "udr"
47+
kube_api_authorized_ip_ranges = ["0.0.0.0/0"]
48+
worker_node_subnets = ["<env-subnet-1>", "<env-subnet-2>", "<env-subnet-3>"]
49+
}
50+
}
4251
}
4352

44-
output "environment_name" {
45-
value = cdp_environments_azure_environment.example-env.environment_name
53+
output "credential" {
54+
value = cdp_environments_azure_credential.example-cred
4655
}
4756

48-
output "crn" {
49-
value = cdp_environments_azure_environment.example-env.crn
57+
output "environment" {
58+
value = cdp_environments_azure_environment.example-env
5059
}

resources/environments/model_aws_environment.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type awsEnvironmentResourceModel struct {
7272
VpcID types.String `tfsdk:"vpc_id"`
7373

7474
WorkloadAnalytics types.Bool `tfsdk:"workload_analytics"`
75+
76+
ComputeCluster *AwsComputeCluster `tfsdk:"compute_cluster"`
7577
}
7678

7779
type Authentication struct {
@@ -99,3 +101,14 @@ type SecurityAccess struct {
99101

100102
SecurityGroupIDsForKnox types.Set `tfsdk:"security_group_ids_for_knox"`
101103
}
104+
105+
type AwsComputeCluster struct {
106+
Enabled types.Bool `tfsdk:"enabled"`
107+
Configuration *AwsComputeClusterConfiguration `tfsdk:"configuration"`
108+
}
109+
110+
type AwsComputeClusterConfiguration struct {
111+
PrivateCluster types.Bool `tfsdk:"private_cluster"`
112+
KubeApiAuthorizedIpRanges types.Set `tfsdk:"kube_api_authorized_ip_ranges"`
113+
WorkerNodeSubnets types.Set `tfsdk:"worker_node_subnets"`
114+
}

resources/environments/model_azure_environment.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type azureEnvironmentResourceModel struct {
7676
EndpointAccessGatewaySubnetIds types.Set `tfsdk:"endpoint_access_gateway_subnet_ids"`
7777

7878
EncryptionUserManagedIdentity types.String `tfsdk:"encryption_user_managed_identity"`
79+
80+
ComputeCluster *AzureComputeCluster `tfsdk:"compute_cluster"`
7981
}
8082

8183
type existingAzureNetwork struct {
@@ -99,3 +101,15 @@ type azureLogStorage struct {
99101

100102
BackupStorageLocationBase types.String `tfsdk:"backup_storage_location_base"`
101103
}
104+
105+
type AzureComputeCluster struct {
106+
Enabled types.Bool `tfsdk:"enabled"`
107+
Configuration *AzureComputeClusterConfiguration `tfsdk:"configuration"`
108+
}
109+
110+
type AzureComputeClusterConfiguration struct {
111+
PrivateCluster types.Bool `tfsdk:"private_cluster"`
112+
KubeApiAuthorizedIpRanges types.Set `tfsdk:"kube_api_authorized_ip_ranges"`
113+
OutboundType types.String `tfsdk:"outbound_type"`
114+
WorkerNodeSubnets types.Set `tfsdk:"worker_node_subnets"`
115+
}

resources/environments/polling.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func waitForEnvironmentToBeAvailable(environmentName string, fallbackTimeout tim
113113
"ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_IN_PROGRESS",
114114
"ENVIRONMENT_VALIDATION_IN_PROGRESS",
115115
"ENVIRONMENT_INITIALIZATION_IN_PROGRESS",
116+
"COMPUTE_CLUSTER_CREATION_IN_PROGRESS",
116117
"FREEIPA_CREATION_IN_PROGRESS"},
117118
Target: []string{"AVAILABLE"},
118119
Delay: 5 * time.Second,

resources/environments/resource_aws_environment.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ func (r *awsEnvironmentResource) Create(ctx context.Context, req resource.Create
100100
}
101101

102102
toAwsEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, descEnvResp, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics)
103+
diags = initiateComputeClustersForAwsAfterEnvCreationAndWait(ctx, data, r, resp, diags, client)
104+
103105
diags = resp.State.Set(ctx, data)
104106
resp.Diagnostics.Append(diags...)
105107
if resp.Diagnostics.HasError() {
@@ -132,7 +134,26 @@ func (r *awsEnvironmentResource) Read(ctx context.Context, req resource.ReadRequ
132134
}
133135
}
134136

135-
func (r *awsEnvironmentResource) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) {
137+
func (r *awsEnvironmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
138+
var plan awsEnvironmentResourceModel
139+
var state awsEnvironmentResourceModel
140+
planDiags := req.Plan.Get(ctx, &plan)
141+
var stateDiags = req.State.Get(ctx, &state)
142+
resp.Diagnostics.Append(planDiags...)
143+
resp.Diagnostics.Append(stateDiags...)
144+
if resp.Diagnostics.HasError() {
145+
tflog.Error(ctx, "Got Error while trying to set plan")
146+
return
147+
}
148+
149+
updateAwsEnvironment(ctx, &plan, &state, r.client.Environments, resp)
150+
151+
stateDiags = resp.State.Set(ctx, state)
152+
resp.Diagnostics.Append(stateDiags...)
153+
if resp.Diagnostics.HasError() {
154+
return
155+
}
156+
resp.State.Set(ctx, state)
136157
}
137158

138159
func (r *awsEnvironmentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {

resources/environments/resource_azure_environment.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func (r *azureEnvironmentResource) Create(ctx context.Context, req resource.Crea
101101
}
102102

103103
toAzureEnvironmentResource(ctx, descEnvResp, &data, data.PollingOptions, &resp.Diagnostics)
104+
diags = initiateComputeClustersForAzureAfterEnvCreationAndWait(ctx, data, r, resp, diags, client)
105+
104106
diags = resp.State.Set(ctx, data)
105107
resp.Diagnostics.Append(diags...)
106108
if resp.Diagnostics.HasError() {
@@ -233,8 +235,26 @@ func toAzureEnvironmentResource(ctx context.Context, env *environmentsmodels.Env
233235
model.WorkloadAnalytics = types.BoolValue(env.WorkloadAnalytics)
234236
}
235237

236-
func (r *azureEnvironmentResource) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) {
238+
func (r *azureEnvironmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
239+
var plan azureEnvironmentResourceModel
240+
var state azureEnvironmentResourceModel
241+
planDiags := req.Plan.Get(ctx, &plan)
242+
var stateDiags = req.State.Get(ctx, &state)
243+
resp.Diagnostics.Append(planDiags...)
244+
resp.Diagnostics.Append(stateDiags...)
245+
if resp.Diagnostics.HasError() {
246+
tflog.Error(ctx, "Got Error while trying to set plan")
247+
return
248+
}
249+
250+
updateAzureEnvironment(ctx, &plan, &state, r.client.Environments, resp)
237251

252+
stateDiags = resp.State.Set(ctx, state)
253+
resp.Diagnostics.Append(stateDiags...)
254+
if resp.Diagnostics.HasError() {
255+
return
256+
}
257+
resp.State.Set(ctx, state)
238258
}
239259

240260
func (r *azureEnvironmentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {

0 commit comments

Comments
 (0)