Open Madhurya98 opened 6 months ago
Thank you for reporting the issue. We observed the affected resources are not provided in the description or it's incorrect. We request you to add it in issue description as mentioned in below format. Example: affected_resources = oci_core_instance , oci_core_instances
If it's not related to any particular resource then mention affected resource as terraform. Example: affected_resources = terraform
As this works through automation, request you to follow exact syntax.
Updated
Some updates here?
@tf-oci-pub We can confirm that we have the same behavior with a user_data script to change and unexpire the opc Password on an windows instance image. The TF Code is unchanged and worked before without any issues. It would be great if someone can find out if that is a BUG.
@Madhurya98 Please can you check on your instance which API Endpoints are enabled:
Instance metadata service: Versions 1 and 2 OR Instance metadata service: Version 2 only
The user_data / Cloudinit needs the legacy Endpoints be enabled. So the Instance should have:
Instance metadata service: Versions 1 and 2
instance_options { are_legacy_imds_endpoints_disabled = false }
@tf-oci-pub We can confirm that we have the same behavior with a user_data. The User data script is not executed via terraform for windows and linux instances, while the same TF Code worked with resource manager oci service.
@asaber80 Did you check your Instance Metadata Versions? You need 1 and 2 available
@rcsvenlimbach Yes both versions are available
Community Note Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request If you are interested in working on this issue or have submitted a pull request, please leave a comment Terraform Version and Provider Version Terraform v1.6.2 Provider Version 5.27.0
Affected Resource(s) affected_resources = oci_core_instance , oci_core_instances
Terraform Configuration Files resource "oci_core_instance" "windows-test1" {
Required
availability_domain = var.availability_domain compartment_id = var.compartment_id shape = var.instance_shape defined_tags = merge(var.tags, var.env_tag) shape_config { ocpus = var.cpus memory_in_gbs = var.memory_in_gbs } source_details { source_id = var.source_id source_type = "image" }
Optional
display_name = "test-windows" create_vnic_details { assign_public_ip = false subnet_id = var.subnet_id } metadata = { ssh_authorized_keys = file(var.ssh_public_key_path) user_data = "${base64encode(data.template_file.cloud-config.rendered)}" } instance_options { are_legacy_imds_endpoints_disabled = var.legacy_imds_endpoints_disabled } is_pv_encryption_in_transit_enabled = var.intransit_encryption_enabled preserve_boot_volume = var.preserve_boot_volume }
also passing data.tf
data "template_file" "cloud-config" { template = file("./testinit.ps1.tpl") }
data "template_cloudinit_config" "config" { gzip = false base64_encode = true
part { content_type = "text/cloud-config"
content_type = "text/x-shellscript" ---> tried this content type as well
} }
testinit.ps1.tpl
ps1_sysnative
function Get-TimeStamp { return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date) }
function checkPathExists($path) { <# .Description Check if the path exists else create path .Parameters $path: Check if $path exists .Return Path which was created if not exists
>
}
function CreateEnvVariable($variableName,$value) <# .Description Update Environment variable .Parameters $variableName: Name of the variable which needs to be added to env variable $value: Value of the variable
>
{ try{ [Environment]::SetEnvironmentVariable($variableName, $value, "Machine") Write-Host "$(Get-TimeStamp) $variableName with value
"$value
" is added to environment variables" } catch{ Write-Host "$(Get-TimeStamp) Failed to add $variableName with value"$value
" to environment variables" -ErrorAction Stop } }function updatePathSystemVariable($variableName,$value,$scope) <# .Description Update path system variable .Parameters $variableName: Name of the variable which needs to be added to PATH $value: Value of the variable
>
{ try{ if (!$scope){$scope="Machine"} $Prepath=[Environment]::GetEnvironmentVariable("$variableName",$scope) $newPath=";$Prepath;$value" [Environment]::SetEnvironmentVariable("$variableName", $newPath,$scope) Write-Host "$(Get-TimeStamp) $value path is updated in environment variables" } catch{ Write-Error "$(Get-TimeStamp) Failed to add $value to environment variables`nError - $_" -ErrorAction Stop } }
function downloadFile($web_path,$destination_path) {<# .Description Download a file from a web url .Parameters $web_path: Url to download the file $destination_path: Path where the file needs to be downloaded
>
} function waitFileDownload($filepath) {<# .Description Wait for specified time for the file to download .Parameters $filepath: File download path
>
}
function Install-TennableAgent($path,$NessusServer,$NessusKey,$NessusGroups) <# .Description Install Tennable Agent .Parameters $path: Path where file needs to be downloaded and installed $NessusServer: Server URL of Nesus $NessusKey: Key of the Nessus $NessusGroups: group of Nessus
>
{ $TennableURL="https://www.tenable.com/downloads/api/v1/public/pages/nessus-agents/downloads/22992/download?i_agree_to_tenable_license_agreement=true"
Install-TennableAgent -path "C:\Tennable" -NessusServer ":" -NessusKey "" -NessusGroups ""
Debug Output NA
Panic Output NA
Expected Behavior The powershell script must be executed as part of the user data on the windows server 2022 and get the tenable agent installed on top of the oci instance.
Actual Behavior
Steps to Reproduce
References None