Skip to content

Commit

Permalink
Merge branch 'develop-oapi' into 'master'
Browse files Browse the repository at this point in the history
0.1.0RC8.1

Closes TPD-1877, TPD-1833, TPD-1843, and TPD-1848

See merge request customer-tooling/terraform-provider-outscale!397
  • Loading branch information
marinsalinas committed Feb 28, 2020
2 parents 772c011 + 743b115 commit ee40428
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ log.txt
terraform-provider-outscale
*.log
*.out

log.*
.DS_Store
*~
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Installing The Provider on Linux
Download the binary and install it in ~/.terraform.d/plugins/linux_amd64/.

```sh
$ wget https://github.com/outscale-dev/terraform-provider-outscale/releases/download/release-0.1.0RC8/terraform-provider-outscale_linux_amd64_v0.1.0-rc8.zip
$ unzip terraform-provider-outscale_linux_amd64_v0.1.0-rc8.zip
$ mv terraform-provider-outscale_v0.1.0-rc8 ~/.terraform.d/plugins/linux_amd64/.
$ wget https://github.com/outscale-dev/terraform-provider-outscale/releases/download/release-0.1.0RC8.1/terraform-provider-outscale_linux_amd64_v0.1.0-rc8.1.zip
$ unzip terraform-provider-outscale_linux_amd64_v0.1.0-rc8.1.zip
$ mv terraform-provider-outscale_v0.1.0-rc8.1 ~/.terraform.d/plugins/linux_amd64/.
```

Installing The Provider on MacOs
Expand All @@ -31,9 +31,9 @@ Installing The Provider on MacOs
Download the binary and install it in ~/.terraform/plugins/darwin_amd64/.

```sh
$ wget https://github.com/outscale-dev/terraform-provider-outscale/releases/download/release-0.1.0RC8/terraform-provider-outscale_darwin_amd64_v0.1.0-rc8.zip
$ unzip terraform-provider-outscale_darwin_amd64_v0.1.0-rc8.zip
$ mv terraform-provider-outscale_v0.1.0-rc8 ~/.terraform.d/plugins/darwin_amd64/.
$ wget https://github.com/outscale-dev/terraform-provider-outscale/releases/download/release-0.1.0RC8.1/terraform-provider-outscale_darwin_amd64_v0.1.0-rc8.1.zip
$ unzip terraform-provider-outscale_darwin_amd64_v0.1.0-rc8.1.zip
$ mv terraform-provider-outscale_v0.1.0-rc8.1 ~/.terraform.d/plugins/darwin_amd64/.
```

Building The Provider
Expand All @@ -43,14 +43,14 @@ Clone repository to: `$GOPATH/src/github.com/terraform-providers/terraform-provi

```sh
$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers
$ git clone --branch release-0.1.0RC8 https://github.com/outscale-dev/terraform-provider-outscale
$ git clone --branch release-0.1.0RC8.1 https://github.com/outscale-dev/terraform-provider-outscale
```

Enter the provider directory and build the provider

```sh
$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-outscale
$ go build -o terraform-provider-outscale_v0.1.0-rc8
$ go build -o terraform-provider-outscale_v0.1.0-rc8.1
```

Using the provider
Expand All @@ -59,7 +59,7 @@ Using the provider
2. Move the plugin to the repository ~/.terraform.d/plugins/linux_amd64/.

```shell
$ mv terraform-provider-outscale_v0.1.0-rc8 ~/.terraform.d/plugins/linux_amd64/.
$ mv terraform-provider-outscale_v0.1.0-rc8.1 ~/.terraform.d/plugins/linux_amd64/.
```

3. Execute `terraform plan`
Expand Down
28 changes: 17 additions & 11 deletions outscale/data_source_outscale_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{}
Filters: &oscgo.FiltersPublicIp{},
}

filters, filtersOk := d.GetOk("filter")

if filtersOk {
req.Filters = buildOutscaleOAPIDataSourcePublicIpsFilters(filters.(*schema.Set))
if p, ok := d.GetOk("public_ip_id"); ok {
req.Filters.SetPublicIpIds([]string{p.(string)})
}

if id := d.Get("public_ip_id"); id != "" {
req.Filters.SetPublicIpIds([]string{id.(string)})
}
if id := d.Get("public_ip"); id != "" {
if id, ok := d.GetOk("public_ip"); ok {
req.Filters.SetPublicIps([]string{id.(string)})
}

filters, filtersOk := d.GetOk("filter")
if filtersOk {
req.Filters = buildOutscaleOAPIDataSourcePublicIpsFilters(filters.(*schema.Set))
}

var response oscgo.ReadPublicIpsResponse
err := resource.Retry(60*time.Second, func() *resource.RetryError {
var err error
Expand All @@ -104,11 +104,11 @@ func dataSourceOutscaleOAPIPublicIPRead(d *schema.ResourceData, meta interface{}

// Verify Outscale returned our EIP
if len(response.GetPublicIps()) == 0 {
return fmt.Errorf("Unable to find EIP: %#v", response.GetPublicIps())
return fmt.Errorf("Unable to find Public IP: %#v", req)
}

if len(response.GetPublicIps()) > 1 {
return fmt.Errorf("multiple External IPs matched; use additional constraints to reduce matches to a single External IP")
return fmt.Errorf("multiple Public IPs matched; you can either use additional constraints to reduce matches to a single Public IP or use public_ips data source instead.")
}

address := response.GetPublicIps()[0]
Expand Down Expand Up @@ -163,7 +163,7 @@ func buildOutscaleOAPIDataSourcePublicIpsFilters(set *schema.Set) *oscgo.Filters
switch name := m["name"].(string); name {
case "public_ip_ids":
filters.SetPublicIpIds(filterValues)
case "link_ids":
case "link_public_ip_id":
filters.SetLinkPublicIpIds(filterValues)
case "placements":
filters.SetPlacements(filterValues)
Expand All @@ -177,6 +177,12 @@ func buildOutscaleOAPIDataSourcePublicIpsFilters(set *schema.Set) *oscgo.Filters
filters.SetPrivateIps(filterValues)
case "public_ips":
filters.SetPublicIps(filterValues)
case "tags":
filters.SetTags(filterValues)
case "tag_keys":
filters.SetTagKeys(filterValues)
case "tag_values":
filters.SetTagValues(filterValues)
default:
log.Printf("[Debug] Unknown Filter Name: %s.", name)
}
Expand Down
34 changes: 34 additions & 0 deletions outscale/data_source_outscale_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ func testAccDataSourceOutscaleOAPIPublicIPCheck(name string) resource.TestCheckF
}
}

func TestAccDataSourceOutscaleOAPIPublicIP_withTags(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataSourceOutscaleOAPIPublicIPConfigWithTags,
},
},
})
}

const testAccDataSourceOutscaleOAPIPublicIPConfig = `
resource "outscale_public_ip" "test" {}
Expand All @@ -74,3 +87,24 @@ const testAccDataSourceOutscaleOAPIPublicIPConfig = `
}
}
`

const testAccDataSourceOutscaleOAPIPublicIPConfigWithTags = `
resource "outscale_public_ip" "outscale_public_ip" {
tags {
key = "name"
value = "public_ip-data"
}
}
data "outscale_public_ip" "outscale_public_ip" {
filter {
name = "tags"
values = ["name=${outscale_public_ip.outscale_public_ip.tags[0].value}"]
}
filter {
name = "public_ip_ids"
values = [outscale_public_ip.outscale_public_ip.public_ip_id]
}
}
`
8 changes: 3 additions & 5 deletions outscale/data_source_outscale_public_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func dataSourceOutscaleOAPIPublicIPS() *schema.Resource {
return &schema.Resource{
Read: oapiDataSourceOutscalePublicIPSRead,
Read: dataSourceOutscalePublicIPSRead,
Schema: oapiGetPublicIPSDataSourceSchema(),
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func oapiGetPublicIPSDataSourceSchema() map[string]*schema.Schema {
}
}

func oapiDataSourceOutscalePublicIPSRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceOutscalePublicIPSRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*OutscaleClient).OSCAPI

req := oscgo.ReadPublicIpsRequest{}
Expand Down Expand Up @@ -123,7 +123,5 @@ func oapiDataSourceOutscalePublicIPSRead(d *schema.ResourceData, meta interface{
return err
}

err = d.Set("public_ips", address)

return err
return d.Set("public_ips", address)
}
38 changes: 37 additions & 1 deletion outscale/data_source_outscale_public_ips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func TestAccDataSourceOutscaleOAPIPublicIPS(t *testing.T) {
})
}

func TestAccDataSourceOutscaleOAPIPublicIPS_withTags(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataSourceOutscaleOAPIPublicIPSConfigWithTags,
},
},
})
}

const testAccDataSourceOutscaleOAPIPublicIPSConfig = `
resource "outscale_public_ip" "test" {}
resource "outscale_public_ip" "test1" {}
Expand All @@ -36,6 +49,29 @@ const testAccDataSourceOutscaleOAPIPublicIPSConfig = `
filter {
name = "public_ip"
values = ["${outscale_public_ip.test.public_ip}", "${outscale_public_ip.test1.public_ip}", "${outscale_public_ip.test2.public_ip}"]
}
}
}
`

const testAccDataSourceOutscaleOAPIPublicIPSConfigWithTags = `
resource "outscale_public_ip" "outscale_public_ip" {
tags {
key = "name"
value = "public_ip-data"
}
}
resource "outscale_public_ip" "outscale_public_ip2" {
tags {
key = "name"
value = outscale_public_ip.outscale_public_ip.tags[0].value
}
}
data "outscale_public_ips" "outscale_public_ips" {
filter {
name = "tags"
values = ["name=${outscale_public_ip.outscale_public_ip.tags[0].value}"]
}
}
`
Loading

0 comments on commit ee40428

Please sign in to comment.