Skip to content

Commit

Permalink
PR change request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev committed Nov 13, 2024
1 parent b475d07 commit 07d55ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pkg/datasources/datasource_network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ func networkPolicyRead(ctx context.Context, d *schema.ResourceData, meta interfa
return diag.FromErr(err)
}

SetId(string(region), "network_policies", "", "", d)
d.SetId(utils.TransformIdWithRegion(string(region), "network_policies"))
return diags
}
24 changes: 12 additions & 12 deletions pkg/materialize/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (b *NetworkPolicyBuilder) Create() error {
q.WriteString(` ( RULES ( `)
ruleStrings := make([]string, len(b.rules))
for i, rule := range b.rules {
ruleStrings[i] = fmt.Sprintf(`%s (action='%s', direction='%s', address='%s')`,
ruleStrings[i] = fmt.Sprintf(`%s (action=%s, direction=%s, address=%s)`,
QuoteIdentifier(rule.Name),
rule.Action,
rule.Direction,
rule.Address)
QuoteString(rule.Action),
QuoteString(rule.Direction),
QuoteString(rule.Address))
}
q.WriteString(strings.Join(ruleStrings, ", "))
q.WriteString(` ))`)
Expand All @@ -65,11 +65,11 @@ func (b *NetworkPolicyBuilder) Alter() error {
q.WriteString(` ( RULES ( `)
ruleStrings := make([]string, len(b.rules))
for i, rule := range b.rules {
ruleStrings[i] = fmt.Sprintf(`%s (action='%s', direction='%s', address='%s')`,
ruleStrings[i] = fmt.Sprintf(`%s (action=%s, direction=%s, address=%s)`,
QuoteIdentifier(rule.Name),
rule.Action,
rule.Direction,
rule.Address)
QuoteString(rule.Action),
QuoteString(rule.Direction),
QuoteString(rule.Address))
}
q.WriteString(strings.Join(ruleStrings, ", "))
q.WriteString(` ))`)
Expand All @@ -93,7 +93,7 @@ type NetworkPolicyParams struct {
Rules []NetworkPolicyRule
}

type networkPolicyQueryResult struct {
type NetworkPolicyQueryResult struct {
PolicyId sql.NullString `db:"id"`
PolicyName sql.NullString `db:"policy_name"`
Comment sql.NullString `db:"comment"`
Expand Down Expand Up @@ -145,7 +145,7 @@ func NetworkPolicyId(conn *sqlx.DB, obj MaterializeObject) (string, error) {
}
q := networkPolicyQuery.QueryPredicate(p)

var result networkPolicyQueryResult
var result NetworkPolicyQueryResult
if err := conn.Get(&result, q); err != nil {
return "", err
}
Expand All @@ -159,7 +159,7 @@ func ScanNetworkPolicy(conn *sqlx.DB, id string) (NetworkPolicyParams, error) {
}
q := networkPolicyQuery.QueryPredicate(p)

var result networkPolicyQueryResult
var result NetworkPolicyQueryResult
if err := conn.Get(&result, q); err != nil {
return NetworkPolicyParams{}, err
}
Expand All @@ -184,7 +184,7 @@ func ListNetworkPolicies(conn *sqlx.DB) ([]NetworkPolicyParams, error) {
var policies []NetworkPolicyParams
q := networkPolicyQuery.QueryPredicate(map[string]string{})

var results []networkPolicyQueryResult
var results []NetworkPolicyQueryResult
if err := conn.Select(&results, q); err != nil {
return policies, err
}
Expand Down
25 changes: 0 additions & 25 deletions pkg/resources/resource_network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ var networkPolicySchema = map[string]*schema.Schema{
},
MaxItems: 25,
},
// "ownership_role": OwnershipRoleSchema(),
"region": RegionSchema(),
}

Expand Down Expand Up @@ -112,10 +111,6 @@ func networkPolicyRead(ctx context.Context, d *schema.ResourceData, meta interfa
return diag.FromErr(err)
}

// if err := d.Set("ownership_role", policy.OwnerName.String); err != nil {
// return diag.FromErr(err)
// }

// Convert rules to terraform format
ruleList := make([]interface{}, len(policy.Rules))
for i, r := range policy.Rules {
Expand Down Expand Up @@ -168,16 +163,6 @@ func networkPolicyCreate(ctx context.Context, d *schema.ResourceData, meta inter
return diag.FromErr(err)
}

// ownership not currently supported
// if v, ok := d.GetOk("ownership_role"); ok {
// ownership := materialize.NewOwnershipBuilder(metaDb, o)
// if err := ownership.Alter(v.(string)); err != nil {
// log.Printf("[DEBUG] resource failed ownership, dropping object: %s", o.Name)
// b.Drop()
// return diag.FromErr(err)
// }
// }

// comment
if v, ok := d.GetOk("comment"); ok {
comment := materialize.NewCommentBuilder(metaDb, o)
Expand Down Expand Up @@ -231,16 +216,6 @@ func networkPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inter
}
}

// Not currently supported
// if d.HasChange("ownership_role") {
// _, newRole := d.GetChange("ownership_role")
// ownership := materialize.NewOwnershipBuilder(metaDb, o)

// if err := ownership.Alter(newRole.(string)); err != nil {
// return diag.FromErr(err)
// }
// }

if d.HasChange("comment") {
_, newComment := d.GetChange("comment")
b := materialize.NewCommentBuilder(metaDb, o)
Expand Down

0 comments on commit 07d55ee

Please sign in to comment.