Skip to content

Commit 93c7afe

Browse files
authored
feat(SKE): support for DNS extension (#492)
* Feat(SKE): support DNS extension * generate docs * fix attributes required/optional * add comment to acceptance test DNS zones * regenerate docs * fix typos * generate docs
1 parent aface95 commit 93c7afe

11 files changed

Lines changed: 198 additions & 18 deletions

File tree

docs/data-sources/mongodbflex_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data "stackit_mongodbflex_instance" "example" {
3232
- `acl` (List of String) The Access Control List (ACL) for the MongoDB Flex instance.
3333
- `backup_schedule` (String) The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").
3434
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
35-
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`instance_id`".
35+
- `id` (String) Terraform's internal data source ID. It is structured as "`project_id`,`instance_id`".
3636
- `name` (String) Instance name.
3737
- `options` (Attributes) Custom parameters for the MongoDB Flex instance. (see [below for nested schema](#nestedatt--options))
3838
- `replicas` (Number)

docs/data-sources/postgresql_credential.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "stackit_postgresql_credential Data Source - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL credential data source schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_user instead. For more details, check
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_user instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
88
---
99

1010
# stackit_postgresql_credential (Data Source)

docs/data-sources/postgresql_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "stackit_postgresql_instance Data Source - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL instance data source schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. For more details, check
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
88
---
99

1010
# stackit_postgresql_instance (Data Source)

docs/data-sources/ske_cluster.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Read-Only:
5050

5151
- `acl` (Attributes) Cluster access control configuration (see [below for nested schema](#nestedatt--extensions--acl))
5252
- `argus` (Attributes) A single argus block as defined below (see [below for nested schema](#nestedatt--extensions--argus))
53+
- `dns` (Attributes) DNS extension configuration (see [below for nested schema](#nestedatt--extensions--dns))
5354

5455
<a id="nestedatt--extensions--acl"></a>
5556
### Nested Schema for `extensions.acl`
@@ -69,6 +70,15 @@ Read-Only:
6970
- `enabled` (Boolean) Flag to enable/disable argus extensions.
7071

7172

73+
<a id="nestedatt--extensions--dns"></a>
74+
### Nested Schema for `extensions.dns`
75+
76+
Read-Only:
77+
78+
- `enabled` (Boolean) Flag to enable/disable DNS extensions
79+
- `zones` (List of String) Specify a list of domain filters for externalDNS (e.g., `foo.runs.onstackit.cloud`)
80+
81+
7282

7383
<a id="nestedatt--hibernations"></a>
7484
### Nested Schema for `hibernations`

docs/resources/postgresql_credential.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "stackit_postgresql_credential Resource - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL credential resource schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_user instead. For more details, check
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_user instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
88
---
99

1010
# stackit_postgresql_credential (Resource)

docs/resources/postgresql_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "stackit_postgresql_instance Resource - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL instance resource schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. Check on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an "import" block ()
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. Check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an "import" block (https://developer.hashicorp.com/terraform/language/import)
88
---
99

1010
# stackit_postgresql_instance (Resource)

docs/resources/ske_cluster.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,36 @@ Optional:
115115

116116
- `acl` (Attributes) Cluster access control configuration. (see [below for nested schema](#nestedatt--extensions--acl))
117117
- `argus` (Attributes) A single argus block as defined below. (see [below for nested schema](#nestedatt--extensions--argus))
118+
- `dns` (Attributes) DNS extension configuration (see [below for nested schema](#nestedatt--extensions--dns))
118119

119120
<a id="nestedatt--extensions--acl"></a>
120121
### Nested Schema for `extensions.acl`
121122

122123
Required:
123124

124-
- `enabled` (Boolean) Is ACL enabled?
125-
126-
Optional:
127-
128125
- `allowed_cidrs` (List of String) Specify a list of CIDRs to whitelist.
126+
- `enabled` (Boolean) Is ACL enabled?
129127

130128

131129
<a id="nestedatt--extensions--argus"></a>
132130
### Nested Schema for `extensions.argus`
133131

134132
Required:
135133

134+
- `argus_instance_id` (String) Argus instance ID to choose which Argus instance is used. Required when enabled is set to `true`.
136135
- `enabled` (Boolean) Flag to enable/disable Argus extensions.
137136

137+
138+
<a id="nestedatt--extensions--dns"></a>
139+
### Nested Schema for `extensions.dns`
140+
141+
Required:
142+
143+
- `enabled` (Boolean) Flag to enable/disable DNS extensions
144+
138145
Optional:
139146

140-
- `argus_instance_id` (String) Argus instance ID to choose which Argus instance is used. Required when enabled is set to `true`.
147+
- `zones` (List of String) Specify a list of domain filters for externalDNS (e.g., `foo.runs.onstackit.cloud`)
141148

142149

143150

stackit/internal/services/ske/cluster/datasource.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,21 @@ func (r *clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
296296
},
297297
},
298298
},
299+
"dns": schema.SingleNestedAttribute{
300+
Description: "DNS extension configuration",
301+
Computed: true,
302+
Attributes: map[string]schema.Attribute{
303+
"enabled": schema.BoolAttribute{
304+
Description: "Flag to enable/disable DNS extensions",
305+
Computed: true,
306+
},
307+
"zones": schema.ListAttribute{
308+
Description: "Specify a list of domain filters for externalDNS (e.g., `foo.runs.onstackit.cloud`)",
309+
Computed: true,
310+
ElementType: types.StringType,
311+
},
312+
},
313+
},
299314
},
300315
},
301316
"kube_config": schema.StringAttribute{

stackit/internal/services/ske/cluster/resource.go

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ var hibernationTypes = map[string]attr.Type{
178178
type extensions struct {
179179
Argus types.Object `tfsdk:"argus"`
180180
ACL types.Object `tfsdk:"acl"`
181+
DNS types.Object `tfsdk:"dns"`
181182
}
182183

183184
// Types corresponding to extensions
184185
var extensionsTypes = map[string]attr.Type{
185186
"argus": basetypes.ObjectType{AttrTypes: argusTypes},
186187
"acl": basetypes.ObjectType{AttrTypes: aclTypes},
188+
"dns": basetypes.ObjectType{AttrTypes: dnsTypes},
187189
}
188190

189191
// Struct corresponding to extensions.ACL
@@ -210,6 +212,18 @@ var argusTypes = map[string]attr.Type{
210212
"argus_instance_id": basetypes.StringType{},
211213
}
212214

215+
// Struct corresponding to extensions.DNS
216+
type dns struct {
217+
Enabled types.Bool `tfsdk:"enabled"`
218+
Zones types.List `tfsdk:"zones"`
219+
}
220+
221+
// Types corresponding to DNS
222+
var dnsTypes = map[string]attr.Type{
223+
"enabled": basetypes.BoolType{},
224+
"zones": basetypes.ListType{ElemType: types.StringType},
225+
}
226+
213227
// NewClusterResource is a helper function to simplify the provider implementation.
214228
func NewClusterResource() resource.Resource {
215229
return &clusterResource{}
@@ -568,7 +582,7 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
568582
},
569583
"argus_instance_id": schema.StringAttribute{
570584
Description: "Argus instance ID to choose which Argus instance is used. Required when enabled is set to `true`.",
571-
Optional: true,
585+
Required: true,
572586
},
573587
},
574588
},
@@ -582,6 +596,21 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
582596
},
583597
"allowed_cidrs": schema.ListAttribute{
584598
Description: "Specify a list of CIDRs to whitelist.",
599+
Required: true,
600+
ElementType: types.StringType,
601+
},
602+
},
603+
},
604+
"dns": schema.SingleNestedAttribute{
605+
Description: "DNS extension configuration",
606+
Optional: true,
607+
Attributes: map[string]schema.Attribute{
608+
"enabled": schema.BoolAttribute{
609+
Description: "Flag to enable/disable DNS extensions",
610+
Required: true,
611+
},
612+
"zones": schema.ListAttribute{
613+
Description: "Specify a list of domain filters for externalDNS (e.g., `foo.runs.onstackit.cloud`)",
585614
Optional: true,
586615
ElementType: types.StringType,
587616
},
@@ -1175,9 +1204,30 @@ func toExtensionsPayload(ctx context.Context, m *Model) (*ske.Extension, error)
11751204
}
11761205
}
11771206

1207+
var skeDNS *ske.DNS
1208+
if !(ex.DNS.IsNull() || ex.DNS.IsUnknown()) {
1209+
dns := dns{}
1210+
diags = ex.DNS.As(ctx, &dns, basetypes.ObjectAsOptions{})
1211+
if diags.HasError() {
1212+
return nil, fmt.Errorf("converting extensions.dns object: %v", diags.Errors())
1213+
}
1214+
dnsEnabled := conversion.BoolValueToPointer(dns.Enabled)
1215+
1216+
zones := []string{}
1217+
diags = dns.Zones.ElementsAs(ctx, &zones, true)
1218+
if diags.HasError() {
1219+
return nil, fmt.Errorf("converting extensions.dns.zones object: %v", diags.Errors())
1220+
}
1221+
skeDNS = &ske.DNS{
1222+
Enabled: dnsEnabled,
1223+
Zones: &zones,
1224+
}
1225+
}
1226+
11781227
return &ske.Extension{
11791228
Acl: skeAcl,
11801229
Argus: skeArgus,
1230+
Dns: skeDNS,
11811231
}, nil
11821232
}
11831233

@@ -1584,15 +1634,15 @@ func getMaintenanceTimes(ctx context.Context, cl *ske.Cluster, m *Model) (startT
15841634
return startTime, endTime, nil
15851635
}
15861636

1587-
func checkDisabledExtensions(ctx context.Context, ex extensions) (aclDisabled, argusDisabled bool, err error) {
1637+
func checkDisabledExtensions(ctx context.Context, ex extensions) (aclDisabled, argusDisabled, dnsDisabled bool, err error) {
15881638
var diags diag.Diagnostics
15891639
acl := acl{}
15901640
if ex.ACL.IsNull() {
15911641
acl.Enabled = types.BoolValue(false)
15921642
} else {
15931643
diags = ex.ACL.As(ctx, &acl, basetypes.ObjectAsOptions{})
15941644
if diags.HasError() {
1595-
return false, false, fmt.Errorf("converting extensions.acl object: %v", diags.Errors())
1645+
return false, false, false, fmt.Errorf("converting extensions.acl object: %v", diags.Errors())
15961646
}
15971647
}
15981648

@@ -1602,11 +1652,21 @@ func checkDisabledExtensions(ctx context.Context, ex extensions) (aclDisabled, a
16021652
} else {
16031653
diags = ex.Argus.As(ctx, &argus, basetypes.ObjectAsOptions{})
16041654
if diags.HasError() {
1605-
return false, false, fmt.Errorf("converting extensions.argus object: %v", diags.Errors())
1655+
return false, false, false, fmt.Errorf("converting extensions.argus object: %v", diags.Errors())
1656+
}
1657+
}
1658+
1659+
dns := dns{}
1660+
if ex.DNS.IsNull() {
1661+
dns.Enabled = types.BoolValue(false)
1662+
} else {
1663+
diags = ex.DNS.As(ctx, &dns, basetypes.ObjectAsOptions{})
1664+
if diags.HasError() {
1665+
return false, false, false, fmt.Errorf("converting extensions.dns object: %v", diags.Errors())
16061666
}
16071667
}
16081668

1609-
return !acl.Enabled.ValueBool(), !argus.Enabled.ValueBool(), nil
1669+
return !acl.Enabled.ValueBool(), !argus.Enabled.ValueBool(), !dns.Enabled.ValueBool(), nil
16101670
}
16111671

16121672
func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {
@@ -1633,12 +1693,12 @@ func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {
16331693
// If we parse that object into the terraform model, it will produce an inconsistent result after apply
16341694
// error
16351695

1636-
aclDisabled, argusDisabled, err := checkDisabledExtensions(ctx, ex)
1696+
aclDisabled, argusDisabled, dnsDisabled, err := checkDisabledExtensions(ctx, ex)
16371697
if err != nil {
16381698
return fmt.Errorf("checking if extensions are disabled: %w", err)
16391699
}
16401700
disabledExtensions := false
1641-
if aclDisabled && argusDisabled {
1701+
if aclDisabled && argusDisabled && dnsDisabled {
16421702
disabledExtensions = true
16431703
}
16441704

@@ -1700,9 +1760,35 @@ func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {
17001760
argusExtension = ex.Argus
17011761
}
17021762

1763+
dnsExtension := types.ObjectNull(dnsTypes)
1764+
if cl.Extensions.Dns != nil {
1765+
enabled := types.BoolNull()
1766+
if cl.Extensions.Dns.Enabled != nil {
1767+
enabled = types.BoolValue(*cl.Extensions.Dns.Enabled)
1768+
}
1769+
1770+
zonesList, diags := types.ListValueFrom(ctx, types.StringType, cl.Extensions.Dns.Zones)
1771+
if diags.HasError() {
1772+
return fmt.Errorf("creating zones list: %w", core.DiagsToError(diags))
1773+
}
1774+
1775+
dnsValues := map[string]attr.Value{
1776+
"enabled": enabled,
1777+
"zones": zonesList,
1778+
}
1779+
1780+
dnsExtension, diags = types.ObjectValue(dnsTypes, dnsValues)
1781+
if diags.HasError() {
1782+
return fmt.Errorf("creating dns: %w", core.DiagsToError(diags))
1783+
}
1784+
} else if dnsDisabled && !ex.DNS.IsNull() {
1785+
dnsExtension = ex.DNS
1786+
}
1787+
17031788
extensionsValues := map[string]attr.Value{
17041789
"acl": aclExtension,
17051790
"argus": argusExtension,
1791+
"dns": dnsExtension,
17061792
}
17071793

17081794
extensions, diags := types.ObjectValue(extensionsTypes, extensionsValues)

0 commit comments

Comments
 (0)