Skip to content

Commit 9707ab7

Browse files
authored
Automatic Terraform Provider Sync (#398)
Automatic sync from Akuity Platform
1 parent c019732 commit 9707ab7

File tree

10 files changed

+234
-136
lines changed

10 files changed

+234
-136
lines changed

akp/data_source_akp_instance_schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ func getInstanceSpecDataSourceAttributes() map[string]schema.Attribute {
199199
Attributes: getAppSetDelegateDataSourceAttributes(),
200200
},
201201
"assistant_extension_enabled": schema.BoolAttribute{
202-
MarkdownDescription: "Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.",
202+
MarkdownDescription: "Deprecated: upcoming removal. Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.",
203+
DeprecationMessage: "assistant_extension_enabled field will be removed in a future release; remove it from configs.",
203204
Computed: true,
204205
},
205206
"appset_policy": schema.SingleNestedAttribute{

akp/provider.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/akuity/api-client-go/pkg/api/gateway/accesscontrol"
9-
gwoption "github.com/akuity/api-client-go/pkg/api/gateway/option"
10-
argocdv1 "github.com/akuity/api-client-go/pkg/api/gen/argocd/v1"
11-
kargov1 "github.com/akuity/api-client-go/pkg/api/gen/kargo/v1"
12-
orgcv1 "github.com/akuity/api-client-go/pkg/api/gen/organization/v1"
13-
idv1 "github.com/akuity/api-client-go/pkg/api/gen/types/id/v1"
14-
httpctx "github.com/akuity/grpc-gateway-client/pkg/http/context"
15-
168
"github.com/hashicorp/terraform-plugin-framework/datasource"
179
"github.com/hashicorp/terraform-plugin-framework/path"
1810
"github.com/hashicorp/terraform-plugin-framework/provider"
1911
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
2012
"github.com/hashicorp/terraform-plugin-framework/resource"
2113
"github.com/hashicorp/terraform-plugin-framework/types"
2214
"github.com/hashicorp/terraform-plugin-log/tflog"
15+
16+
"github.com/akuity/api-client-go/pkg/api/gateway/accesscontrol"
17+
gwoption "github.com/akuity/api-client-go/pkg/api/gateway/option"
18+
argocdv1 "github.com/akuity/api-client-go/pkg/api/gen/argocd/v1"
19+
kargov1 "github.com/akuity/api-client-go/pkg/api/gen/kargo/v1"
20+
orgcv1 "github.com/akuity/api-client-go/pkg/api/gen/organization/v1"
21+
idv1 "github.com/akuity/api-client-go/pkg/api/gen/types/id/v1"
22+
httpctx "github.com/akuity/grpc-gateway-client/pkg/http/context"
2323
)
2424

2525
var _ provider.Provider = &AkpProvider{}

akp/resource_akp_cluster.go

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework/diag"
1111
"github.com/hashicorp/terraform-plugin-framework/path"
1212
"github.com/hashicorp/terraform-plugin-framework/resource"
13+
tftypes "github.com/hashicorp/terraform-plugin-framework/types"
1314
"github.com/hashicorp/terraform-plugin-log/tflog"
1415
"github.com/pkg/errors"
1516
"golang.org/x/exp/slices"
@@ -618,25 +619,37 @@ func (v sizeConfigValidator) MarkdownDescription(ctx context.Context) string {
618619
}
619620

620621
func (v sizeConfigValidator) ValidateResource(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
621-
// Get the full resource configuration
622-
var config types.Cluster
622+
dataPath := path.Root("spec").AtName("data")
623623

624-
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
625-
if resp.Diagnostics.HasError() {
624+
var data tftypes.Object
625+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, dataPath, &data)...)
626+
if resp.Diagnostics.HasError() || data.IsNull() || data.IsUnknown() {
627+
return
628+
}
629+
630+
var size tftypes.String
631+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, dataPath.AtName("size"), &size)...)
632+
if resp.Diagnostics.HasError() || size.IsNull() || size.IsUnknown() {
626633
return
627634
}
635+
sizeValue := size.ValueString()
628636

629-
// Check if spec is nil
630-
if config.Spec == nil {
637+
var autoConfig tftypes.Object
638+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, dataPath.AtName("auto_agent_size_config"), &autoConfig)...)
639+
if resp.Diagnostics.HasError() || autoConfig.IsUnknown() {
631640
return
632641
}
642+
hasAutoConfig := !autoConfig.IsNull()
633643

634-
data := &config.Spec.Data
635-
size := data.Size.ValueString()
636-
hasAutoConfig := !data.AutoscalerConfig.IsNull()
637-
hasCustomConfig := data.CustomAgentSizeConfig != nil
644+
customConfigPath := dataPath.AtName("custom_agent_size_config")
645+
var customConfig tftypes.Object
646+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, customConfigPath, &customConfig)...)
647+
if resp.Diagnostics.HasError() || customConfig.IsUnknown() {
648+
return
649+
}
650+
hasCustomConfig := !customConfig.IsNull()
638651

639-
switch size {
652+
switch sizeValue {
640653
case "auto":
641654
// auto_agent_size_config is optional when size is "auto" - API provides defaults if not specified
642655
if hasCustomConfig {
@@ -666,14 +679,14 @@ func (v sizeConfigValidator) ValidateResource(ctx context.Context, req resource.
666679
resp.Diagnostics.AddAttributeError(
667680
path.Root("spec").AtName("data").AtName("auto_agent_size_config"),
668681
"Invalid auto_agent_size_config",
669-
fmt.Sprintf("auto_agent_size_config cannot be used when size is '%s'", size),
682+
fmt.Sprintf("auto_agent_size_config cannot be used when size is '%s'", sizeValue),
670683
)
671684
}
672685
if hasCustomConfig {
673686
resp.Diagnostics.AddAttributeError(
674687
path.Root("spec").AtName("data").AtName("custom_agent_size_config"),
675688
"Invalid custom_agent_size_config",
676-
fmt.Sprintf("custom_agent_size_config cannot be used when size is '%s'", size),
689+
fmt.Sprintf("custom_agent_size_config cannot be used when size is '%s'", sizeValue),
677690
)
678691
}
679692
default:

akp/resource_akp_cluster_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,93 @@ resource "akp_cluster" "test_validation" {
15101510
})
15111511
}
15121512

1513+
func testAccClusterResourceConfigMergeData(name, instanceId string) string {
1514+
return fmt.Sprintf(`
1515+
variable "config" {
1516+
type = map(any)
1517+
default = {}
1518+
}
1519+
1520+
resource "akp_cluster" "test" {
1521+
instance_id = %q
1522+
name = %q
1523+
namespace = "test"
1524+
1525+
labels = merge({
1526+
"condor.io/cluster-name" = %q
1527+
},
1528+
{
1529+
environment = "test"
1530+
managed-by = "terraform"
1531+
}
1532+
)
1533+
1534+
annotations = merge({
1535+
"argocd.argoproj.io/instance" = %q
1536+
},
1537+
{
1538+
team = "platform"
1539+
owner = "devops"
1540+
}
1541+
)
1542+
1543+
spec = {
1544+
namespace_scoped = false
1545+
description = "Managed by Terraform, do not edit!"
1546+
data = merge({
1547+
kustomization = <<EOF
1548+
apiVersion: kustomize.config.k8s.io/v1beta1
1549+
kind: Kustomization
1550+
patches:
1551+
- patch: |-
1552+
apiVersion: apps/v1
1553+
kind: Deployment
1554+
metadata:
1555+
name: argocd-repo-server
1556+
spec:
1557+
template:
1558+
spec:
1559+
containers:
1560+
- name: argocd-repo-server
1561+
resources:
1562+
limits:
1563+
memory: 2Gi
1564+
requests:
1565+
cpu: 500m
1566+
memory: 1Gi
1567+
target:
1568+
kind: Deployment
1569+
name: argocd-repo-server
1570+
EOF
1571+
}, {
1572+
size = "small"
1573+
auto_upgrade_disabled = true
1574+
}, var.config)
1575+
}
1576+
}
1577+
`, instanceId, name, name, "test-instance")
1578+
}
1579+
1580+
func TestAccClusterResourceMergeData(t *testing.T) {
1581+
name := acctest.RandomWithPrefix("test-merge-data")
1582+
resource.Test(t, resource.TestCase{
1583+
PreCheck: func() { testAccPreCheck(t) },
1584+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
1585+
Steps: []resource.TestStep{
1586+
{
1587+
Config: providerConfig + testAccClusterResourceConfigMergeData(name, getInstanceId()),
1588+
},
1589+
{
1590+
Config: providerConfig + testAccClusterResourceConfigMergeData(name, getInstanceId()),
1591+
Check: resource.ComposeAggregateTestCheckFunc(
1592+
resource.TestCheckResourceAttr("akp_cluster.test", "spec.data.size", "small"),
1593+
resource.TestCheckResourceAttr("akp_cluster.test", "spec.data.auto_upgrade_disabled", "true"),
1594+
),
1595+
},
1596+
},
1597+
})
1598+
}
1599+
15131600
// TestAccCluster_CustomAgentSizeInconsistency tests for custom agent size configuration inconsistencies
15141601
// This test provokes issues in the complex custom agent size logic in types.go lines 226-241
15151602
func TestAccCluster_CustomAgentSizeInconsistency(t *testing.T) {

akp/resource_akp_instance_schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,10 @@ func getInstanceSpecAttributes() map[string]schema.Attribute {
299299
Attributes: getAppSetDelegateAttributes(),
300300
},
301301
"assistant_extension_enabled": schema.BoolAttribute{
302-
MarkdownDescription: "Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.",
302+
MarkdownDescription: "Deprecated: upcoming removal. Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.",
303303
Optional: true,
304304
Computed: true,
305+
DeprecationMessage: "assistant_extension_enabled field will be removed in a future release; remove it from configs.",
305306
PlanModifiers: []planmodifier.Bool{
306307
boolplanmodifier.UseStateForUnknown(),
307308
},

akp/types/cluster.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ type Resources struct {
4040
Cpu types.String `tfsdk:"cpu"`
4141
}
4242

43+
type DirectClusterSpec struct {
44+
ClusterType types.String `tfsdk:"cluster_type"`
45+
KargoInstanceId types.String `tfsdk:"kargo_instance_id"`
46+
}
47+
4348
type ManagedClusterConfig struct {
4449
SecretName types.String `tfsdk:"secret_name"`
4550
SecretKey types.String `tfsdk:"secret_key"`
@@ -86,20 +91,15 @@ type ClusterArgoCDNotificationsSettings struct {
8691
InClusterSettings types.Bool `tfsdk:"in_cluster_settings"`
8792
}
8893

89-
type DirectClusterSpec struct {
90-
ClusterType types.String `tfsdk:"cluster_type"`
91-
KargoInstanceId types.String `tfsdk:"kargo_instance_id"`
92-
}
93-
9494
type ClusterData struct {
9595
Size types.String `tfsdk:"size"`
9696
AutoUpgradeDisabled types.Bool `tfsdk:"auto_upgrade_disabled"`
9797
Kustomization types.String `tfsdk:"kustomization"`
9898
AppReplication types.Bool `tfsdk:"app_replication"`
9999
TargetVersion types.String `tfsdk:"target_version"`
100100
RedisTunneling types.Bool `tfsdk:"redis_tunneling"`
101-
DatadogAnnotationsEnabled types.Bool `tfsdk:"datadog_annotations_enabled"`
102101
DirectClusterSpec *DirectClusterSpec `tfsdk:"direct_cluster_spec"`
102+
DatadogAnnotationsEnabled types.Bool `tfsdk:"datadog_annotations_enabled"`
103103
EksAddonEnabled types.Bool `tfsdk:"eks_addon_enabled"`
104104
ManagedClusterConfig *ManagedClusterConfig `tfsdk:"managed_cluster_config"`
105105
MultiClusterK8SDashboardEnabled types.Bool `tfsdk:"multi_cluster_k8s_dashboard_enabled"`

docs/data-sources/instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Read-Only:
7272
- `app_set_delegate` (Attributes) Select cluster in which you want to Install Application Set controller (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--app_set_delegate))
7373
- `appset_plugins` (Attributes List) Application Set plugins (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--appset_plugins))
7474
- `appset_policy` (Attributes) Configures Application Set policy settings. (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--appset_policy))
75-
- `assistant_extension_enabled` (Boolean) Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.
75+
- `assistant_extension_enabled` (Boolean, Deprecated) Deprecated: upcoming removal. Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.
7676
- `audit_extension_enabled` (Boolean) Enable Audit Extension. Set this to `true` to install Audit Extension to Argo CD instance.
7777
- `backend_ip_allow_list_enabled` (Boolean) Enable ip allow list for cluster agents
7878
- `cluster_customization_defaults` (Attributes) Default values for cluster agents (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--cluster_customization_defaults))

docs/resources/instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ Optional:
616616
- `app_set_delegate` (Attributes) Select cluster in which you want to Install Application Set controller (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--app_set_delegate))
617617
- `appset_plugins` (Attributes List) Application Set plugins (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--appset_plugins))
618618
- `appset_policy` (Attributes) Configures Application Set policy settings. (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--appset_policy))
619-
- `assistant_extension_enabled` (Boolean) Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.
619+
- `assistant_extension_enabled` (Boolean, Deprecated) Deprecated: upcoming removal. Enable Powerful AI-powered assistant Extension. It helps analyze Kubernetes resources behavior and provides suggestions about resolving issues.
620620
- `audit_extension_enabled` (Boolean) Enable Audit Extension. Set this to `true` to install Audit Extension to Argo CD instance.
621621
- `backend_ip_allow_list_enabled` (Boolean) Enable ip allow list for cluster agents
622622
- `cluster_customization_defaults` (Attributes) Default values for cluster agents (see [below for nested schema](#nestedatt--argocd--spec--instance_spec--cluster_customization_defaults))

0 commit comments

Comments
 (0)