diff --git a/README.md b/README.md index da54c911..685c308d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ At this point, the registry will be able to provide the new release - check out ## Development -1. Add the asdf plugins: `asdf plugin add golang richgo` +1. Add the asdf plugins: `asdf plugin add golang richgo terraform` 2. Run `asdf install` to install necessary tools from .tool-versions 3. Run `make local` to create the binary locally diff --git a/sym/provider/acceptance_test_util.go b/sym/provider/acceptance_test_util.go index 19f27b2d..86051094 100644 --- a/sym/provider/acceptance_test_util.go +++ b/sym/provider/acceptance_test_util.go @@ -369,10 +369,15 @@ func (r flowResource) String() string { p.WriteString(fmt.Sprintf(" allow_revoke = %v\n", r.params.allowRevoke)) p.WriteString(fmt.Sprintf(" schedule_deescalation = %v\n", r.params.scheduleDeescalation)) + if r.params.additionalHeaderText != "" { + p.WriteString(fmt.Sprintf(" additional_header_text = \"%s\"\n", r.params.additionalHeaderText)) + } + // if allowedSources is not nil, include it in the params if r.params.allowedSources != "" { p.WriteString(fmt.Sprintf(" allowed_sources_json = jsonencode(%v)\n", r.params.allowedSources)) } + p.WriteString(" prompt_fields_json = jsonencode([\n") for _, f := range r.params.promptFields { p.WriteString(" {\n") @@ -416,6 +421,7 @@ type params struct { strategyId string allowRevoke bool allowedSources string + additionalHeaderText string scheduleDeescalation bool promptFields []field } diff --git a/sym/provider/flow_resource_test.go b/sym/provider/flow_resource_test.go index 9aa4ccbe..91695b68 100644 --- a/sym/provider/flow_resource_test.go +++ b/sym/provider/flow_resource_test.go @@ -25,6 +25,7 @@ func TestAccSymFlow_basic(t *testing.T) { resource.TestCheckResourceAttrPair("sym_flow.this", "params.strategy_id", "sym_strategy.sso_main", "id"), resource.TestCheckResourceAttr("sym_flow.this", "params.allow_revoke", "true"), resource.TestCheckResourceAttr("sym_flow.this", "params.allowed_sources_json", `["slack","api"]`), + resource.TestCheckResourceAttr("sym_flow.this", "params.additional_header_text", "Additional Header Text"), resource.TestCheckResourceAttr("sym_flow.this", "params.schedule_deescalation", "false"), resource.TestCheckResourceAttr("sym_flow.this", "params.prompt_fields_json", `[{"name":"reason","type":"string","required":true,"label":"Reason"},{"name":"urgency","type":"list","required":true,"default":"Low","allowed_values":["Low","Medium","High"]}]`), ), @@ -39,6 +40,7 @@ func TestAccSymFlow_basic(t *testing.T) { resource.TestCheckResourceAttrPair("sym_flow.this", "environment_id", "sym_environment.this", "id"), resource.TestCheckResourceAttrPair("sym_flow.this", "params.strategy_id", "sym_strategy.sso_main", "id"), resource.TestCheckResourceAttr("sym_flow.this", "params.allow_revoke", "false"), + resource.TestCheckNoResourceAttr("sym_flow.this", "params.header_text"), resource.TestCheckResourceAttr("sym_flow.this", "params.schedule_deescalation", "true"), ), }, @@ -158,7 +160,7 @@ func TestAccSymFlow_allowedSourcesOnlyAPI(t *testing.T) { }) } -func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId string, scheduleDeescalation bool, allowedSources string) string { +func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId string, scheduleDeescalation bool, allowedSources string, additionalHeaderText string) string { return makeTerraformConfig( providerResource{org: data.OrgSlug}, integrationResource{ @@ -244,6 +246,7 @@ func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId str strategyId: strategyId, allowRevoke: allowRevoke, allowedSources: allowedSources, + additionalHeaderText: additionalHeaderText, scheduleDeescalation: scheduleDeescalation, promptFields: []field{ { @@ -267,24 +270,24 @@ func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId str func createFlowConfig(data TestData) string { return flowConfig(data, "internal/testdata/before_impl.py", true, "sym_strategy.sso_main.id", false, - `["slack", "api"]`) + `["slack", "api"]`, "Additional Header Text") } func updateFlowConfig(data TestData) string { return flowConfig(data, "internal/testdata/after_impl.py", false, "sym_strategy.sso_main.id", true, - "") + "", "") } func createFlowNoStrategyConfig(data TestData) string { return flowConfig(data, "internal/testdata/before_impl.py", true, "", false, - "") + "", "") } func updateFlowNoStrategyConfig(data TestData) string { return flowConfig(data, "internal/testdata/after_impl.py", false, "", true, - "") + "", "") } func createFlowConfigWithOnlyAPISource(data TestData) string { - return flowConfig(data, "internal/testdata/after_impl.py", true, "sym_strategy.sso_main.id", true, `["api"]`) + return flowConfig(data, "internal/testdata/after_impl.py", true, "sym_strategy.sso_main.id", true, `["api"]`, "") } diff --git a/sym/templates/sym_approval.go b/sym/templates/sym_approval.go index 454c3113..1cc11774 100644 --- a/sym/templates/sym_approval.go +++ b/sym/templates/sym_approval.go @@ -28,11 +28,12 @@ func fieldResource() *schema.Resource { func (t *SymApprovalTemplate) ParamResource() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ - "strategy_id": utils.Optional(schema.TypeString), - "allow_revoke": utils.OptionalWithDefault(schema.TypeBool, true), - "allowed_sources": utils.StringList(false), - "schedule_deescalation": utils.OptionalWithDefault(schema.TypeBool, true), - "prompt_fields": utils.OptionalList(fieldResource()), + "strategy_id": utils.Optional(schema.TypeString), + "allow_revoke": utils.OptionalWithDefault(schema.TypeBool, true), + "allowed_sources": utils.StringList(false), + "schedule_deescalation": utils.OptionalWithDefault(schema.TypeBool, true), + "prompt_fields": utils.OptionalList(fieldResource()), + "additional_header_text": utils.Optional(schema.TypeString), }, } } @@ -71,6 +72,10 @@ func (t *SymApprovalTemplate) terraformToAPI(params *HCLParamMap) client.APIPara raw["strategy_id"] = field.Value() } + if field := params.checkKey("additional_header_text"); field != nil { + raw["additional_header_text"] = field.Value() + } + if field := params.checkKey("allow_revoke"); field != nil { // If allow_revoke is set, validate that it is a boolean and add it to params allowRevoke, err := strconv.ParseBool(field.Value()) @@ -163,6 +168,10 @@ func apiParamsToTFParams(apiParams client.APIParams) (*HCLParamMap, error) { params["allowed_sources_json"] = allowedSourcesOutput } + if additionalHeaderTextField, ok := apiParams["additional_header_text"].(string); ok { + params["additional_header_text"] = additionalHeaderTextField + } + if apiParamsStrategyID, ok := apiParams["strategy_id"].(string); ok { params["strategy_id"] = apiParamsStrategyID } diff --git a/sym/templates/sym_approval_test.go b/sym/templates/sym_approval_test.go index a18f5da0..027fd2a1 100644 --- a/sym/templates/sym_approval_test.go +++ b/sym/templates/sym_approval_test.go @@ -92,15 +92,17 @@ func Test_apiParamsToTFParams_allowed_sources(t *testing.T) { { "allow-slack-and-api", client.APIParams{ - "prompt_fields": []interface{}{}, - "allowed_sources": []interface{}{"slack", "api"}, + "prompt_fields": []interface{}{}, + "allowed_sources": []interface{}{"slack", "api"}, + "additional_header_text": "Default Header Text", }, &HCLParamMap{ Params: map[string]string{ - "allow_revoke": "false", - "schedule_deescalation": "false", - "prompt_fields_json": `[]`, - "allowed_sources_json": `["slack","api"]`, + "allow_revoke": "false", + "schedule_deescalation": "false", + "prompt_fields_json": `[]`, + "allowed_sources_json": `["slack","api"]`, + "additional_header_text": "Default Header Text", }, }, false,