Skip to content

Commit

Permalink
Changes wrt latest schematics sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviGopal committed Jan 4, 2024
1 parent 160caa0 commit 881cb4a
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 128 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/IBM/project-go-sdk v0.1.6
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v5 v5.1.3
github.com/IBM/schematics-go-sdk v0.2.2
github.com/IBM/schematics-go-sdk v0.2.3
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.2
github.com/IBM/vpc-beta-go-sdk v0.6.0
github.com/IBM/vpc-go-sdk v0.47.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ github.com/IBM/sarama v1.41.2 h1:ZDBZfGPHAD4uuAtSv4U22fRZBgst0eEwGFzLj0fb85c=
github.com/IBM/sarama v1.41.2/go.mod h1:xdpu7sd6OE1uxNdjYTSKUfY8FaKkJES9/+EyjSgiGQk=
github.com/IBM/scc-go-sdk/v5 v5.1.3 h1:8zqJx/HgChTlMaC21HzthIR4HbFkuJ3dR/D68254jRg=
github.com/IBM/scc-go-sdk/v5 v5.1.3/go.mod h1:YtAVlzq10bwR82QX4ZavhDIwa1s85RuVO9N/KmXVcuk=
github.com/IBM/schematics-go-sdk v0.2.2 h1:8S3hoVLzF/ZRgWDaLqwHnLmZvlEBHCKgHszmMh7yD2E=
github.com/IBM/schematics-go-sdk v0.2.2/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/schematics-go-sdk v0.2.3 h1:lgTt0Sbudii3cuSk1YSQgrtiZAXDbBABAoVj3eQuBrU=
github.com/IBM/schematics-go-sdk v0.2.3/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.2 h1:+Svh1OmoFxMBnZQSOUtp2UUzrOGFsSQlE5TFL/ptJco=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.2/go.mod h1:WII+LS4VkQYykmq65NWSuPb5xGNvsqkcK1aCWZoU2x4=
github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc=
Expand Down
8 changes: 6 additions & 2 deletions ibm/service/schematics/data_source_ibm_schematics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,13 @@ func dataSourceIbmSchematicsAgentRead(context context.Context, d *schema.Resourc
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

getAgentDataOptions.SetAgentID(d.Get("agent_id").(string))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ func dataSourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.R
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff
getAgentDataOptions.SetAgentID(d.Get("agent_id").(string))

agentData, response, err := schematicsClient.GetAgentDataWithContext(context, getAgentDataOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ func dataSourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.R
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff
getAgentDataOptions.SetAgentID(d.Get("agent_id").(string))

agentData, response, err := schematicsClient.GetAgentDataWithContext(context, getAgentDataOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ func dataSourceIbmSchematicsAgentPrsRead(context context.Context, d *schema.Reso
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff
getAgentDataOptions.SetAgentID(d.Get("agent_id").(string))

agentData, response, err := schematicsClient.GetAgentDataWithContext(context, getAgentDataOptions)
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/schematics/data_source_ibm_schematics_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4212,7 +4212,7 @@ func dataSourceJobLogSummaryToMap(logSummaryItem schematicsv1.JobLogSummary) (lo
return logSummaryMap
}

func dataSourceJobLogSummaryLogErrorsToMap(logErrorsItem schematicsv1.JobLogSummaryLogErrors) (logErrorsMap map[string]interface{}) {
func dataSourceJobLogSummaryLogErrorsToMap(logErrorsItem schematicsv1.JobLogSummaryLogErrorsItem) (logErrorsMap map[string]interface{}) {
logErrorsMap = map[string]interface{}{}

if logErrorsItem.ErrorCode != nil {
Expand Down
34 changes: 0 additions & 34 deletions ibm/service/schematics/data_source_ibm_schematics_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,37 +123,3 @@ func dataSourceIBMSchematicsOutputRead(d *schema.ResourceData, meta interface{})
func dataSourceIBMSchematicsOutputID(d *schema.ResourceData) string {
return time.Now().UTC().String()
}

func dataSourceOutputValuesListFlattenOutputValues(result []schematicsv1.OutputValuesInner) (outputValues interface{}) {
for _, outputValuesItem := range result {
outputValues = dataSourceOutputValuesListOutputValuesToMap(outputValuesItem)
}

return outputValues
}

func dataSourceOutputValuesListOutputValuesToMap(outputValuesItem schematicsv1.OutputValuesInner) (outputValuesMap map[string]interface{}) {
outputValuesMap = map[string]interface{}{}

if outputValuesItem.Folder != nil {
outputValuesMap["folder"] = outputValuesItem.Folder
}
if outputValuesItem.ID != nil {
outputValuesMap["id"] = outputValuesItem.ID
}

m := []flex.Map{}

for _, outputValues := range outputValuesItem.OutputValues {
m = append(m, flex.Flatten(outputValues))
}

if outputValuesItem.OutputValues != nil {
outputValuesMap["output_values"] = m
}
if outputValuesItem.ValueType != nil {
outputValuesMap["value_type"] = outputValuesItem.ValueType
}

return outputValuesMap
}
51 changes: 9 additions & 42 deletions ibm/service/schematics/data_source_ibm_schematics_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package schematics

import (
"context"
"encoding/json"
"fmt"
"log"

Expand Down Expand Up @@ -86,30 +87,10 @@ func DataSourceIBMSchematicsWorkspace() *schema.Resource {
Description: "The version of the software template that you chose to install from the IBM Cloud catalog.",
},
"service_extensions": {
Type: schema.TypeList,
Type: schema.TypeString,
Computed: true,
Description: "List of service data",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the Service Data.",
},
"value": {
Type: schema.TypeString,
Computed: true,
Description: "Value of the Service Data.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Type of the value string, int, bool.",
},
},
},
},
}}},
Description: "Service extensions defined as string of json",
}}}},
"created_at": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -880,30 +861,16 @@ func dataSourceWorkspaceResponseCatalogRefToMap(catalogRefItem schematicsv1.Cata
catalogRefMap["offering_version"] = catalogRefItem.OfferingVersion
}
if catalogRefItem.ServiceExtensions != nil {
serviceExtensionsList := []map[string]interface{}{}
for _, serviceExtensionsItem := range catalogRefItem.ServiceExtensions {
serviceExtensionsList = append(serviceExtensionsList, dataSourceWorkspaceResponseCatalogRefServiceExtensionsToMap(serviceExtensionsItem))
serviceExtensionsByte, err := json.MarshalIndent(catalogRefItem.ServiceExtensions, "", "")
if err != nil {
log.Printf("[DEBUG] Marshelling of service extensions failed %s", err)
}
catalogRefMap["service_extensions"] = serviceExtensionsList
serviceExtensionsJSON := string(serviceExtensionsByte[:])
catalogRefMap["service_extensions"] = serviceExtensionsJSON
}
return catalogRefMap
}

func dataSourceWorkspaceResponseCatalogRefServiceExtensionsToMap(serviceExtensionsItem schematicsv1.ServiceExtensions) (serviceExtensionMap map[string]interface{}) {
serviceExtensionMap = map[string]interface{}{}

if serviceExtensionsItem.Name != nil {
serviceExtensionMap["name"] = *serviceExtensionsItem.Name
}
if serviceExtensionsItem.Type != nil {
serviceExtensionMap["type"] = serviceExtensionsItem.Type
}
if serviceExtensionsItem.Value != nil {
serviceExtensionMap["value"] = *serviceExtensionsItem.Value
}
return serviceExtensionMap
}

func dataSourceWorkspaceResponseFlattenRuntimeData(result []schematicsv1.TemplateRunTimeDataResponse) (runtimeData []map[string]interface{}) {
for _, runtimeDataItem := range result {
runtimeData = append(runtimeData, dataSourceWorkspaceResponseRuntimeDataToMap(runtimeDataItem))
Expand Down
26 changes: 21 additions & 5 deletions ibm/service/schematics/resource_ibm_schematics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,12 @@ func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.Resourc
}

createAgentDataOptions := &schematicsv1.CreateAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
// XFeatureAgents: core.BoolPtr(true),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
createAgentDataOptions.Headers = ff

createAgentDataOptions.SetName(d.Get("name").(string))
createAgentDataOptions.SetResourceGroup(d.Get("resource_group").(string))
Expand Down Expand Up @@ -636,9 +640,13 @@ func resourceIbmSchematicsAgentRead(context context.Context, d *schema.ResourceD
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

getAgentDataOptions.SetAgentID(d.Id())

Expand Down Expand Up @@ -788,8 +796,12 @@ func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.Resourc
}

updateAgentDataOptions := &schematicsv1.UpdateAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
// XFeatureAgents: core.BoolPtr(true),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
updateAgentDataOptions.Headers = ff

updateAgentDataOptions.SetAgentID(d.Id())

Expand Down Expand Up @@ -878,8 +890,12 @@ func resourceIbmSchematicsAgentDelete(context context.Context, d *schema.Resourc
}

deleteAgentDataOptions := &schematicsv1.DeleteAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
// XFeatureAgents: core.BoolPtr(true),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
deleteAgentDataOptions.Headers = ff

deleteAgentDataOptions.SetAgentID(d.Id())

Expand Down
18 changes: 11 additions & 7 deletions ibm/service/schematics/resource_ibm_schematics_agent_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func resourceIbmSchematicsAgentDeployCreate(context context.Context, d *schema.R

d.SetId(fmt.Sprintf("%s/%s", *deployAgentJobOptions.AgentID, *agentDeployJob.JobID))
log.Printf("[INFO] Agent : %s", *deployAgentJobOptions.AgentID)
d.Set("status_message", *agentDeployJob.StatusMessage)

_, err = isWaitForAgentAvailable(context, schematicsClient, *deployAgentJobOptions.AgentID, d.Timeout(schema.TimeoutCreate))
if err != nil {
Expand Down Expand Up @@ -152,10 +151,13 @@ func isWaitForAgentAvailable(context context.Context, schematicsClient *schemati
func agentRefreshFunc(schematicsClient *schematicsv1.SchematicsV1, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
AgentID: core.StringPtr(id),
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
AgentID: core.StringPtr(id),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

agent, response, err := schematicsClient.GetAgentData(getAgentDataOptions)
if err != nil {
Expand All @@ -180,9 +182,12 @@ func resourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.Res
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

getAgentDataOptions.SetAgentID(parts[0])
agentData, response, err := schematicsClient.GetAgentDataWithContext(context, getAgentDataOptions)
Expand Down Expand Up @@ -269,7 +274,6 @@ func resourceIbmSchematicsAgentDeployUpdate(context context.Context, d *schema.R
return diag.FromErr(fmt.Errorf("DeployAgentJobWithContext failed %s\n%s", err, response))
}
d.SetId(fmt.Sprintf("%s/%s", *deployAgentJobOptions.AgentID, *agentDeployJob.JobID))
d.Set("status_message", *agentDeployJob.StatusMessage)

_, err = isWaitForAgentAvailable(context, schematicsClient, parts[0], d.Timeout(schema.TimeoutUpdate))
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ func testAccCheckIbmSchematicsAgentDeployExists(n string, obj *schematicsv1.Agen
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

parts, err := flex.SepIdParts(rs.Primary.ID, "/")
if err != nil {
Expand Down Expand Up @@ -138,8 +142,8 @@ func testAccCheckIbmSchematicsAgentDeployDestroy(s *terraform.State) error {
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}

parts, err := flex.SepIdParts(rs.Primary.ID, "/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ func resourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.Res
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

getAgentDataOptions.SetAgentID(parts[0])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ func testAccCheckIbmSchematicsAgentHealthExists(n string, obj *schematicsv1.Agen
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}
ff := map[string]string{
"X-Feature-Agents": "true",
}
getAgentDataOptions.Headers = ff

parts, err := flex.SepIdParts(rs.Primary.ID, "/")
if err != nil {
Expand Down Expand Up @@ -138,8 +142,8 @@ func testAccCheckIbmSchematicsAgentHealthDestroy(s *terraform.State) error {
}

getAgentDataOptions := &schematicsv1.GetAgentDataOptions{
XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
// XFeatureAgents: core.BoolPtr(true),
Profile: core.StringPtr("detailed"),
}

parts, err := flex.SepIdParts(rs.Primary.ID, "/")
Expand Down
Loading

0 comments on commit 881cb4a

Please sign in to comment.