Skip to content

Commit

Permalink
Merge pull request #50 from jmpaloalto/importFeatureUpdate
Browse files Browse the repository at this point in the history
Import feature update
  • Loading branch information
wfg authored May 2, 2022
2 parents 39d477e + 524ef58 commit 4fc34be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/resources/custom_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
page_title: "prismacloudcompute_custom_rule Resource - terraform-provider-prismacloudcompute"
subcategory: ""
description: |-
---

# prismacloudcompute_custom_rule (Resource)
Expand Down Expand Up @@ -31,4 +31,8 @@ description: |-
- **id** (String) ID of the custom rule.
- **prisma_id** (Number) Prisma Cloud Compute ID of the custom rule.

## Import

```
$ terraform import prismacloudcompute_custom_rule.example <rule_name>:<prisma_id>
```
30 changes: 28 additions & 2 deletions internal/provider/resource_custom_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package provider

import (
"fmt"

"strings"
"strconv"
"github.com/PaloAltoNetworks/terraform-provider-prismacloudcompute/internal/api"
"github.com/PaloAltoNetworks/terraform-provider-prismacloudcompute/internal/api/rule"
"github.com/PaloAltoNetworks/terraform-provider-prismacloudcompute/internal/convert"
Expand All @@ -17,7 +18,21 @@ func resourceCustomRule() *schema.Resource {
Delete: deleteCustomRule,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {

name, id, err := CustomRuleParseId(d.Id())

intVar, err := strconv.Atoi(id)

if err != nil {
return []*schema.ResourceData{d}, nil
}

var pid int = intVar
d.Set("prisma_id", pid)
d.SetId(name)
return []*schema.ResourceData{d}, nil
},
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -60,6 +75,17 @@ func resourceCustomRule() *schema.Resource {
}
}


func CustomRuleParseId(id string) (string, string, error) {
parts := strings.SplitN(id, ":", 2)

if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", "", fmt.Errorf("unexpected format of ID (%s), expected attribute1:attribute2", id)
}

return parts[0], parts[1], nil
}

func createCustomRule(d *schema.ResourceData, meta interface{}) error {
client := meta.(*api.Client)
parsedCustomRule := convert.SchemaToCustomRule(d)
Expand Down

0 comments on commit 4fc34be

Please sign in to comment.