forked from rancher/norman
-
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.
Merge pull request rancher#145 from rawmind0/monitoring
Added argument to define monitoring config for rancher2_cluster and rancher2_project
- Loading branch information
Showing
17 changed files
with
355 additions
and
20 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
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
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,19 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
//Schemas | ||
|
||
func monitoringInputFields() map[string]*schema.Schema { | ||
s := map[string]*schema.Schema{ | ||
"answers": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
Description: "Answers for monitor input", | ||
}, | ||
} | ||
|
||
return s | ||
} |
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
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,37 @@ | ||
package rancher2 | ||
|
||
import ( | ||
managementClient "github.com/rancher/types/client/management/v3" | ||
) | ||
|
||
// Flatteners | ||
|
||
func flattenMonitoringInput(in *managementClient.MonitoringInput) []interface{} { | ||
obj := map[string]interface{}{} | ||
|
||
if in == nil { | ||
return []interface{}{} | ||
} | ||
|
||
if len(in.Answers) > 0 { | ||
obj["answers"] = toMapInterface(in.Answers) | ||
} | ||
|
||
return []interface{}{obj} | ||
} | ||
|
||
// Expanders | ||
|
||
func expandMonitoringInput(p []interface{}) *managementClient.MonitoringInput { | ||
obj := &managementClient.MonitoringInput{} | ||
if len(p) == 0 || p[0] == nil { | ||
return nil | ||
} | ||
in := p[0].(map[string]interface{}) | ||
|
||
if v, ok := in["answers"].(map[string]interface{}); ok && len(v) > 0 { | ||
obj.Answers = toMapString(v) | ||
} | ||
|
||
return obj | ||
} |
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,72 @@ | ||
package rancher2 | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
managementClient "github.com/rancher/types/client/management/v3" | ||
) | ||
|
||
var ( | ||
testMonitoringInputConf *managementClient.MonitoringInput | ||
testMonitoringInputInterface []interface{} | ||
) | ||
|
||
func init() { | ||
testMonitoringInputConf = &managementClient.MonitoringInput{ | ||
Answers: map[string]string{ | ||
"answer_one": "one", | ||
"answer_two": "two", | ||
}, | ||
} | ||
testMonitoringInputInterface = []interface{}{ | ||
map[string]interface{}{ | ||
"answers": map[string]interface{}{ | ||
"answer_one": "one", | ||
"answer_two": "two", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func TestFlattenMonitoringInput(t *testing.T) { | ||
|
||
cases := []struct { | ||
Input *managementClient.MonitoringInput | ||
ExpectedOutput []interface{} | ||
}{ | ||
{ | ||
testMonitoringInputConf, | ||
testMonitoringInputInterface, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
output := flattenMonitoringInput(tc.Input) | ||
if !reflect.DeepEqual(output, tc.ExpectedOutput) { | ||
t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", | ||
tc.ExpectedOutput, output) | ||
} | ||
} | ||
} | ||
|
||
func TestExpandMonitoringInput(t *testing.T) { | ||
|
||
cases := []struct { | ||
Input []interface{} | ||
ExpectedOutput *managementClient.MonitoringInput | ||
}{ | ||
{ | ||
testMonitoringInputInterface, | ||
testMonitoringInputConf, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
output := expandMonitoringInput(tc.Input) | ||
if !reflect.DeepEqual(output, tc.ExpectedOutput) { | ||
t.Fatalf("Unexpected output from expander.\nExpected: %#v\nGiven: %#v", | ||
tc.ExpectedOutput, output) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.