diff --git a/CHANGELOG.md b/CHANGELOG.md index 41ba2119..a52df13f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.3.7 (Unreleased) +* Add labels to functionalities + ## 0.3.6 * Fix client versioning diff --git a/firehydrant/functionalities.go b/firehydrant/functionalities.go index ccfabe8a..bc3e9228 100644 --- a/firehydrant/functionalities.go +++ b/firehydrant/functionalities.go @@ -2,7 +2,6 @@ package firehydrant import ( "context" - "time" "github.com/dghubble/sling" "github.com/pkg/errors" @@ -27,23 +26,6 @@ func (c *RESTFunctionalitiesClient) restClient() *sling.Sling { return c.client.client() } -// FunctionalityResponse is the payload for a single environment -// URL: GET https://api.firehydrant.io/v1/functionalities/{id} -type FunctionalityResponse struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Slug string `json:"slug"` - Services []FunctionalityService `json:"services"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` -} - -// FunctionalityService represents a service when creating a functionality -type FunctionalityService struct { - ID string `json:"id"` -} - // Get retrieves a functionality from FireHydrant func (c *RESTFunctionalitiesClient) Get(ctx context.Context, id string) (*FunctionalityResponse, error) { funcResponse := &FunctionalityResponse{} @@ -61,14 +43,6 @@ func (c *RESTFunctionalitiesClient) Get(ctx context.Context, id string) (*Functi return funcResponse, nil } -// CreateFunctionalityRequest is the payload for creating a service -// URL: POST https://api.firehydrant.io/v1/services -type CreateFunctionalityRequest struct { - Name string `json:"name"` - Description string `json:"description"` - Services []FunctionalityService `json:"services,omitempty"` -} - // Create creates a functionality in FireHydrant func (c *RESTFunctionalitiesClient) Create(ctx context.Context, req CreateFunctionalityRequest) (*FunctionalityResponse, error) { funcResponse := &FunctionalityResponse{} @@ -86,15 +60,6 @@ func (c *RESTFunctionalitiesClient) Create(ctx context.Context, req CreateFuncti return funcResponse, nil } -// UpdateFunctionalityRequest is the payload for updating a environment -// URL: PATCH https://api.firehydrant.io/v1/environments/{id} -type UpdateFunctionalityRequest struct { - Name string `json:"name,omitempty"` - Description string `json:"description"` - RemoveRemainingServices bool `json:"remove_remaining_services"` - Services []FunctionalityService `json:"services"` -} - // Update updates a functionality in FireHydrant func (c *RESTFunctionalitiesClient) Update(ctx context.Context, id string, req UpdateFunctionalityRequest) (*FunctionalityResponse, error) { funcResponse := &FunctionalityResponse{} diff --git a/firehydrant/types.go b/firehydrant/types.go index 8487c7ce..e7e0aa1e 100644 --- a/firehydrant/types.go +++ b/firehydrant/types.go @@ -258,3 +258,40 @@ type Pagination struct { Prev int `json:"prev,omitempty"` Next int `json:"next,omitempty"` } + +// FunctionalityResponse is the payload for a single environment +// URL: GET https://api.firehydrant.io/v1/functionalities/{id} +type FunctionalityResponse struct { + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Slug string `json:"slug"` + Services []FunctionalityService `json:"services"` + Labels map[string]string `json:"labels"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +// FunctionalityService represents a service when creating a functionality +type FunctionalityService struct { + ID string `json:"id"` +} + +// CreateFunctionalityRequest is the payload for creating a service +// URL: POST https://api.firehydrant.io/v1/services +type CreateFunctionalityRequest struct { + Name string `json:"name"` + Description string `json:"description"` + Services []FunctionalityService `json:"services,omitempty"` + Labels map[string]string `json:"labels"` +} + +// UpdateFunctionalityRequest is the payload for updating a environment +// URL: PATCH https://api.firehydrant.io/v1/environments/{id} +type UpdateFunctionalityRequest struct { + Name string `json:"name,omitempty"` + Description string `json:"description"` + RemoveRemainingServices bool `json:"remove_remaining_services"` + Labels map[string]string `json:"labels"` + Services []FunctionalityService `json:"services"` +} diff --git a/provider/functionality_data.go b/provider/functionality_data.go index 6c2969b8..d76042cb 100644 --- a/provider/functionality_data.go +++ b/provider/functionality_data.go @@ -30,6 +30,10 @@ func dataSourceFunctionality() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "labels": { + Type: schema.TypeMap, + Computed: true, + }, "service_ids": { Type: schema.TypeSet, Computed: true, @@ -59,6 +63,7 @@ func dataFireHydrantFunctionality(ctx context.Context, d *schema.ResourceData, m attributes := map[string]interface{}{ "name": functionalityResponse.Name, "description": functionalityResponse.Description, + "labels": functionalityResponse.Labels, } serviceIDs := make([]string, 0) diff --git a/provider/functionality_data_test.go b/provider/functionality_data_test.go index 6b31b58d..f5fa396d 100644 --- a/provider/functionality_data_test.go +++ b/provider/functionality_data_test.go @@ -70,6 +70,9 @@ resource "firehydrant_functionality" "test_functionality" { name = "test-functionality-%s" description = "test-description-%s" service_ids = [firehydrant_service.test_service.id] + labels = { + test1 = "test-label1-foo", + } } data "firehydrant_functionality" "test_functionality" { diff --git a/provider/functionality_resource.go b/provider/functionality_resource.go index 6ecfffd5..a891d9ea 100644 --- a/provider/functionality_resource.go +++ b/provider/functionality_resource.go @@ -40,6 +40,10 @@ func resourceFunctionality() *schema.Resource { Type: schema.TypeString, }, }, + "labels": { + Type: schema.TypeMap, + Optional: true, + }, }, } } @@ -69,6 +73,7 @@ func readResourceFireHydrantFunctionality(ctx context.Context, d *schema.Resourc attributes := map[string]interface{}{ "name": functionalityResponse.Name, "description": functionalityResponse.Description, + "labels": functionalityResponse.Labels, } serviceIDs := make([]string, 0) @@ -95,6 +100,7 @@ func createResourceFireHydrantFunctionality(ctx context.Context, d *schema.Resou createRequest := firehydrant.CreateFunctionalityRequest{ Name: d.Get("name").(string), Description: d.Get("description").(string), + Labels: convertStringMap(d.Get("labels").(map[string]interface{})), } // Process any optional attributes and add to the create request if necessary @@ -129,6 +135,7 @@ func updateResourceFireHydrantFunctionality(ctx context.Context, d *schema.Resou updateRequest := firehydrant.UpdateFunctionalityRequest{ Name: d.Get("name").(string), Description: d.Get("description").(string), + Labels: convertStringMap(d.Get("labels").(map[string]interface{})), } // Process any optional attributes and add to the update request if necessary diff --git a/provider/functionality_resource_test.go b/provider/functionality_resource_test.go index a7d6fd3b..888e1e5e 100644 --- a/provider/functionality_resource_test.go +++ b/provider/functionality_resource_test.go @@ -229,6 +229,9 @@ func testAccFunctionalityResourceConfig_basic(rName string) string { return fmt.Sprintf(` resource "firehydrant_functionality" "test_functionality" { name = "test-functionality-%s" + labels = { + test1 = "test-label1-foo", + } }`, rName) } @@ -245,6 +248,9 @@ resource "firehydrant_service" "test_service2" { resource "firehydrant_functionality" "test_functionality" { name = "test-functionality-%s" description = "test-description-%s" + labels = { + test1 = "test-label1-foo", + } service_ids = [ firehydrant_service.test_service1.id, diff --git a/provider/priority_data_test.go b/provider/priority_data_test.go index 6cf5ab8c..e2fa7d0a 100644 --- a/provider/priority_data_test.go +++ b/provider/priority_data_test.go @@ -2,41 +2,45 @@ package provider import ( "fmt" + "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccPriorityDataSource_basic(t *testing.T) { + rSlug := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testFireHydrantIsSetup(t) }, ProviderFactories: defaultProviderFactories(), Steps: []resource.TestStep{ { - Config: testAccPriorityDataSourceConfig_basic(), + Config: testAccPriorityDataSourceConfig_basic(rSlug), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.firehydrant_priority.test_priority", "id"), resource.TestCheckResourceAttr( - "data.firehydrant_priority.test_priority", "slug", "TESTPRIORITY"), + "data.firehydrant_priority.test_priority", "slug", fmt.Sprintf("TESTPRIORITY%s", rSlug)), resource.TestCheckResourceAttr( "data.firehydrant_priority.test_priority", "description", "test-description"), resource.TestCheckResourceAttr( - "data.firehydrant_priority.test_priority", "default", "true"), + "data.firehydrant_priority.test_priority", "default", "false"), ), }, }, }) } -func testAccPriorityDataSourceConfig_basic() string { - return fmt.Sprintln(` +func testAccPriorityDataSourceConfig_basic(rSlug string) string { + return fmt.Sprintf(` resource "firehydrant_priority" "test_priority" { - slug = "TESTPRIORITY" + slug = "TESTPRIORITY%s" description = "test-description" - default = true + default = false } data "firehydrant_priority" "test_priority" { slug = firehydrant_priority.test_priority.id -}`) +}`, rSlug) } diff --git a/provider/priority_resource_test.go b/provider/priority_resource_test.go index b02d7b6b..723c059a 100644 --- a/provider/priority_resource_test.go +++ b/provider/priority_resource_test.go @@ -68,7 +68,7 @@ func TestAccPriorityResource_update(t *testing.T) { resource.TestCheckResourceAttr( "firehydrant_priority.test_priority", "description", fmt.Sprintf("test-description-%s", rSlugUpdated)), resource.TestCheckResourceAttr( - "firehydrant_priority.test_priority", "default", "true"), + "firehydrant_priority.test_priority", "default", "false"), ), }, { @@ -258,7 +258,7 @@ func testAccPriorityResourceConfig_update(rSlug string) string { resource "firehydrant_priority" "test_priority" { slug = "TESTPRIORITY%s" description = "test-description-%s" - default = true + default = false }`, rSlug, rSlug) }