Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all 11395 articles
Browse latest View live

EKS ALB Not Working


Security_rule Adding all the VM's IP address to the security rule

Terraform ssh connection to Windows 10 “The directory name is invalid”

$
0
0

@philthynz wrote:

I have the following Terraform code at an attempt to remotely generalize a Windows 10 box via “remote-exec”. I have already enabled openssh-server on Windows 10 and I can connect fine. After it connects it then has an error “The directory name is invalid”. Even commands like “dir” or “hostname” have this error.

Code:

resource "null_resource" "generalize_vm" {
  provisioner "remote-exec" {
    connection {
    user     = var.vm_username
    password = var.vm_password
    host     = "ip"
    }

    inline = [
      "dir",
    ]
  }
}

Terraform apply:

module.vm.null_resource.generalize_vm (remote-exec): Connecting to remote host via SSH...
module.vm.null_resource.generalize_vm (remote-exec):   Host: ip
module.vm.null_resource.generalize_vm (remote-exec):   User: username
module.vm.null_resource.generalize_vm (remote-exec):   Password: true
module.vm.null_resource.generalize_vm (remote-exec):   Private key: false
module.vm.null_resource.generalize_vm (remote-exec):   Certificate: false
module.vm.null_resource.generalize_vm (remote-exec):   SSH Agent: false
module.vm.null_resource.generalize_vm (remote-exec):   Checking Host Key: false
module.vm.null_resource.generalize_vm (remote-exec): Connected!
module.vm.null_resource.generalize_vm (remote-exec):




















                                                     The directory name is invalid.
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm (remote-exec):
module.vm.null_resource.generalize_vm: Creation complete after 1s [id=4268925703469176082]
module.vm.null_resource.generalize_vm (remote-exec):
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

I have tried both Terraform on Windows and Linux. Is remote-exec for ssh expecting only bash syntax? Would be great if remote-exec can exec commands over ssh like open-ssh does. I can use ssh username@ ‘ipconfig’ to exec remote commands in open-ssh.

Posts: 1

Participants: 1

Read full topic

Backup and restores of TF managed resources

$
0
0

@bradroe wrote:

Hi,

We need to have the ability to backup and restore EC2/EBS volumes. We use Terraform to create the infrastructure and store the backend in S3. Is anyone using a backup solution for there Terraform managed infrastructure? If so, how does Terraform deal with a restore? What happens to the state file etc?

I have had a look at using AWS backup which works fine for backing up and restoring, however on restores it means a new instance is created and is not managed by Terraform.

It could be done using snapshots and AMIs however we require a single pane of glass which gives a centralized view for another team to do restores. It would also mean a code change to the TF code to replace the volumes/AMIs.

Any advice would be appreciated.

Posts: 2

Participants: 2

Read full topic

Recover Terraform Registry GitHub Webhook

$
0
0

@michaelwittig wrote:

Hi,

I accidentally deleted the GitHub Webhook that Terraform Registry adds to a repo. How can I recreate the webhook?

Thanks
Michael

Posts: 1

Participants: 1

Read full topic

Error in using string list variable in Terraform Cloud

$
0
0

@HanSooloo wrote:

I have a simple project that creates DigitalOcean droplets. As part of the droplet creation, I need to inject a list of SSH key fingerprints to the authorized keys list.
When I add these as Terraform Variables in the UI

The resulting run fails with the following error.

Terraform v0.12.23
Configuring remote state backend...
Initializing Terraform configuration...
2020/03/09 15:09:44 [DEBUG] Using modified User-Agent: Terraform/0.12.23 TFC/896fd11ba6

Error: Invalid value for input variable

  on /terraform/terraform/terraform.tfvars line 4:
   4: ssh_fingerprints = "[\"fingerprint_1\", \"fingerprint_2\"]"

The given value is not valid for variable "ssh_fingerprints": list of string
required.

But, if I change the variable definition to be parsed as HCL, then it works.

Why would using ["fingerprint_1", "fingerprint_2"] as is not work?

Posts: 2

Participants: 2

Read full topic

Terraforming AWS Config across multiple sub-accounts + multiple regions

$
0
0

@kylecompassion wrote:

I’m trying to enable AWS Config in multiple AWS subaccounts (members of an AWS Organization) + enable AWS Config in multiple regions. I’ve got it working for a single region, but since the resources don’t accept Region values i’m struggling to figure out a good way to enable it in multiple regions.
I can’t just tell the Config Recorder/delivery channel/recorder status to deploy into multiple regions within the module as regions arent supported arguments in those resources.
If i declare the module multiple times, using a provider for AWS with each provider configured for a different region, i end up deploying multiple, identical, IAM resources and S3 buckets to store the Config logs. because it’ll deploy the same resources in each region, including the IAM pieces and S3 buckets. I guess this is doable but not ideal. if i deploy to every region available id end up with 22 duplicates per IAM resource type and 22 S3 buckets. per account.
Does anyone know of another alternative for how to do this that allows multiple regions to be deployed but minimizes the duplication of IAM resources and reuse of an S3 bucket?

Posts: 1

Participants: 1

Read full topic

Terraform a Kubernetes VNF Environment

$
0
0

@captainCrench wrote:

New to Terraform but excited about its potential. I’m trying to learn IaC concepts and have a particular use case I’d like to utilize Terraform for. My plan is to utilize Terraform to create a Kubernetes VNF cluster for network simulation purposes. I’d also like to utilize NSM (https://networkservicemesh.io/) to connect these VNFs together in a topology described with IaC files. Is this something that is feasible? I’m not going to ask about the NSM specifics here but can Terraform describe how Pods connect to one another? Either through CNI or with NSM which would be ideal.

Posts: 1

Participants: 1

Read full topic


Unable to create Azure Windows VM

$
0
0

@NisharunnisaShaik wrote:

Hi
I am unable to create Windows Virtual Machine.I gone through many blogs, official docs but nothing helped . Somehow one or the other error is popping up.

Terraform version : v0.12.23
My config for creating vm:

resource "azurerm_windows_virtual_machine" "resource_virtual_machine" {
name = "${var.virtual-machine}"
location = "${azurerm_resource_group.resource_group_name.location}"
resource_group_name = "${azurerm_resource_group.resource_group_name.name}"
size = "Standard_B1ls"
admin_username = "${var.admin}"
admin_password = "${var.password}"
network_interface_ids = ["${azurerm_network_interface.resource_network_interface.id}"]

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"

}

source_image_reference{
publisher="MicrosoftWindowsDesktop"
offer="Windows-10"
sku="19h1-ent"
version="18362.592.2001092016"
}
}

Error : compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 – Original Error: Code=“InvalidParameter” Message=“The Admin Username specified is not allowed.” Target="adminUsername"

Note : Storage_image_reference , os_profile_windows_config, os_profile

I have tried using all the above options in the config file but every time i get a new error stating the "
os_profile is not expected here".

Solutions & suggestions appreciated.
Thank you

Posts: 1

Participants: 1

Read full topic

Random String Import

Flattening schema need help

$
0
0

@skydion wrote:

Hello

I have the next schema

"network" : &schema.Schema {
  Type          : schema.TypeSet,
  Computed      : true,
  Elem : &schema.Resource {
    Schema: map[string]*schema.Schema {
      "id" : &schema.Schema {
        Type      : schema.TypeInt,
        Computed  : true,
      },
    },
  },
},

if err := d.Set("network", flattenNetwork(ipnet.Network)); err != nil {
  return err
}

I have two functions first worked some time ago but now it don’t work

func flattenNetwork1(net testgo.ID) map[string]int {
   return map[string]int {
     "id" : net.ID,
   }
}

New function, but I got error - panic: interface conversion: interface {} is map[string]interface {}, not *schema.Set

func flattenNetwork2(net testgo.ID) *schema.Set {
  flattenedNetwork := schema.NewSet(schema.HashInt, []interface{}{})
  flattenedNetwork.Add( net.ID )
  return flattenedNetwork
}

JSON body which I get from API
[ { "ip_net":{ "network":{ "id":6 } } } ]

So what I do wrong?

Posts: 1

Participants: 1

Read full topic

Is that possible to use TWO or more providers in the same tf file?

$
0
0

@MarcoPalomo wrote:

:sun_with_face:
Hi all,
I am trying to use two (or more) providers in the same terraform tf file. I want to apply on both (or more) my changes. Is that possible to do it?

These are the providers :

provider "rancher2"{  //the first one
 api_url = "https://first.rancher.cloud/v3" //api-endpoint
 access_key = "tokxen-xxxxxx" 
 secret_key = "xxxqrzertwlm8f9pqsddffg8c84npl9kbgh9xbvwfh7klc7d5m9ktsk"
 alias = "a"
}


provider "rancher2"{  //the second
 api_url = "https://second.rancher.cloud/v3" //api-endpoint
 access_key = "tokxen-xxxxx" 
 secret_key = "vs5qliuhgygydhthrthrjkjkaz53s5bssxj8fthfphc82vwnd4jwrn9"
 alias = "b"
}

And here is my resource :

resource "rancher2_role_template" "bt" {
  
  name = "bt"
  context = "cluster"
  default_role = true
  description = "tf templating for CRD acceptance by API gps"
  rules {
    api_groups = ["common.k8s.elastic.co"]
    resources = ["*"]
    verbs = ["create","delete","get","list","patch","update","watch"]
  }

The difficulty is to attack these two providers to refresh my resource at the same time.

Posts: 4

Participants: 2

Read full topic

Provider referring arguments exported from other resources

$
0
0

@giorgos-nikolopoulos wrote:

Hello,

I am developing the citrixadc provider ( https://github.com/citrix/terraform-provider-citrixadc ).

We recently had a user case where there was the need to instantiate an AWS VM with a Citrix ADC image and then go on to configure this instance with the citrixadc provider.

The problem is that the citrixadc provider needs the ip address of the primary network interface to instantiate the NITRO API client, which is not known during the plan step of terraform.

We suggested the solution of applying the configuration in two steps, first apply the aws_instance configuration and then use the exported values to apply the citrixadc configuration.

Nevertheless the user would like to do this operation in a single plan and apply step.

The only way to accommodate this in the provider would be to have each resource instantiate its own NITRO API client to communicate with the target ADC.

That means for each resource we would need to define all the provider attributes as input parameters and use them to instantiate the client.

Since we plan to have the provider certified at some point in the future I would like to ask if this design is advisable.

What is the recommended way to handle such a use case?

Posts: 1

Participants: 1

Read full topic

Terraform tfstate

$
0
0

@RanzBiswa wrote:

For primitive type TypeFloat in terraform, when I write a acceptance test case where I pass a value called as 12.32 then it stores data as 12.31111**9
My acceptance test case fails as it’s not equal.

How to solve this ?

Can anyone help me in this

Posts: 2

Participants: 2

Read full topic

Unable to import google logging metric using terraform

$
0
0

@pkaramol wrote:

I have created in terraform the following logging metric resource

resource "google_logging_metric" "proservices_run" {
  name   = "user/proservices-run"
  filter = "resource.type=gae_app AND severity>=ERROR"
  project = "${google_project.service.project_id}"
  metric_descriptor {
    metric_kind = "DELTA"
    value_type  = "INT64"
  }
}

I have also on Stackdriver a custom metric named user/proservices-run.

However the following two import attempts fail:

$ terraform google_logging_metric.proservices_run proservices-run

google_logging_metric.proservices_run: Importing from ID "proservices-run"...
google_logging_metric.proservices_run: Import complete!
  Imported google_logging_metric (ID: proservices-run)
google_logging_metric.proservices_run: Refreshing state... (ID: proservices-run)

Error: google_logging_metric.proservices_run (import id: proservices-run): 1 error occurred:
	* import google_logging_metric.proservices_run result: proservices-run: google_logging_metric.proservices_run: project: required field is not set

$ terraform google_logging_metric.proservices_run user/proservices-run

google_logging_metric.proservices_run: Importing from ID "user/proservices-run"...
google_logging_metric.proservices_run: Import complete!
  Imported google_logging_metric (ID: user/proservices-run)
google_logging_metric.proservices_run: Refreshing state... (ID: user/proservices-run)

Error: google_logging_metric.proservices_run (import id: user/proservices-run): 1 error occurred:
	* import google_logging_metric.proservices_run result: user/proservices-run: google_logging_metric.proservices_run: project: required field is not set

Using

Terraform v0.11.14

and

provider.google 2.11.0
provider.google-beta 2.11.0

edit: I noticed the project: required field is not set in the error message, I added the field project in my TF code, however the outcome is still the same.

Posts: 1

Participants: 1

Read full topic


Trouble with AzureRM SAS Token for backend with Ampersand

$
0
0

@jeramecaudill wrote:

I’m trying to setup a remote state in Azure. My sas_token contains & (ampersand) characters, and I don’t seem to be able to escape them. I get the following errors:

There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Invalid multi-line string
PS C:\Demo> terraform init
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Invalid multi-line string

  on backend.tf line 6, in terraform:
   6:
   7:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.


Error: Unterminated template string

  on backend.tf line 6, in terraform:
   6:
   7:

No closing marker was found for the string.


Error: Invalid multi-line string

  on backend.tf line 7, in terraform:
   7:
   8:

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.

I’m not having any luck searching online how to get around this.
PS C:\Demo> terraform version
Terraform v0.12.23
+ provider.azurerm v2.0.0

My backend file looks like this:

terraform {
backend “azurerm” {
storage_account_name = “"
container_name = "

key = “terraform.tfstate”
sas_token = “*****&&&&…”
}
}

Posts: 1

Participants: 1

Read full topic

Issue creating a MS SQL Server instance on GCP using Terraform

$
0
0

@asbchakri wrote:

I was trying to create a MS SQL Server Instance in GCP, I’m having issues with the root_password parameter. I was able to create the instance using Provider=Google-beta where i had to provide the root_password. But when i’m trying to create in Provider=gooogle (the latest version), i’m having an error regarding root_password. If I add the parameter root_password, Terraform plan gives an error saying root_password is not expected here. I f i remove it Terraform Plan works but when i run Terraform apply it gives a error saying missing parameter Root Password. If I add it and run terraform apply it says root_password is not expected here. Can someone please help me out on how to fix this issue.

Posts: 1

Participants: 1

Read full topic

[Terraform] New Learn guide for the Terraform Consul provider

$
0
0

@im2nguyen wrote:

The Terraform Consul provider exposes resources used to interact with Consul. In the new Learn guide, you will register two external services with a small Consul datacenter. The guide uses Docker Compose to deploy a three server Consul datacenter and two external services locally. You will then configure the Terraform Consul provider to register the external services with health checks to Consul.

If you do not want to deploy the demo locally, you can use the interactive tutorial included in the guide.

Register External Services with Terraform

Posts: 2

Participants: 1

Read full topic

Custom Provisioner Failing After Updating to Terraform 12

$
0
0

@FuzzOli87 wrote:

	connState := ctx.Value(schema.ProvRawStateKey).(*terraform.InstanceState)

instance := connState.ID

o.Output(fmt.Sprintf("Connstate: %+v\n", connState))
o.Output(fmt.Sprintf("Connstate: %v\n", connState.ID))
o.Output(fmt.Sprintf("d: %+v\n", d))

We have had this code when it was terraform 11.x I have searched everywhere for any migration documentation for provisioners and haven’t found anything. After updating this provisioners dependencies to 12. This part fails due to connState.ID not being defined. In fact, the value of connState is “not created” which can’t be possible if this provisioner is triggered when we successfully create the resource it’s operating on, right?

Any idea how to debug this? AFAIK, the type of “instanceState” still contains an ID field.

Posts: 1

Participants: 1

Read full topic

Map Object with Optional Attributes

$
0
0

@MattMencel wrote:

I am attempting to write a module to build subnets from a map variable looking something like this…

   subnets = {
     "subnet1" = {
       "address_prefix" = "10.0.1.0/24"
     }
     "subnet2" = {
       "address_prefix" = "10.0.2.0/24"
       "service_endpoints" = [
         "Microsoft.KeyVault",
         "Microsoft.Storage",
       ]
     }
   }

Used like so in the call to the module…

module "subnets" {
  source               = "../../.."
  resource_group_name  = azurerm_resource_group.rsg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  subnets              = local.settings.virtual_network.subnets
}

Because map attributes must be of the same type, I’m attempting to use a variable like this in the module.

variable "subnets" {
  description = "A map of subnets"
  type = map(object({
    address_prefix    = string
    service_endpoints = list(string)
  }))
}

However, this way requires that every subnet has service_endpoints, which is not always the case. Is there a way to make that optional? The resource I’m using in the module uses for_each…

resource "azurerm_subnet" "subnet" {
  for_each = var.subnets

  name                 = each.key
  resource_group_name  = var.resource_group_name
  virtual_network_name = var.virtual_network_name
  address_prefix       = each.value["address_prefix"]
  service_endpoints    = each.value["service_endpoints"]
}

Posts: 2

Participants: 2

Read full topic

Viewing all 11395 articles
Browse latest View live