Skip to content

Commit

Permalink
update resources_go
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskuchin committed Aug 31, 2023
1 parent 05b10af commit 8818818
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions internal/bowtie/client/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ func (c *Client) DeleteResource(id string) error {
return err
}

func (c *Client) CreateResourceGroup(name string, resources, resource_groups []string) (string, error) {
func (c *Client) CreateResourceGroup(ctx context.Context, name string, resources, resource_groups []string) (string, error) {
id := uuid.NewString()
return id, c.UpsertResourceGroup(id, name, resources, resource_groups)
return id, c.UpsertResourceGroup(ctx, id, name, resources, resource_groups)
}

func (c *Client) UpsertResourceGroup(id, name string, resources, resource_groups []string) error {
func (c *Client) UpsertResourceGroup(ctx context.Context, id, name string, resources, resource_groups []string) error {
payload := BowtieResourceGroup{
ID: id,
Name: name,
Expand All @@ -193,6 +193,10 @@ func (c *Client) UpsertResourceGroup(id, name string, resources, resource_groups
}

body, err := json.Marshal(payload)
if err != nil {
return err
}

req, err := http.NewRequest(http.MethodPost, c.getHostURL("/policy/upsert_resource_group"), bytes.NewBuffer(body))
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions internal/bowtie/resources/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (rg *resourceGroupResource) Schema(ctx context.Context, req resource.Schema
"inherited": schema.ListAttribute{
MarkdownDescription: "The list of resource groups to include in this resource group",
ElementType: types.StringType,
Optional: true,
Required: true,
},
"resources": schema.ListAttribute{
MarkdownDescription: "The resources that should directly be included in this resource group",
Expand Down Expand Up @@ -94,7 +94,7 @@ func (rg *resourceGroupResource) Create(ctx context.Context, req resource.Create
return
}

id, err := rg.client.CreateResourceGroup(plan.Name.ValueString(), resources, resource_groups)
id, err := rg.client.CreateResourceGroup(ctx, plan.Name.ValueString(), resources, resource_groups)
if err != nil {
resp.Diagnostics.AddError(
"Failed to create the resource group",
Expand All @@ -110,16 +110,16 @@ func (rg *resourceGroupResource) Create(ctx context.Context, req resource.Create

func (rg *resourceGroupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var state resourceGroupResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, state)...)
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

resourceGroup, err := rg.client.GetResourceGroup(state.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"",
"",
"Failed to read the resource group",
"Unexpected error reading the resource group: "+state.ID.ValueString()+" err: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func (rg *resourceGroupResource) Update(ctx context.Context, req resource.Update
return
}

err := rg.client.UpsertResourceGroup(plan.ID.ValueString(), plan.Name.ValueString(), resources, resource_groups)
err := rg.client.UpsertResourceGroup(ctx, plan.ID.ValueString(), plan.Name.ValueString(), resources, resource_groups)
if err != nil {
resp.Diagnostics.AddError(
"Failed updating the resource group",
Expand Down

0 comments on commit 8818818

Please sign in to comment.