Skip to content

Commit f5d0126

Browse files
authored
Merge pull request #566 from labd/565-currently-the-resource-commercetools_tax_category_rate-does-not-support-a-key
feat: added tax category rate key
2 parents 85d81c7 + 70ba0db commit f5d0126

File tree

7 files changed

+37
-7
lines changed

7 files changed

+37
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: Added tax category rate key
3+
time: 2025-02-14T10:00:41.057277942+01:00

commercetools/resource_tax_category.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func resourceTaxCategory() *schema.Resource {
2424
},
2525
Schema: map[string]*schema.Schema{
2626
"key": {
27-
Description: "User-specific unique identifier for the category",
27+
Description: "User-specific unique identifier for the tax category",
2828
Type: schema.TypeString,
2929
Optional: true,
3030
},

commercetools/resource_tax_category_rate.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func resourceTaxCategoryRate() *schema.Resource {
2929
Type: schema.TypeString,
3030
Required: true,
3131
},
32+
"key": {
33+
Description: "User-specific unique identifier for the tax category rate",
34+
Type: schema.TypeString,
35+
Optional: true,
36+
},
3237
"name": {
3338
Type: schema.TypeString,
3439
Required: true,
@@ -185,6 +190,7 @@ func resourceTaxCategoryRateRead(ctx context.Context, d *schema.ResourceData, m
185190
}
186191

187192
func setTaxRateState(d *schema.ResourceData, taxRate *platform.TaxRate) {
193+
_ = d.Set("key", taxRate.Key)
188194
_ = d.Set("name", taxRate.Name)
189195
_ = d.Set("amount", taxRate.Amount)
190196
_ = d.Set("included_in_price", taxRate.IncludedInPrice)
@@ -223,7 +229,7 @@ func resourceTaxCategoryRateUpdate(ctx context.Context, d *schema.ResourceData,
223229
Actions: []platform.TaxCategoryUpdateAction{},
224230
}
225231

226-
if d.HasChange("name") || d.HasChange("amount") || d.HasChange("included_in_price") || d.HasChange("country") || d.HasChange("state") || d.HasChange("sub_rate") {
232+
if d.HasChange("key") || d.HasChange("name") || d.HasChange("amount") || d.HasChange("included_in_price") || d.HasChange("country") || d.HasChange("state") || d.HasChange("sub_rate") {
227233
taxRateDraft, err := createTaxRateDraft(d)
228234
if err != nil {
229235
// Workaround invalid state to be written, see
@@ -282,6 +288,11 @@ func createTaxRateDraft(d *schema.ResourceData) (*platform.TaxRateDraft, error)
282288
}
283289
}
284290

291+
var key *string
292+
if value, ok := d.Get("key").(string); ok && value != "" {
293+
key = &value
294+
}
295+
285296
var countryCode string
286297
if value, ok := d.Get("country").(string); ok {
287298
countryCode = value
@@ -290,6 +301,7 @@ func createTaxRateDraft(d *schema.ResourceData) (*platform.TaxRateDraft, error)
290301
amountRaw := d.Get("amount").(float64)
291302

292303
taxRateDraft := platform.TaxRateDraft{
304+
Key: key,
293305
Name: d.Get("name").(string),
294306
Amount: &amountRaw,
295307
IncludedInPrice: d.Get("included_in_price").(bool),

commercetools/resource_tax_category_rate_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,40 @@ func TestAccTaxCategoryRate_createAndUpdateWithID(t *testing.T) {
2323
CheckDestroy: testAccCheckTaxCategoryRateDestroy,
2424
Steps: []resource.TestStep{
2525
{
26-
Config: testAccTaxCategoryRateConfig(name, amount, true, country),
26+
Config: testAccTaxCategoryRateConfig(name, amount, true, country, ""),
2727
Check: resource.ComposeTestCheckFunc(
2828
resource.TestCheckResourceAttr(resourceName, "name", name),
2929
resource.TestCheckResourceAttr(resourceName, "amount", "0.2"),
3030
resource.TestCheckResourceAttr(resourceName, "included_in_price", "true"),
3131
resource.TestCheckResourceAttr(resourceName, "country", country),
32+
resource.TestCheckResourceAttr(resourceName, "key", ""),
3233
),
3334
},
3435
{
35-
Config: testAccTaxCategoryRateConfig(name, amount, false, country),
36+
Config: testAccTaxCategoryRateConfig(name, amount, false, country, "some-key"),
3637
Check: resource.ComposeTestCheckFunc(
3738
resource.TestCheckResourceAttr(resourceName, "name", name),
3839
resource.TestCheckResourceAttr(resourceName, "amount", "0.2"),
3940
resource.TestCheckResourceAttr(resourceName, "included_in_price", "false"),
4041
resource.TestCheckResourceAttr(resourceName, "country", country),
42+
resource.TestCheckResourceAttr(resourceName, "key", "some-key"),
4143
),
4244
},
4345
{
44-
Config: testAccTaxCategoryRateConfig(name, 0.0, true, country),
46+
Config: testAccTaxCategoryRateConfig(name, 0.0, true, country, ""),
4547
Check: resource.ComposeTestCheckFunc(
4648
resource.TestCheckResourceAttr(resourceName, "name", name),
4749
resource.TestCheckResourceAttr(resourceName, "amount", "0"),
4850
resource.TestCheckResourceAttr(resourceName, "included_in_price", "true"),
4951
resource.TestCheckResourceAttr(resourceName, "country", country),
52+
resource.TestCheckResourceAttr(resourceName, "key", ""),
5053
),
5154
},
5255
},
5356
})
5457
}
5558

56-
func testAccTaxCategoryRateConfig(name string, amount float64, includedInPrice bool, country string) string {
59+
func testAccTaxCategoryRateConfig(name string, amount float64, includedInPrice bool, country, key string) string {
5760
return hclTemplate(`
5861
resource "commercetools_tax_category" "standard" {
5962
key = "test-rate-category"
@@ -64,6 +67,10 @@ func testAccTaxCategoryRateConfig(name string, amount float64, includedInPrice b
6467
resource "commercetools_tax_category_rate" "test_rate" {
6568
tax_category_id = commercetools_tax_category.standard.id
6669
70+
{{if .key }}
71+
key = "{{ .key }}"
72+
{{end}}
73+
6774
name = "{{ .name }}"
6875
amount = {{ .amount }}
6976
included_in_price = {{ .includedInPrice }}
@@ -75,6 +82,7 @@ func testAccTaxCategoryRateConfig(name string, amount float64, includedInPrice b
7582
"amount": amount,
7683
"includedInPrice": includedInPrice,
7784
"country": country,
85+
"key": key,
7886
})
7987
}
8088

docs/resources/tax_category.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ resource "commercetools_tax_category" "my-tax-category" {
3333
### Optional
3434

3535
- `description` (String)
36-
- `key` (String) User-specific unique identifier for the category
36+
- `key` (String) User-specific unique identifier for the tax category
3737

3838
### Read-Only
3939

docs/resources/tax_category_rate.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ See also [Tax Rate API Documentation](https://docs.commercetools.com/api/project
1717

1818
```terraform
1919
resource "commercetools_tax_category" "my-tax-category" {
20+
key = "my-tax-category"
2021
name = "Standard tax category"
2122
description = "Example category"
2223
}
2324
2425
resource "commercetools_tax_category_rate" "standard-tax-category-DE" {
26+
key = "standard-tax-category-DE"
2527
tax_category_id = commercetools_tax_category.my-tax-category.id
2628
name = "19% MwSt"
2729
amount = 0.19
@@ -34,6 +36,7 @@ resource "commercetools_tax_category_rate" "standard-tax-category-DE" {
3436
}
3537
3638
resource "commercetools_tax_category_rate" "standard-tax-category-NL" {
39+
key = "standard-tax-category-NL"
3740
tax_category_id = commercetools_tax_category.my-tax-category.id
3841
name = "21% BTW"
3942
amount = 0.21
@@ -55,6 +58,7 @@ resource "commercetools_tax_category_rate" "standard-tax-category-NL" {
5558
### Optional
5659

5760
- `amount` (Number) Number Percentage in the range of [0..1]. The sum of the amounts of all subRates, if there are any
61+
- `key` (String) User-specific unique identifier for the tax category rate
5862
- `state` (String) The state in the country
5963
- `sub_rate` (Block List) For countries (for example the US) where the total tax is a combination of multiple taxes (for example state and local taxes) (see [below for nested schema](#nestedblock--sub_rate))
6064

examples/resources/commercetools_tax_category_rate/resource.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
resource "commercetools_tax_category" "my-tax-category" {
2+
key = "my-tax-category"
23
name = "Standard tax category"
34
description = "Example category"
45
}
56

67
resource "commercetools_tax_category_rate" "standard-tax-category-DE" {
8+
key = "standard-tax-category-DE"
79
tax_category_id = commercetools_tax_category.my-tax-category.id
810
name = "19% MwSt"
911
amount = 0.19
@@ -16,6 +18,7 @@ resource "commercetools_tax_category_rate" "standard-tax-category-DE" {
1618
}
1719

1820
resource "commercetools_tax_category_rate" "standard-tax-category-NL" {
21+
key = "standard-tax-category-NL"
1922
tax_category_id = commercetools_tax_category.my-tax-category.id
2023
name = "21% BTW"
2124
amount = 0.21

0 commit comments

Comments
 (0)