Skip to content

Commit

Permalink
feat(argocd_application): add read-only status attribute (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
onematchfox authored Jun 9, 2023
1 parent ce561fa commit 49e347e
Show file tree
Hide file tree
Showing 6 changed files with 466 additions and 21 deletions.
1 change: 1 addition & 0 deletions argocd/resource_argocd_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func resourceArgoCDApplication() *schema.Resource {
Optional: true,
Default: true,
},
"status": applicationStatusSchema(),
},
SchemaVersion: 4,
StateUpgraders: []schema.StateUpgrader{
Expand Down
48 changes: 34 additions & 14 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ func TestAccArgoCDApplication(t *testing.T) {
"spec.0.source.0.target_revision",
"8.0.0",
),
resource.TestCheckResourceAttrSet(
"argocd_application."+name,
"status.0.%",
),
),
},
{
ResourceName: "argocd_application." + name,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
{
// Update
Expand Down Expand Up @@ -67,8 +71,24 @@ func TestAccArgoCDApplication(t *testing.T) {
"spec.0.source.0.target_revision",
"9.4.1",
),
resource.TestCheckResourceAttr(
"argocd_application."+name,
"status.0.health.0.status",
"Healthy",
),
resource.TestCheckResourceAttr(
"argocd_application."+name,
"status.0.sync.0.status",
"Synced",
),
),
},
{
ResourceName: "argocd_application." + name,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
},
},
})
}
Expand Down Expand Up @@ -129,7 +149,7 @@ ingress:
ResourceName: "argocd_application.helm",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -178,7 +198,7 @@ func TestAccArgoCDApplication_Kustomize(t *testing.T) {
ResourceName: "argocd_application.kustomize",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -213,7 +233,7 @@ func TestAccArgoCDApplication_IgnoreDifferences(t *testing.T) {
ResourceName: "argocd_application.ignore_differences",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "status"},
},
{
Config: testAccArgoCDApplicationIgnoreDiffJQPathExpressions(
Expand All @@ -239,7 +259,7 @@ func TestAccArgoCDApplication_IgnoreDifferences(t *testing.T) {
ResourceName: "argocd_application.ignore_differences_jqpe",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "status"},
},
},
})
Expand Down Expand Up @@ -273,7 +293,7 @@ func TestAccArgoCDApplication_RevisionHistoryLimit(t *testing.T) {
ResourceName: "argocd_application.revision_history_limit",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "status"},
},
},
})
Expand Down Expand Up @@ -302,7 +322,7 @@ func TestAccArgoCDApplication_OptionalDestinationNamespace(t *testing.T) {
ResourceName: "argocd_application.no_namespace",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "status"},
},
},
})
Expand Down Expand Up @@ -387,7 +407,7 @@ func TestAccArgoCDApplication_DirectoryJsonnet(t *testing.T) {
ResourceName: "argocd_application.directory",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -493,7 +513,7 @@ func TestAccArgoCDApplication_EmptyDirectory(t *testing.T) {
ResourceName: "argocd_application.directory",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -525,7 +545,7 @@ func TestAccArgoCDApplication_DirectoryIncludeExclude(t *testing.T) {
ResourceName: "argocd_application.directory",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -585,7 +605,7 @@ func TestAccArgoCDApplication_SyncPolicy(t *testing.T) {
ResourceName: "argocd_application.sync_policy",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -937,7 +957,7 @@ func TestAccArgoCDApplication_CustomNamespace(t *testing.T) {
ResourceName: "argocd_application.custom_namespace",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "status"},
},
},
})
Expand Down Expand Up @@ -971,7 +991,7 @@ func TestAccArgoCDApplication_MultipleSources(t *testing.T) {
ResourceName: "argocd_application.multiple_sources",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down Expand Up @@ -1009,7 +1029,7 @@ func TestAccArgoCDApplication_HelmValuesFromExternalGitRepo(t *testing.T) {
ResourceName: "argocd_application.helm_values_external",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version", "status"},
},
},
})
Expand Down
204 changes: 204 additions & 0 deletions argocd/schema_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,210 @@ func resourceArgoCDApplicationV3() *schema.Resource {
}
}

func applicationStatusSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Description: "Status information for the application. **Note**: this is not guaranteed to be up to date immediately after creating/updating an application unless `wait=true`.",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"conditions": {
Type: schema.TypeList,
Description: "List of currently observed application conditions.",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"message": {
Type: schema.TypeString,
Description: "Human-readable message indicating details about condition.",
Computed: true,
},
"last_transition_time": {
Type: schema.TypeString,
Description: "The time the condition was last observed.",
Computed: true,
},
"type": {
Type: schema.TypeString,
Description: "Application condition type.",
Computed: true,
},
},
},
},
"health": {
Type: schema.TypeList,
Description: "Application's current health status.",
Computed: true,
Elem: resourceApplicationHealthStatus(),
},
"operation_state": {
Type: schema.TypeList,
Description: "Information about any ongoing operations, such as a sync.",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"finished_at": {
Type: schema.TypeString,
Description: "Time of operation completion.",
Computed: true,
},
"message": {
Type: schema.TypeString,
Description: "Any pertinent messages when attempting to perform operation (typically errors).",
Computed: true,
},
"phase": {
Type: schema.TypeString,
Description: "The current phase of the operation.",
Computed: true,
},
"retry_count": {
Type: schema.TypeString,
Description: "Count of operation retries.",
Computed: true,
},
"started_at": {
Type: schema.TypeString,
Description: "Time of operation start.",
Computed: true,
},
},
},
},
"reconciled_at": {
Type: schema.TypeString,
Description: "When the application state was reconciled using the latest git version.",
Computed: true,
},
"resources": {
Type: schema.TypeList,
Description: "List of Kubernetes resources managed by this application.",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
Description: "The Kubernetes resource Group.",
Computed: true,
},
"health": {
Type: schema.TypeList,
Description: "Resource health status.",
Computed: true,
Elem: resourceApplicationHealthStatus(),
},
"kind": {
Type: schema.TypeString,
Description: "The Kubernetes resource Kind.",
Computed: true,
},
"hook": {
Type: schema.TypeBool,
Description: "Indicates whether or not this resource has a hook annotation.",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "The Kubernetes resource Name.",
Computed: true,
},
"namespace": {
Type: schema.TypeString,
Description: "The Kubernetes resource Namespace.",
Computed: true,
},
"requires_pruning": {
Type: schema.TypeBool,
Description: "Indicates if the resources requires pruning or not.",
Computed: true,
},
"status": {
Type: schema.TypeString,
Description: "Resource sync status.",
Computed: true,
},
"sync_wave": {
Type: schema.TypeString,
Description: "Sync wave.",
Computed: true,
},
"version": {
Type: schema.TypeString,
Description: "The Kubernetes resource Version.",
Computed: true,
},
},
},
},
"summary": {
Type: schema.TypeList,
Description: "List of URLs and container images used by this application.",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"external_urls": {
Type: schema.TypeList,
Description: "All external URLs of application child resources.",
Computed: true,
Elem: schema.TypeString,
},
"images": {
Type: schema.TypeList,
Description: "All images of application child resources.",
Computed: true,
Elem: schema.TypeString,
},
},
},
},
"sync": {
Type: schema.TypeList,
Description: "Application's current sync status",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"revision": {
Type: schema.TypeString,
Description: "Information about the revision the comparison has been performed to.",
Computed: true,
},
"revisions": {
Type: schema.TypeList,
Description: "Information about the revision(s) the comparison has been performed to.",
Computed: true,
Elem: schema.TypeString,
},
"status": {
Type: schema.TypeString,
Description: "Sync state of the comparison.",
Computed: true,
},
},
},
},
},
},
}
}

func resourceApplicationHealthStatus() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"message": {
Type: schema.TypeString,
Description: "Human-readable informational message describing the health status.",
Computed: true,
},
"status": {
Type: schema.TypeString,
Description: "Status code of the application or resource.",
Computed: true,
},
},
}
}

func resourceArgoCDApplicationStateUpgradeV0(_ context.Context, rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) {
_spec, ok := rawState["spec"].([]interface{})
if !ok || len(_spec) == 0 {
Expand Down
Loading

0 comments on commit 49e347e

Please sign in to comment.