Skip to content

Commit

Permalink
DXE-3087 Merge pull request #468 from joel-g/cps-enrollment/pending-c…
Browse files Browse the repository at this point in the history
…hange

DXE-3087 Adds pending_changes computed field to Enrollment data source
  • Loading branch information
mgwoj authored Sep 8, 2023
2 parents 999a0f3 + b3251fe commit 0d95005
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/providers/cps/data_akamai_cps_enrollment.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ func dataSourceCPSEnrollment() *schema.Resource {
Computed: true,
Description: "The registration authority or certificate authority (CA) used to obtain a certificate",
},
"pending_changes": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether some changes are pending",
},
"dns_challenges": {
Type: schema.TypeSet,
Computed: true,
Expand Down Expand Up @@ -324,6 +329,8 @@ func dataCPSEnrollmentRead(ctx context.Context, d *schema.ResourceData, m interf

attrs := createAttrs(enrollment, enrollmentID)

attrs["pending_changes"] = len(enrollment.PendingChanges) > 0

if err = tf.SetAttrs(d, attrs); err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/providers/cps/data_akamai_cps_enrollment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func checkAttributesForEnrollment(en *cps.Enrollment, enID int, changes *cps.Cha
checkCommonAttrs(en, enID),
checkSetTypeAttrs(en),
checkChallenges(changes, dvArray),
checkPendingChangesEnrollment(en),
)
}

Expand Down Expand Up @@ -637,6 +638,13 @@ func checkChallenges(changes *cps.Change, dvArray *cps.DVArray) resource.TestChe
return resource.ComposeAggregateTestCheckFunc(checkFunctions...)
}

func checkPendingChangesEnrollment(en *cps.Enrollment) resource.TestCheckFunc {
if len(en.PendingChanges) > 0 {
return resource.TestCheckResourceAttr("data.akamai_cps_enrollment.test", "pending_changes", "true")
}
return resource.TestCheckResourceAttr("data.akamai_cps_enrollment.test", "pending_changes", "false")
}

func calculateNumberOfChanges(dvArray *cps.DVArray, changeType string) int {
counter := 0
for _, dv := range dvArray.DV {
Expand Down

0 comments on commit 0d95005

Please sign in to comment.