Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Project initiation for Terraform (resource_mso_schema_template_anp_test) (DCNE-148) #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ test: fmtcheck
testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m

testacccoverage: fmtcheck
-TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -race -covermode=atomic -coverprofile=coverage.out
go tool cover -html=coverage.out

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
Expand Down
45 changes: 30 additions & 15 deletions mso/resource_mso_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ func resourceMSORest() *schema.Resource {
Type: schema.TypeString,
Required: true,
},

"ignore_on_destroy": &schema.Schema{
Type: schema.TypeBool,
Required: true,
},

"schema_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
}),
}
}
Expand Down Expand Up @@ -93,22 +104,26 @@ func resourceMSORestUpdate(d *schema.ResourceData, m interface{}) error {
}

func resourceMSORestDelete(d *schema.ResourceData, m interface{}) error {
var method, path, payload string
path = d.Get("path").(string)
payload = d.Get("payload").(string)
if tempVar, ok := d.GetOk("method"); ok {
method = tempVar.(string)
} else {
method = "DELETE"
}
if !contains(HTTP_METHODS, method) {
return fmt.Errorf("Invalid method %s passed", method)
}
msoClient := m.(*client.Client)
_, err := MakeRestRequest(msoClient, path, method, payload)
var ignore_on_destroy = d.Get("ignore_on_destroy").(bool)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var ignore_on_destroy = d.Get("ignore_on_destroy").(bool)
var ignoreOnDestroy = d.Get("ignore_on_destroy").(bool)

And everywhere else where this is used.

if ignore_on_destroy == false {
var method, path, payload string
path = d.Get("path").(string)
payload = d.Get("payload").(string)
if tempVar, ok := d.GetOk("method"); ok {
method = tempVar.(string)
} else {
method = "DELETE"
}
if !contains(HTTP_METHODS, method) {
return fmt.Errorf("Invalid method %s passed", method)
}

if err != nil {
return err
msoClient := m.(*client.Client)
_, err := MakeRestRequest(msoClient, path, method, payload)

if err != nil {
return err
}
}
d.SetId("")
return nil
Expand Down
37 changes: 25 additions & 12 deletions mso/resource_mso_schema_site_anp_epg_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,29 @@ func resourceMSOSchemaSiteAnpEpgSelector() *schema.Resource {
}
}

var importReadSchemaID, importReadSiteID, importReadTemplate, importReadANP, importReadEPG string

func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
log.Printf("[DEBUG] %s: Beginning Import", d.Id())
found := false
msoClient := m.(*client.Client)
get_attribute := strings.Split(d.Id(), "/")
schemaID := get_attribute[0]
siteID := get_attribute[2]
template := get_attribute[4]
anpName := get_attribute[6]
epgName := get_attribute[8]
name := get_attribute[10]

var schemaID, siteID, template, anpName, epgName, name string
if !strings.Contains(d.Id(), "/") {
name = d.Id()
schemaID = importReadSchemaID
siteID = importReadSiteID
template = importReadTemplate
anpName = importReadANP
epgName = importReadEPG
} else {
get_attribute := strings.Split(d.Id(), "/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_attribute := strings.Split(d.Id(), "/")
getAttribute := strings.Split(d.Id(), "/")

Same as everywhere else and in other resources.

schemaID = get_attribute[0]
siteID = get_attribute[2]
template = get_attribute[4]
anpName = get_attribute[6]
epgName = get_attribute[8]
name = get_attribute[10]
}
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
if err != nil {
return nil, err
Expand Down Expand Up @@ -180,7 +191,7 @@ func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{
currentName := models.StripQuotes(selectorCont.S("name").String())
if currentName == name {
found = true
d.SetId(name)
d.SetId(currentName)
d.Set("name", currentName)
exps := selectorCont.S("expressions").Data().([]interface{})

Expand Down Expand Up @@ -357,14 +368,17 @@ func resourceSchemaSiteApnEpgSelectorUpdate(d *schema.ResourceData, m interface{
func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{}) error {
found := false
msoClient := m.(*client.Client)

dn := d.Id()
schemaID := d.Get("schema_id").(string)
siteID := d.Get("site_id").(string)
template := d.Get("template_name").(string)
anpName := d.Get("anp_name").(string)
epgName := d.Get("epg_name").(string)

importReadSchemaID = schemaID
anvitha-jain marked this conversation as resolved.
Show resolved Hide resolved
importReadSiteID = siteID
importReadTemplate = template
importReadANP = anpName
importReadEPG = epgName
cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID))
if err != nil {
return err
Expand Down Expand Up @@ -429,7 +443,6 @@ func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{})
currentName := models.StripQuotes(selectorCont.S("name").String())
if currentName == dn {
found = true
d.SetId(dn)
d.Set("name", currentName)
exps := selectorCont.S("expressions").Data().([]interface{})

Expand Down
Loading