Skip to content

Commit

Permalink
PC-6755: Add schemas for client_id and client_secret (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
danstan9 authored Dec 16, 2022
1 parent ab3afc6 commit 8d43326
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/resources/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ resource "nobl9_agent" "this" {

### Read-Only

- `client_id` (String) client_id of created agent.
- `client_secret` (String) client_secret of created agent.
- `id` (String) The ID of this resource.
- `status` (Map of String) Status of the created agent.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.19.0
github.com/nobl9/nobl9-go v0.3.2
github.com/nobl9/nobl9-go v0.4.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nobl9/nobl9-go v0.3.2 h1:l6eA5d7JVyaz+eSwTV1vfPIXGt1VDML5JjKawkySEJg=
github.com/nobl9/nobl9-go v0.3.2/go.mod h1:V+SUN5VoHZrBtNQ7ghBEFIzqHw/IWPzWAm6KF4agKvE=
github.com/nobl9/nobl9-go v0.4.0 h1:iaW5YlB9Cdfibc4izQRaEMA+Q7LbwbNxqo3Kn1mDqaA=
github.com/nobl9/nobl9-go v0.4.0/go.mod h1:V+SUN5VoHZrBtNQ7ghBEFIzqHw/IWPzWAm6KF4agKvE=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down
25 changes: 21 additions & 4 deletions nobl9/resource_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func agentSchema() map[string]*schema.Schema {
Required: true,
Description: "The type of the Agent. Check [Supported Agent types | Nobl9 Documentation](https://docs.nobl9.com/Sources/)",
},
"client_id": {
Type: schema.TypeString,
Computed: true,
Description: "client_id of created agent.",
},
"client_secret": {
Type: schema.TypeString,
Computed: true,
Description: "client_secret of created agent.",
},
"status": {
Type: schema.TypeMap,
Computed: true,
Expand Down Expand Up @@ -98,20 +108,27 @@ func resourceAgentApply(ctx context.Context, d *schema.ResourceData, meta interf
if ds != nil {
return ds
}
service, diags := marshalAgent(d)
agent, diags := marshalAgent(d)
if diags.HasError() {
return diags
}

var p n9api.Payload
p.AddObject(service)
p.AddObject(agent)

err := client.ApplyObjects(p.GetObjects())
agentsData, err := client.ApplyAgents(p.GetObjects())
if err != nil {
return diag.Errorf("could not add agent: %s", err.Error())
}

d.SetId(service.Metadata.Name)
if len(agentsData) == 1 {
err = d.Set("client_id", agentsData[0].ClientID)
diags = appendError(diags, err)
err = d.Set("client_secret", agentsData[0].ClientSecret)
diags = appendError(diags, err)
}

d.SetId(agent.Metadata.Name)

readAgentDiags := resourceAgentRead(ctx, d, meta)

Expand Down

0 comments on commit 8d43326

Please sign in to comment.