How to use terraform-docs with no modules (only root module)?

I have been trying to use terraform-docs with a Terraform sample infrastructure which is not organized into modules, so it only has the root module (as we read in modules docs). I started by installing terraform-docs with go get, according to the instructions on GitHub. The terraform-docs syntax to generate markdown docs is terraform-docs markdown ./my-terraform-module. If I try to pass a .tf file as argument, I get:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x79eb84]

goroutine 1 [running]:
github.com/terraform-docs/terraform-docs/internal/cli.(*cfgreader).exist(0xc000156000, 0xc000156000, 0x2, 0xc000018e80)
    /home/username/go/pkg/mod/github.com/terraform-docs/terraform-docs@v0.10.0-rc.1/internal/cli/reader.go:22 +0xe4
github.com/terraform-docs/terraform-docs/internal/cli.PreRunEFunc.func1(0xc0000b1b80, 0xc00014c1f0, 0x1, 0x1, 0x0, 0x0)
    /home/username/go/pkg/mod/github.com/terraform-docs/terraform-docs@v0.10.0-rc.1/internal/cli/run.go:46 +0x1b9
github.com/spf13/cobra.(*Command).execute(0xc0000b1b80, 0xc00014c1d0, 0x1, 0x1, 0xc0000b1b80, 0xc00014c1d0)
    /home/username/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:831 +0x514
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000b0dc0, 0x43c027, 0xba3e80, 0xc000012090)
    /home/username/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
    /home/username/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/terraform-docs/terraform-docs/cmd.Execute(0x4ae00, 0xc00001e238)
    /home/username/go/pkg/mod/github.com/terraform-docs/terraform-docs@v0.10.0-rc.1/cmd/root.go:24 +0x2b

When I pass the files directory as argument, I get a markdown output containing only the requirements, providers and input section only contains variables and their values. So, I ask: is it possible to use terraform-docs with the root module?

Thanks in advance

Go to Source
Author: rtrigo

Terraform fails on creating network with libvirt provider

I wanted to spin up a test environment locally using the description from this stackoverflow answer:
https://stackoverflow.com/a/58607900/4397899

The main.tf looks like

################################################################################
# ENV VARS
################################################################################

# https://www.terraform.io/docs/commands/environment-variables.html

variable "VM_COUNT" {
  default = 3
  type = number
}

variable "VM_USER" {
  default = "developer"
  type = string
}

variable "VM_HOSTNAME" {
  default = "ci-vm"
  type = string
}

variable "VM_IMG_URL" {
  default = "https://cloud-images.ubuntu.com/releases/bionic/release/ubuntu-18.04-server-cloudimg-amd64.img"
  type = string
}

variable "VM_IMG_FORMAT" {
  default = "qcow2"
  type = string
}

variable "VM_CIDR_RANGE" {
  default = "10.10.10.10/24"
  type = string
}


################################################################################
# PROVIDERS
################################################################################

# instance the provider
provider "libvirt" {
  uri = "qemu:///system"
}


################################################################################
# DATA TEMPLATES
################################################################################

# https://www.terraform.io/docs/providers/template/d/file.html

# https://www.terraform.io/docs/providers/template/d/cloudinit_config.html
data "template_file" "user_data" {
  template = file("${path.module}/cloud_init.cfg")
  vars = {
    VM_USER = var.VM_USER
  }
}

data "template_file" "network_config" {
  template = file("${path.module}/network_config.cfg")
}


################################################################################
# RESOURCES
################################################################################

resource "libvirt_pool" "vm" {
  name = "${var.VM_HOSTNAME}_pool"
  type = "dir"
  path = "/tmp/terraform-provider-libvirt-pool-ubuntu"
}

# We fetch the latest ubuntu release image from their mirrors
resource "libvirt_volume" "vm" {
  count  = var.VM_COUNT
  name   = "${var.VM_HOSTNAME}-${count.index}_volume.${var.VM_IMG_FORMAT}"
  pool   = libvirt_pool.vm.name
  source = var.VM_IMG_URL
  format = var.VM_IMG_FORMAT
}

# Create a public network for the VMs
resource "libvirt_network" "vm_public_network" {
   name = "${var.VM_HOSTNAME}_network"
   mode = "nat"
   domain = "${var.VM_HOSTNAME}.local"
   addresses = ["${var.VM_CIDR_RANGE}"]
   dhcp {
    enabled = true
   }
   dns {
    enabled = true
   }
}

# for more info about paramater check this out
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r/cloudinit.html.markdown
# Use CloudInit to add our ssh-key to the instance
# you can add also meta_data field
resource "libvirt_cloudinit_disk" "cloudinit" {
  name           = "${var.VM_HOSTNAME}_cloudinit.iso"
  user_data      = data.template_file.user_data.rendered
  network_config = data.template_file.network_config.rendered
  pool           = libvirt_pool.vm.name
}

# Create the machine
resource "libvirt_domain" "vm" {
  count  = var.VM_COUNT
  name   = "${var.VM_HOSTNAME}-${count.index}"
  memory = "1024"
  vcpu   = 1

  cloudinit = "${libvirt_cloudinit_disk.cloudinit.id}"

  # TODO: Automate the creation of public network
  network_interface {
    network_id = "${libvirt_network.vm_public_network.id}"
    #network_id = "6d8e2494-835d-4baf-a14f-3a5c705febcc"
    #network_name = "vm_docker_network"
    network_name = "${libvirt_network.vm_public_network.name}"
  }

  # IMPORTANT
  # Ubuntu can hang is a isa-serial is not present at boot time.
  # If you find your CPU 100% and never is available this is why.
  #
  # This is a known bug on cloud images, since they expect a console
  # we need to pass it:
  # https://bugs.launchpad.net/cloud-images/+bug/1573095
  console {
    type        = "pty"
    target_port = "0"
    target_type = "serial"
  }

  console {
    type        = "pty"
    target_type = "virtio"
    target_port = "1"
  }

  disk {
    volume_id = "${libvirt_volume.vm[count.index].id}"
  }

  graphics {
    type        = "spice"
    listen_type = "address"
    autoport    = true
  }
}


################################################################################
# TERRAFORM CONFIG
################################################################################

terraform {
  required_version = ">= 0.12"
}

The network_config.cfg looks like this

version: 2
ethernets:
  ens3:
     dhcp4: true

Steps to Reproduce Issue

Run

terraform init
terraform apply

Then I get the error message:

Error: Error creating libvirt network: virError(Code=38, Domain=0, Message='error creating bridge interface ci-vm_network-br: Numerical result out of range')

Go to Source
Author: programmingFox

Terraform duplicates the security groups, how do I stop it?

I’m using terraform to create two instances and a security group. Here is how I did it:

# bastion host
resource "aws_instance" "bastion_1a" {
  ami                         = data.aws_ami.amazon_linux_2.id
  availability_zone           = var.az_1a
  instance_type               = var.instance_type
  key_name                    = var.bastion_key_name
  subnet_id                   = data.aws_subnet.public_subnet_us_east_1a.id
  vpc_security_group_ids      = [aws_security_group.bastion_sg.id]
}

resource "aws_instance" "bastion_1b" {
  ami                         = data.aws_ami.amazon_linux_2.id
  availability_zone           = var.az_1b
  instance_type               = var.instance_type
  key_name                    = var.bastion_key_name
  subnet_id                   = data.aws_subnet.public_subnet_us_east_1b.id
  vpc_security_group_ids      = [aws_security_group.bastion_sg.id]    
}

resource "aws_security_group" "bastion_sg" {
  name        = var.name_bastion_sg
  description = var.bastion_sg_description  
  vpc_id      = module.vpc.vpc_id

  ingress {
    description = var.ssh_ingress_description
    from_port   = var.port_ssh
    to_port     = var.port_ssh
    protocol    = var.protocol_tcp
    cidr_blocks = local.ips_allowed_ssh
  }
}

the problem: after the resources have been created, I checked the console and found that two security groups were created one for bastion_1a and another one for bastion_1b. However, as you can see in my terraform I only specified one security group.

I would like to use terraform to create one security group for both instances.Please can someone explain to me why terraform is creating two security groups.

What do I need to do so that terraform only creates one security group.

Go to Source
Author: davidonstack

Automating puppet master deployment with r10k

I am looking to automate the process of standing up and tearing down a development environment. Puppet currently manages the production and staging systems. I am looking to leverage r10k to populate the Puppet master environments, starting with dev. My issue is, how do I provide a secret key to the Puppet master that it can use to access bit bucket repo’s in an automated fashion? My plan is to use Terraform to codify the infrastructure and puppet to manage the systems. When the development suite isn’t needed, I would like to be able to tear it down completely.

Go to Source
Author: deejay