cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1215
Views
0
Helpful
13
Replies

Intersight Terraform issue

Tbowden
Level 1
Level 1

I am trying to configure Terraform and Intersight and trying to call the OS Install workflow, but something isnt right.  I ran terraform init, then plan, then apply, but I get this error message below.  Any idea what could be wrong?

 

intersight_os_install.os_install: Creating...

Error: error occurred while creating OsInstall: 400 Bad Request Response from endpoint: {"code":"InvalidRequest","message":"Cannot execute the request. The JSON document is malformed.","messageId":"barcelona_request_malformed_json","traceId":"VkJFRH6XwfSaXXt4sslpZjw0jkCFWZxCI7OUSLkvL1h-9YJ8-DlI-A==","cause":{"code":"InternalServerError","message":"Cannot execute the request due to an error. Retry later.","messageId":"barcelona_request_internal_error","traceId":"VkJFRH6XwfSaXXt4sslpZjw0jkCFWZxCI7OUSLkvL1h-9YJ8-DlI-A=="}}

  with intersight_os_install.os_install,

  on os_install.tf line 1, in resource "intersight_os_install" "os_install":

    1: resource "intersight_os_install" "os_install" {

13 Replies 13

The JSON body you are passing in the resource configuration is malformed. Double check that the JSON follows proper formatting syntax and that all required attributes are included. Run the terraform validate to check.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

I did the "terraform validate" and it comes back clean, thats what Im not understanding.

run terraform show -json os_install.os_install

this will output the complete JSON document that defines the os_install resource configuration, including any arguments and nested blocks that have been set

run the trace command also as this might show more details 

export TF_LOG="TRACE"

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Thank you, but when I run the above I get this error message.  Should I be setting it to os_install.tf?

terraform show -json os_install.tf

Error: Failed to read the given file as a state or plan file

State read error: Error reading os_install.tf as a statefile: 2 problems:

- Unsupported state file format: The state file could not be parsed as JSON: syntax error at byte offset 1.

- Unsupported state file format: The state file does not have a "version" attribute, which is required to identify the format version.

Plan read error: couldn't load the provided path as either a local plan file (zip: not a valid zip file) or a saved cloud plan (invalid character 'r' looking for beginning of value)

 

terraform show -json os_install.os_install

Error: Failed to read the given file as a state or plan file

State read error: Error loading statefile: open os_install.os_install: no such file or directory

Plan read error: couldn't load the provided path as either a local plan file (open os_install.os_install: no such file or directory) or a saved cloud plan (open os_install.os_install: no such file or directory)

Ah I see ok, the terraform show command requires you to pass in an actual state file or plan file, not just a resource name here . Since you want to inspect the os_install resource configuration that is defined in your Terraform code, try this instead

 

terraform state show 'data.intersight_os_install.os_install'

 

This will show the resource attributes that Terraform has stored in the state for that os_install data resource.

However, if you haven't run terraform apply yet, that resource won't yet exist in the state.

In that case, your options are:

  1. Do a terraform plan -out=tfplan, then run terraform show -json tfplan to see the planned resource definition
  2. Print out the resource definition from your Terraform code:
 
terraform print os_install.tf
 
  1. Manually inspect the os_install.tf file to view the resource definition
 

Let me know if any of those help you view that os_install configuration!

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

terraform state show 'data.intersight_os_install.os_install'

No instance found for the given address!

 

This command requires that the address references one specific instance.

To view the available instances, use "terraform state list". Please modify

the address to reference a specific instance.

terraform state list

data.intersight_compute_physical_summary.server

data.intersight_firmware_server_configuration_utility_distributable.scu_repo

data.intersight_organization_organization.org

data.intersight_os_configuration_file.os_config

data.intersight_softwarerepository_operating_system_file.os_repo

I tried the terraform print command you referred to, but "print" is not an option.  I also ran the terraform command to an output file, and then ran the command "terraform show -json tfplan", but that looks all strung out together, at least from the command line when I ran it.

Arh ok on the terraform state list output you shared, it doesn't look like you have a data.intersight_os_install resource in your state yet. That would explain why you got the "No instance found" error when trying to show it.

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

So I have a data.tf file that has this in there, then I have another file called os_install.tf

data "intersight_os_install" "response" {

  moid = intersight_os_install.os_install.id

}

resource "intersight_os_install" "os_install" {
name = local.name
description = local.description
organization {
object_type = "organization.Organization"
moid = data.intersight_organization_organization.org.results[0].moid
}
server {
object_type = data.intersight_compute_physical_summary.server.results[0].source_object_type
moid = data.intersight_compute_physical_summary.server.results[0].moid
}
image {
object_type = "softwarerepository.OperatingSystemFile"
moid = data.intersight_softwarerepository_operating_system_file.os_repo.results[0].moid
}
osdu_image {
object_type = "firmware.ServerConfigurationUtilityDistributable"
moid = data.intersight_firmware_server_configuration_utility_distributable.scu_repo.results[0].moid
}
configuration_file {
object_type = "os.ConfigurationFile"
moid = data.intersight_os_configuration_file.os_config.results[0].moid
}
answers {
hostname = local.os_hostname
ip_config_type = local.os_ip_config_type
ip_configuration {
additional_properties = jsonencode({
IpV4Config = {
IpAddress = local.os_ipv4_addr
Netmask = local.os_ipv4_netmask
Gateway = local.os_ipv4_gateway
}
})
object_type = "os.Ipv4Configuration"
}
is_root_password_crypted = false
nameserver = local.os_ipv4_dns_ip
root_password = local.os_root_password
nr_source = local.os_answers_nr_source
}
install_method = "vMedia"
install_target {
object_type = local.target_config.ObjectType
additional_properties = jsonencode({
# MRAID VD Target
ObjectType = local.ObjectType
Id = local.Id
Name = local.Name
StorageControllerSlotId = local.StorageControllerSlotId
# FC Target
InitiatorWwpn = local.InitiatorWwpn
TargetWwpn = local.TargetWwpn
# iSCSI Target
TargetIqn = local.TargetIqn
VnicMac = local.VnicMac
# LunId parameter is common between FC and iSCSI Targets
LunId = local.LunId
})
}
}

 

Any other idea of how to solve my issue?

The only thing i can think of now is  based on the last output that is trying to reference the id attribute of intersight_os_install.os_install before the resource has been created.  Which you cannot reference attributes of a resource before it has been created.,the id attribute is generated only after the resource has been successfully created.

In the  data "intersight_os_install" "response" block, its attempting to use intersight_os_install.os_install.id, but at that point, os_install hasn't been created yet.

Have you pulled this code from a repo or made this yourself? Only asking if this is a clone repo, might be worth looking over the issues on the repo to see if this has been raised or linked to a version?

Hope this helps.

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

I did pull this code from GitHub, and it looks like the last update may have been around 7 months ago, but you know how things can change very quickly

https://developer.cisco.com/codeexchange/github/repo/sandkum5/terraform_intersight_os_install/

I would place an issue on the repo and see if this a version issue

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io