-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,029 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ website/node_modules | |
*.iml | ||
*.test | ||
*.iml | ||
.nix/ | ||
shell.nix | ||
*.bk | ||
|
||
|
||
website/vendor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "doit_budget Resource - terraform-provider-doit" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# doit_budget (Resource) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `collaborators` (Attributes List) (see [below for nested schema](#nestedatt--collaborators)) | ||
- `currency` (String) Budget currency can be one of: ["USD","ILS","EUR","GBP","AUD","CAD","DKK","NOK","SEK","BRL","SGD","MXN","CHF","MYR","TWD","EGP","ZAR"] | ||
- `name` (String) Name Budget Name | ||
- `recipients` (List of String) List of emails to notify when reaching alert threshold | ||
- `scope` (List of String) List of budges that defines that budget scope | ||
- `type` (String) Budget type can be one of: ["fixed", "recurring"] | ||
|
||
### Optional | ||
|
||
- `alerts` (Attributes List) (see [below for nested schema](#nestedatt--alerts)) | ||
- `amount` (Number) Budget period required: true(if usePrevSpend is false) | ||
- `description` (String) | ||
- `end_period` (Number) Fixed budget end date required: true(if budget type is fixed) | ||
- `growth_per_period` (Number) Periodical growth percentage in recurring budget | ||
- `metric` (String) Budget metric - currently fixed to "cost" | ||
- `public` (String) Public | ||
- `recipients_slack_channels` (Attributes List) (see [below for nested schema](#nestedatt--recipients_slack_channels)) | ||
- `start_period` (Number) Budget start Date | ||
- `time_interval` (String) Recurring budget interval can be on of:["day", "week", "month", "quarter","year]" | ||
- `use_prev_spend` (Boolean) Use the last period's spend as the target amount for recurring budgets | ||
|
||
### Read-Only | ||
|
||
- `id` (String) Numeric identifier of the budget | ||
- `last_updated` (String) Timestamp of the last Terraform update ofthe budget group. | ||
|
||
<a id="nestedatt--collaborators"></a> | ||
### Nested Schema for `collaborators` | ||
|
||
Required: | ||
|
||
- `email` (String) Collaborator email | ||
- `role` (String) Collaborator role | ||
|
||
|
||
<a id="nestedatt--alerts"></a> | ||
### Nested Schema for `alerts` | ||
|
||
Optional: | ||
|
||
- `forecasted_date` (Number) | ||
- `percentage` (Number) | ||
- `triggered` (Boolean) | ||
|
||
|
||
<a id="nestedatt--recipients_slack_channels"></a> | ||
### Nested Schema for `recipients_slack_channels` | ||
|
||
Optional: | ||
|
||
- `customer_id` (String) | ||
- `id` (String) Slack channel ID | ||
- `name` (String) Slack channel name | ||
- `shared` (Boolean) Slack channel shared | ||
- `type` (String) Slack channel type | ||
- `workspace` (String) Slack channel workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,49 @@ terraform { | |
required_providers { | ||
doit = { | ||
source = "doitintl/doit" | ||
version = "0.10.0" | ||
version = "0.14.0" | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
resource "doit_budget" "my_budget" { | ||
name = "test budget terraform" | ||
description = "hellogo test2" | ||
alerts = [ | ||
{ | ||
percentage = 50 | ||
triggered = false | ||
}, | ||
{ | ||
"percentage" = 85, | ||
"triggered" = false | ||
}, | ||
{ | ||
"percentage" = 100, | ||
"triggered" = false | ||
} | ||
] | ||
recipients = [ | ||
"[email protected]" | ||
] | ||
collaborators = [ | ||
{ | ||
"email" : "[email protected]", | ||
"role" : "owner" | ||
}, | ||
] | ||
scope = [ | ||
"Evct3J0DYcyXIVuAXORd" | ||
] | ||
amount = 200 | ||
currency = "AUD" | ||
growth_per_period = 10 | ||
time_interval = "month" | ||
type = "recurring" | ||
} | ||
|
||
resource "doit_attribution" "attri" { | ||
name = "attritestnewname" | ||
description = "attritestdesc" | ||
|
@@ -88,7 +127,4 @@ resource "doit_report" "my-report_january" { | |
} | ||
] | ||
} | ||
} | ||
|
||
provider "doit" { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package provider | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// CreateBudget - Create new budget | ||
func (c *ClientTest) CreateBudget(budget Budget) (*Budget, error) { | ||
rb, err := json.Marshal(budget) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/budgets/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb))) | ||
log.Println("URL----------------") | ||
log.Println(req.URL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
log.Println("ERROR REQUEST----------------") | ||
log.Println(err) | ||
return nil, err | ||
} | ||
|
||
budgetResponse := Budget{} | ||
err = json.Unmarshal(body, &budgetResponse) | ||
if err != nil { | ||
log.Println("ERROR UNMARSHALL----------------") | ||
log.Println(err) | ||
return nil, err | ||
} | ||
log.Println("Budget response----------------") | ||
log.Println(budgetResponse) | ||
return &budgetResponse, nil | ||
} | ||
|
||
// UpdateBudget - Updates an budget | ||
func (c *ClientTest) UpdateBudget(budgetID string, budget Budget) (*Budget, error) { | ||
rb, err := json.Marshal(budget) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), strings.NewReader(string(rb))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Println("Update BODY----------------") | ||
log.Println(string(rb)) | ||
log.Println("Update URL----------------") | ||
log.Println(req.URL) | ||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Println("Update BODY----------------") | ||
log.Println(string(body)) | ||
budgetResponse := Budget{} | ||
err = json.Unmarshal(body, &budgetResponse) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Println("Budget response----------------") | ||
log.Println(budgetResponse) | ||
return &budgetResponse, nil | ||
} | ||
|
||
func (c *ClientTest) DeleteBudget(budgetID string) error { | ||
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetBudget - Returns a specifc budget | ||
func (c *ClientTest) GetBudget(orderID string) (*Budget, error) { | ||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
budget := Budget{} | ||
err = json.Unmarshal(body, &budget) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &budget, nil | ||
} |
Oops, something went wrong.