forked from hashicorp/terraform-provider-aws
-
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
1 parent
efa8cd4
commit 951d77a
Showing
4 changed files
with
174 additions
and
0 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
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
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,121 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/budgets" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsBudget() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: resourceAwsBudgetSchema(), | ||
Create: resourceAwsBudgetCreate, | ||
Read: resourceAwsBudgetRead, | ||
Update: resourceAwsBudgetUpdate, | ||
Delete: resourceAwsBudgetDelete, | ||
} | ||
} | ||
|
||
func resourceAwsBudgetSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"limit_amount": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"limit_unit": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"include_tax": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
}, | ||
"include_subscriptions": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
}, | ||
"include_blended": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
}, | ||
"time_period_start": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
}, | ||
"time_period_end": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
}, | ||
"time_unit": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsBudgetCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*AWSClient).budgetconn | ||
accountID := meta.(*AWSClient).accountid | ||
budgetName := d.Get("name").(string) | ||
budgetType := d.Get("type").(string) | ||
budgetLimitAmount := d.Get("limit_amount").(string) | ||
budgetLimitUnit := d.Get("limit_unit").(string) | ||
budgetIncludeTax := d.Get("include_tax").(bool) | ||
budgetIncludeSubscriptions := d.Get("include_subscriptions").(bool) | ||
budgetIncludeBlended := d.Get("include_blended").(bool) | ||
budgetTimePeriodStart := time.Unix(int64(d.Get("time_period_start").(int)), 0) | ||
budgetTimePeriodEnd := time.Unix(int64(d.Get("time_period_end").(int)), 0) | ||
budgetTimeUnit := d.Get("time_unit").(string) | ||
|
||
budget := new(budgets.Budget) | ||
budget.SetBudgetName(budgetName) | ||
budget.SetBudgetType(budgetType) | ||
budget.SetBudgetLimit(&budgets.Spend{ | ||
Amount: &budgetLimitAmount, | ||
Unit: &budgetLimitUnit, | ||
}) | ||
budget.SetCostTypes(&budgets.CostTypes{ | ||
IncludeSubscription: &budgetIncludeSubscriptions, | ||
IncludeTax: &budgetIncludeTax, | ||
UseBlended: &budgetIncludeBlended, | ||
}) | ||
budget.SetTimePeriod(&budgets.TimePeriod{ | ||
End: &budgetTimePeriodEnd, | ||
Start: &budgetTimePeriodStart, | ||
}) | ||
budget.SetTimeUnit(budgetTimeUnit) | ||
createBudgetInput := new(budgets.CreateBudgetInput) | ||
createBudgetInput.SetAccountId(accountID) | ||
createBudgetInput.SetBudget(budget) | ||
_, err := client.CreateBudget(createBudgetInput) | ||
if err != nil { | ||
return fmt.Errorf("create budget failed: ", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsBudgetRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*AWSClient).budgetconn | ||
return fmt.Errorf("not yet implemented", client) | ||
} | ||
|
||
func resourceAwsBudgetUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*AWSClient).budgetconn | ||
return fmt.Errorf("not yet implemented", client) | ||
} | ||
|
||
func resourceAwsBudgetDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*AWSClient).budgetconn | ||
return fmt.Errorf("not yet implemented", client) | ||
} |
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,49 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAwsBudget_basic(t *testing.T) { | ||
rInt := acctest.RandInt() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
//CheckDestroy: testCheckBudgetDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testBudgetConfig_basic(fmt.Sprintf("test-budget-%d", rInt)), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckOutput( | ||
"aws_budget.foo", fmt.Sprintf("test-budget-%d", rInt)), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testCheckBudgetDestroy(s *terraform.State) error { | ||
return fmt.Errorf("not yet implemented") | ||
} | ||
|
||
func testBudgetConfig_basic(name string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_budget" "foo" { | ||
name = "%s" | ||
type = "COST" | ||
limit_amount = "100" | ||
limit_unit = "USD" | ||
include_tax = "true" | ||
include_subscriptions = "false" | ||
include_blended = "false" | ||
time_period_start = 1477353600000 | ||
time_period_end = 1477958399000 | ||
time_unit = "MONTHLY" | ||
}`, name) | ||
} |