Skip to content

Commit

Permalink
adding principal to monitoring and caching (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
sraj-sm authored Aug 4, 2023
2 parents 2c45b97 + 720fdd7 commit 6862303
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ type TableMonitoring struct {
Cluster int `json:"cluster"`
ClusterPropertySets []int `json:"clusterPropertySets"`
Enabled bool `json:"enabled"`
Principal *int `json:"principal,omitempty"`
}

type CachingPlan struct {
Expand All @@ -467,6 +468,7 @@ type TableCaching struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Principal *int `json:"principal,omitempty"`
Plan *CachingPlan `json:"plan"`
Retainement *string `json:"retainment"`
PrefixURI string `json:"prefixURI"`
Expand Down
21 changes: 21 additions & 0 deletions client/resource_table_caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func ResourceTableCaching() *schema.Resource {
Elem: cronScheduleSchema(),
ConflictsWith: []string{"daily_schedule"},
},
"principal": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAnamlIdentifier(),
},
"cluster": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -225,6 +230,11 @@ func resourceTableCachingRead(d *schema.ResourceData, m interface{}) error {
if err := d.Set("auto", nil); err != nil {
return err
}
if TableCaching.Principal != nil {
if err := d.Set("principal", strconv.Itoa(*TableCaching.Principal)); err != nil {
return err
}
}
loc, plan := flattenTableCachingPlan(TableCaching.Plan)
if err := d.Set(loc, plan); err != nil {
return err
Expand Down Expand Up @@ -322,6 +332,16 @@ func composeTableCaching(d *schema.ResourceData) (*TableCaching, error) {
}
}

var principal (*int) = nil
principalRaw, principalOk := d.GetOk("principal")
if principalOk {
principal_, err := strconv.Atoi(principalRaw.(string))
if err != nil {
return nil, err
}
principal = &principal_
}

var retainment *string
if d.Get("retainment").(string) != "" {
retainmentstr := d.Get("retainment").(string)
Expand All @@ -337,6 +357,7 @@ func composeTableCaching(d *schema.ResourceData) (*TableCaching, error) {
Name: d.Get("name").(string),
Description: d.Get("description").(string),
PrefixURI: d.Get("prefix_url").(string),
Principal: principal,
Plan: plan,
Retainement: retainment,
Cluster: cluster,
Expand Down
23 changes: 23 additions & 0 deletions client/resource_table_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func ResourceTableMonitoring() *schema.Resource {
ValidateFunc: validateAnamlIdentifier(),
},
},
"principal": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAnamlIdentifier(),
},
"enabled": {
Type: schema.TypeBool,
Required: true,
Expand Down Expand Up @@ -95,6 +100,11 @@ func resourceTableMonitoringRead(d *schema.ResourceData, m interface{}) error {
if err := d.Set("enabled", TableMonitoring.Enabled); err != nil {
return err
}
if TableMonitoring.Principal != nil {
if err := d.Set("principal", strconv.Itoa(*TableMonitoring.Principal)); err != nil {
return err
}
}
if err := d.Set("cluster", strconv.Itoa(TableMonitoring.Cluster)); err != nil {
return err
}
Expand Down Expand Up @@ -162,6 +172,16 @@ func composeTableMonitoring(d *schema.ResourceData) (*TableMonitoring, error) {
return nil, err
}

var principal (*int) = nil
principalRaw, principalOk := d.GetOk("principal")
if principalOk {
principal_, err := strconv.Atoi(principalRaw.(string))
if err != nil {
return nil, err
}
principal = &principal_
}

if dailySchedule, _ := expandSingleMap(d.Get("daily_schedule")); dailySchedule != nil {
schedule, err := composeDailySchedule(dailySchedule)
if err != nil {
Expand All @@ -171,6 +191,7 @@ func composeTableMonitoring(d *schema.ResourceData) (*TableMonitoring, error) {
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Tables: expandIdentifierList(d.Get("tables").(*schema.Set).List()),
Principal: principal,
Enabled: d.Get("enabled").(bool),
Cluster: cluster,
ClusterPropertySets: expandIdentifierList(d.Get("cluster_property_sets").([]interface{})),
Expand All @@ -187,6 +208,7 @@ func composeTableMonitoring(d *schema.ResourceData) (*TableMonitoring, error) {
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Tables: expandIdentifierList(d.Get("tables").(*schema.Set).List()),
Principal: principal,
Enabled: d.Get("enabled").(bool),
Cluster: cluster,
ClusterPropertySets: expandIdentifierList(d.Get("cluster_property_sets").([]interface{})),
Expand All @@ -200,6 +222,7 @@ func composeTableMonitoring(d *schema.ResourceData) (*TableMonitoring, error) {
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Enabled: d.Get("enabled").(bool),
Principal: principal,
Cluster: cluster,
ClusterPropertySets: expandIdentifierList(d.Get("cluster_property_sets").([]interface{})),
Schedule: schedule,
Expand Down
32 changes: 32 additions & 0 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,24 @@ resource "anaml-operations_caching" "caching" {
}
}

resource "anaml-operations_caching" "caching_with_principal" {
name = "household_caching_with_principal"
description = "Caching of tables for households"
prefix_url = "file:///tmp/anaml/caching"
include {
spec {
table = anaml_table.household.id
entity = anaml_entity.household.id
}
}
retainment = "PT48H"
cluster = data.anaml-operations_cluster.local.id
daily_schedule {
start_time_of_day = "00:00:00"
}
principal = anaml-operations_user.jane.id
}

resource "anaml-operations_caching" "caching_two" {
name = "household_caching_auto"
description = "Caching of tables for households"
Expand Down Expand Up @@ -918,6 +936,20 @@ resource "anaml-operations_monitoring" "monitoring" {
}
}

resource "anaml-operations_monitoring" "monitoring_with_principal" {
name = "household_monitoring_with_principal"
description = "Monitoring of tables for households"
enabled = true
tables = [
anaml_table.household.id
]
cluster = data.anaml-operations_cluster.local.id
daily_schedule {
start_time_of_day = "00:00:00"
}
principal = anaml-operations_user.jane.id
}

resource "anaml-operations_user_group" "engineering" {
name = "Engineering"
description = "A user group with engineering members."
Expand Down

0 comments on commit 6862303

Please sign in to comment.