Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Security Groups and Cloud-init examples #251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ resource "yandex_compute_instance" "default" {

network_interface {
subnet_id = "${yandex_vpc_subnet.foo.id}"
nat = true
security_group_ids = [ yandex_vpc_security_group.security_group1.id ]
}

metadata = {
foo = "bar"
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
user-data = "${file("/home/user/cloudinit/meta.txt")}"
}
}

Expand All @@ -46,6 +49,74 @@ resource "yandex_vpc_subnet" "foo" {
zone = "ru-central1-a"
network_id = "${yandex_vpc_network.foo.id}"
}

resource "yandex_iam_service_account" "savpcsg" {
name = "savpcsg"
}

resource "yandex_resourcemanager_folder_iam_binding" "editor" {
folder_id = var.yc_folder_id
role = "editor"
members = [
"serviceAccount:${yandex_iam_service_account.savpcsg.id}"
]
depends_on = [
yandex_iam_service_account.savpcsg,
]
}

resource "yandex_vpc_security_group" "security_group1" {
name = "Security Group 1"
description = "Our Security Group"
network_id = yandex_vpc_network.foo.id
depends_on = [
yandex_iam_service_account.savpcsg,
yandex_resourcemanager_folder_iam_binding.editor,
yandex_vpc_network.foo,
yandex_vpc_subnet.foo,
]

ingress {
protocol = "TCP"
description = "SSH"
port = 22
v4_cidr_blocks = ["0.0.0.0/0"]
}

egress {

protocol = "ANY"
description = "Outbound unrestricted"
v4_cidr_blocks = ["0.0.0.0/0"]
port = -1
}

}
```
```
#Sample cloudinit/meta.txt
users:
- name: user1
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
homedir: /opt/user1
ssh-authorized-keys:
- ssh-rsa .... <comment>

packages:
- tmux
- rsync

package_upgrade: true
package_reboot_if_required: true
timezone: 'Asia/Tokyo'

runcmd:
- echo PermitRootLogin No >> /etc/ssh/sshd_config && sshd -t && systemctl restart sshd
- echo -e "net.core.rmem_max=4194304\nnet.core.wmem_max=1048576" > /etc/sysctl.d/mynetwork.conf
- sysctl -p /etc/sysctl.d/mynetwork.conf
- chown -R user1:user1 /opt/user1
```

## Argument Reference
Expand Down