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

Detect sg #416

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions outscale/data_source_outscale_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,22 @@ func testAccCheckOutscaleOAPIImageDataSourceID(n string) resource.TestCheckFunc

func testAccCheckOutscaleOAPIImageDataSourceBasicConfig(omi, vmType, region, imageName string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_img_data" {
security_group_name = "sg_imgData"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "basicIm" {
image_id = "%[1]s"
vm_type = "%[2]s"
keypair_name = "terraform-basic"
placement_subregion_name = "%[3]sa"
security_group_ids = [outscale_security_group.sg_img_data.security_group_id]
}

resource "outscale_image" "image" {
Expand Down
12 changes: 12 additions & 0 deletions outscale/data_source_outscale_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,30 @@ func testAccCheckOutscaleOAPIImagesDataSourceID(n string) resource.TestCheckFunc

func testAccCheckOutscaleOAPIImagesDataSourceConfig(omi, vmType, region, imageName string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_imgs_data" {
security_group_name = "sg_imgsData"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "basic_one" {
image_id = "%[1]s"
vm_type = "%[2]s"
keypair_name = "terraform-basic"
placement_subregion_name = "%[3]sa"
security_group_ids = [outscale_security_group.sg_imgs_data.security_group_id]
}

resource "outscale_vm" "basic_two" {
image_id = "%[1]s"
vm_type = "%[2]s"
keypair_name = "terraform-basic"
placement_subregion_name = "%[3]sa"
security_group_ids = [outscale_security_group.sg_imgs_data.security_group_id]
}

resource "outscale_image" "image_one" {
Expand Down
61 changes: 40 additions & 21 deletions outscale/data_source_outscale_nic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,42 @@ func testAccCheckOutscaleOAPINICDestroy(s *terraform.State) error {

func testAccOutscaleOAPIENIDataSourceConfig(subregion string) string {
return fmt.Sprintf(`
resource "outscale_net" "outscale_net" {
ip_range = "10.0.0.0/16"

tags {
key = "Name"
value = "testacc-nic-ds"
}
resource "outscale_net" "outscale_net" {
ip_range = "10.0.0.0/16"
tags {
key = "Name"
value = "testacc-nic-ds"
}
}

resource "outscale_subnet" "outscale_subnet" {
subregion_name = "%sa"
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.id
resource "outscale_subnet" "outscale_subnet" {
subregion_name = "%sa"
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.id
}
resource "outscale_security_group" "sgdatNic" {
security_group_name = "test_sgNic"
description = "Used in the terraform acceptance tests"
tags {
key = "Name"
value = "tf-acc-test"
}
net_id = outscale_net.outscale_net.net_id
}

resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.id
tags {
value = "tf-value"
key = "tf-key"
}
resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.id
security_group_ids = [outscale_security_group.sgdatNic.security_group_id]
tags {
value = "tf-value"
key = "tf-key"
}
}

data "outscale_nic" "outscale_nic" {
nic_id = outscale_nic.outscale_nic.id
}
`, subregion)
data "outscale_nic" "outscale_nic" {
nic_id = outscale_nic.outscale_nic.id
}
`, subregion)
}

func testAccOutscaleOAPIENIDataSourceConfigFilter(subregion string) string {
Expand All @@ -176,9 +185,19 @@ func testAccOutscaleOAPIENIDataSourceConfigFilter(subregion string) string {
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.id
}
resource "outscale_security_group" "sgdatNic" {
security_group_name = "test_sgNic"
description = "Used in the terraform acceptance tests"
tags {
key = "Name"
value = "tf-acc-test"
}
net_id = outscale_net.outscale_net.net_id
}

resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.id
security_group_ids = [outscale_security_group.sgdatNic.security_group_id]
tags {
value = "tf-value"
key = "tf-key"
Expand Down
10 changes: 9 additions & 1 deletion outscale/data_source_outscale_nics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ func testAccCheckOutscaleOAPINicsDataSourceConfig(subregion string) string {
ip_range = "10.0.0.0/24"
net_id = outscale_net.outscale_net.net_id
}


resource "outscale_security_group" "sg_dataNic" {
description = "sg for terraform tests"
security_group_name = "terraform-sg"
net_id = outscale_net.outscale_net.net_id
}

resource "outscale_nic" "outscale_nic" {
subnet_id = outscale_subnet.outscale_subnet.subnet_id
security_group_ids = [outscale_security_group.sg_dataNic.security_group_id]

}

data "outscale_nics" "outscale_nics" {
Expand Down
11 changes: 11 additions & 0 deletions outscale/data_source_outscale_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,21 @@ const testAccDataSourceOutscaleOAPIPublicIPConfigWithTags = `

func testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi, region string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_Pbip" {
security_group_name = "sg_data_ip"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "outscale_vm" {
image_id = "%s"
vm_type = "tinav4.c2r2p2"
keypair_name = "terraform-basic"
security_group_ids = [outscale_security_group.sg_Pbip.security_group_id]
}

resource "outscale_public_ip" "outscale_public_ip" {
Expand Down
8 changes: 8 additions & 0 deletions outscale/data_source_outscale_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter(region stri
name = "available_ips_counts"
values = [outscale_subnet.outscale_subnet.available_ips_count]
}
filter {
name = "ip_ranges"
values = ["10.0.0.0/24"]
}
filter {
name = "net_ids"
values = [outscale_net.outscale_net.net_id]
}
}
`, region)
}
16 changes: 13 additions & 3 deletions outscale/data_source_outscale_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ func TestAccVM_WithTagDataSource(t *testing.T) {
// Lookup based on InstanceID
func testAccOAPITagDataSourceConfig(omi, vmType string) string {
return fmt.Sprintf(`
resource "outscale_vm" "basic" {
resource "outscale_security_group" "sg_vm_tag" {
security_group_name = "sg_tag"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "basicTag" {
image_id = "%s"
vm_type = "%s"
keypair_name = "terraform-basic"

security_group_ids = [outscale_security_group.sg_vm_tag.security_group_id]
tags {
key = "Name"
value = "test-vm"
Expand All @@ -47,7 +57,7 @@ func testAccOAPITagDataSourceConfig(omi, vmType string) string {
data "outscale_tag" "web" {
filter {
name = "resource_ids"
values = [outscale_vm.basic.id]
values = [outscale_vm.basicTag.id]
}
}
`, omi, vmType)
Expand Down
7 changes: 3 additions & 4 deletions outscale/data_source_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ func oapiVMDescriptionAttributes(set AttributeSetter, vm *oscgo.Vm) error {
if err := set("root_device_type", vm.GetRootDeviceType()); err != nil {
return err
}
if err := set("security_groups", getOAPIVMSecurityGroups(vm.GetSecurityGroups())); err != nil {
log.Printf("[DEBUG] SECURITY GROUPS ERR %+v", err)
if err := set("security_groups", getSecurityGroups(vm.GetSecurityGroups())); err != nil {
return err
}
if err := set("state", vm.GetState()); err != nil {
Expand Down Expand Up @@ -216,7 +215,7 @@ func getOscAPIVMBlockDeviceMapping(blockDeviceMappings []oscgo.BlockDeviceMappin
return blockDeviceMapping
}

func getOAPIVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]interface{} {
func getSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]interface{} {
res := []map[string]interface{}{}
for _, g := range groupSet {
r := map[string]interface{}{
Expand All @@ -229,7 +228,7 @@ func getOAPIVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]i
return res
}

func getVMSecurityGroupIds(sgIds []oscgo.SecurityGroupLight) []string {
func getSecurityGroupIds(sgIds []oscgo.SecurityGroupLight) []string {
res := make([]string, len(sgIds))
for k, ids := range sgIds {
res[k] = ids.GetSecurityGroupId()
Expand Down
21 changes: 18 additions & 3 deletions outscale/data_source_outscale_vm_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func testAccDataSourceOutscaleOAPIVMStateCheck(name string) resource.TestCheckFu
return fmt.Errorf("root module has no resource called %s", name)
}

vm, ok := s.RootModule().Resources["outscale_vm.basic"]
vm, ok := s.RootModule().Resources["outscale_vm.basic_state"]
if !ok {
return fmt.Errorf("can't find outscale_public_ip.test in state")
}
Expand All @@ -55,17 +55,32 @@ func testAccDataSourceOutscaleOAPIVMStateCheck(name string) resource.TestCheckFu

func testAccDataSourceOutscaleOAPIVmStateConfig(omi, vmType string) string {
return fmt.Sprintf(`
resource "outscale_vm" "basic" {
resource "outscale_security_group" "sg_vm_state" {
security_group_name = "sg_vmState"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "basic_state" {
image_id = "%s"
vm_type = "%s"
keypair_name = "terraform-basic"
security_group_ids = [outscale_security_group.sg_vm_state.security_group_id]
}

data "outscale_vm_state" "state" {
all_vms = false
filter {
name = "vm_ids"
values = [outscale_vm.basic.id]
values = [outscale_vm.basic_state.id]
}
filter {
name = "vm_states"
values = ["running"]
}
}
`, omi, vmType)
Expand Down
7 changes: 7 additions & 0 deletions outscale/data_source_outscale_vm_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ func TestAccVM_StatesDataSource(t *testing.T) {

func testAccDataSourceOutscaleOAPIVMStatesConfig(omi, vmType string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_vStates" {
description = "testAcc Terraform security group"
security_group_name = "sg_volumes_link"
}

resource "outscale_vm" "basic" {
image_id = "%s"
vm_type = "%s"
keypair_name = "terraform-basic"
security_group_ids = [outscale_security_group.sg_vStates.security_group_id]

}

data "outscale_vm_states" "state" {
Expand Down
16 changes: 13 additions & 3 deletions outscale/data_source_outscale_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,32 @@ func TestAccVM_DataSource_basic(t *testing.T) {

func testAccOAPIVMDataSourceConfig(omi, vmType, region string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_vm_data" {
security_group_name = "sg_vm_basic"
description = "Used in the terraform acceptance tests"

resource "outscale_vm" "outscale_vm" {
tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "outscale_vm_data" {
image_id = "%[1]s"
vm_type = "%[2]s"
keypair_name = "terraform-basic"

security_group_ids = [outscale_security_group.sg_vm_data.security_group_id]
tags {
key = "name"
value = "Terraform-VM"
}

}

data "outscale_vm" "basic_web" {
filter {
name = "vm_ids"
values = [outscale_vm.outscale_vm.vm_id]
values = [outscale_vm.outscale_vm_data.vm_id]
}
}
`, omi, vmType, region)
Expand Down
13 changes: 12 additions & 1 deletion outscale/data_source_outscale_vm_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,21 @@ func TestAccVM_TypesDataSource_basic(t *testing.T) {

func testAccDataSourceOutscaleOAPIVMTypesConfig(omi, vmType string) string {
return fmt.Sprintf(`
resource "outscale_vm" "basic" {
resource "outscale_security_group" "sg_vms_types" {
security_group_name = "sg_vm_type"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "basic_types" {
image_id = "%s"
vm_type = "%s"
keypair_name = "terraform-basic"
security_group_ids = [outscale_security_group.sg_vms_types.security_group_id]
}

data "outscale_vm_types" "vm_types" {
Expand Down
11 changes: 11 additions & 0 deletions outscale/data_source_outscale_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ func TestAccVMS_DataSource_basic(t *testing.T) {

func testAccOAPIVMSDataSourceConfig(omi, vmType string) string {
return fmt.Sprintf(`
resource "outscale_security_group" "sg_vms" {
security_group_name = "sg_vms_test"
description = "Used in the terraform acceptance tests"

tags {
key = "Name"
value = "tf-acc-test"
}
}

resource "outscale_vm" "basic" {
image_id = "%s"
vm_type = "%s"
keypair_name = "terraform-basic"
security_group_ids = [outscale_security_group.sg_vms.security_group_id]
}

data "outscale_vms" "basic_web" {
Expand Down
Loading
Loading