Skip to content

Commit

Permalink
Merge branch 'main' into add-reserved-ipv6-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
loosla authored Dec 10, 2024
2 parents fded416 + c0ea0d4 commit 8c4a028
Show file tree
Hide file tree
Showing 18 changed files with 1,917 additions and 128 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
## 2.45.0

IMPROVEMENTS:

- #1279 - @jvasilevsky - LBAAS-3552: add lb ipv6 field

BUG FIXES:

- #1276 - @andrewsomething - apps: support removing ingress rules.

MISC:

- #1283 - @loosla - [documentation]: update contributing: move terraformrc section to reb…
- #1282 - @loosla - [documentation]: update contributing doc

## 2.44.1

BUG FIXES:

- #1273 - @andrewsomething - opensearch_config: follow PATCH semantics

MISC:

- #1265 - @brianhelba - Fix docs for "digitalocean_database_opensearch_config"
- #1270 - @dduportal - docs(droplet) details `user_data` behavior (resource forces recreate)

## 2.44.0

IMPROVEMENTS:
Expand Down
151 changes: 122 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,163 @@
Developing the Provider
---------------------------
# Developing the Provider

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
Testing Your Changes Locally
----------------------------

### 1. Rebuilding the Provider
1.1 If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.

To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.

```sh
$ make build
...
$ $GOPATH/bin/terraform-provider-digitalocean
$ ls -la $GOPATH/bin/terraform-provider-digitalocean
...
```

Remember to rebuild the provider with `make build` to apply any new changes.

1.2 In order to check changes you made locally to the provider, you can use the binary you just compiled by adding the following
to your `~/.terraformrc` file. This is valid for Terraform 0.14+. Please see
[Terraform's documentation](https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers)
for more details.

```
provider_installation {
# Use /home/developer/go/bin as an overridden package directory
# for the digitalocean/digitalocean provider. This disables the version and checksum
# verifications for this provider and forces Terraform to look for the
# digitalocean provider plugin in the given directory.
dev_overrides {
"digitalocean/digitalocean" = "/home/developer/go/bin"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
```

### 2. Creating a Sample Terraform Configuration
2.1 From the root of the project, create a directory for your Terraform configuration:

```console
mkdir -p examples/my-tf
```

2.2 Create a new Terraform configuration file:

``` console
touch examples/my-tf/main.tf
```

2.3 Populate the main.tf file with the following example configuration.
* [Available versions for the DigitalOcean Terraform provider](https://registry.terraform.io/providers/digitalocean/digitalocean/latest)
* Make sure to update the token value with your own [DigitalOcean token](https://docs.digitalocean.com/reference/api/create-personal-access-token).

```console
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.44.1"
}
}
}

provider "digitalocean" {
token = "dop_v1_12345d7ce104413a59023656565"
}

resource "digitalocean_droplet" "foobar-my-tf" {
image = "ubuntu-22-04-x64"
name = "tf-acc-test-my-tf"
region = "nyc3"
size = "s-1vcpu-1gb"
}
```
2.4 Before using the Terraform configuration, you need to initialize your working directory.
```console
cd examples/my-tf
terraform init
```

### 3. Running Terraform Commands
3.1 Navigate to the working directory:

```console
cd examples/my-tf
```

3.2 To see the changes that will be applied run:

```console
terraform plan
```

3.3 To apply the changes run:

```console
terraform apply
```
This will interact with your DigitalOcean account, using the token you provided in the `main.tf` configuration file.
Once you've finished testing, it's a good practice to clean up any resources you created to avoid incurring charges.

### 4. Debugging and Logging
You can add logs to your code with `log.Printf()`. Remember to run `make build` to apply changes.

If you'd like to see more detailed logs for debugging, you can set the `TF_LOG` environment variable to `DEBUG` or `TRACE`.

``` console
export TF_LOG=DEBUG
export TF_LOG=TRACE
```

After setting the log level, you can run `terraform plan` or `terraform apply` again to see more detailed output.

Provider Automation Tests
--------------------
### Running unit tests
In order to test the provider, you can simply run `make test`.

```sh
$ make test
```

In order to run the full suite of acceptance tests, run `make testacc`.
### Running Acceptance Tests

*Note:* Acceptance tests create real resources, and often cost money to run.
Rebuild the provider before running acceptance tests.

```sh
$ make testacc
```
Please be aware that **running ALL acceptance tests will take a significant amount of time and could be expensive**, as they interact with your **real DigitalOcean account**. For this reason, it is highly recommended to run only one acceptance test at a time to minimize both time and cost.

- It is preferable to run one acceptance test at a time.
In order to run a specific acceptance test, use the `TESTARGS` environment variable. For example, the following command will run `TestAccDigitalOceanDomain_Basic` acceptance test only:

```sh
$ make testacc TESTARGS='-run=TestAccDigitalOceanDomain_Basic'
```

All acceptance tests for a specific package can be run by setting the `PKG_NAME` environment variable. For example:
- All acceptance tests for a specific package can be run by setting the `PKG_NAME` environment variable. For example:

```sh
$ make testacc PKG_NAME=digitalocean/account
```

In order to check changes you made locally to the provider, you can use the binary you just compiled by adding the following
to your `~/.terraformrc` file. This is valid for Terraform 0.14+. Please see
[Terraform's documentation](https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers)
for more details.
- In order to run the full suite of acceptance tests, run `make testacc`.

```
provider_installation {
# Use /home/developer/go/bin as an overridden package directory
# for the digitalocean/digitalocean provider. This disables the version and checksum
# verifications for this provider and forces Terraform to look for the
# digitalocean provider plugin in the given directory.
dev_overrides {
"digitalocean/digitalocean" = "/home/developer/go/bin"
}
**Note:** Acceptance tests create real resources, and often cost money to run.

# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
```sh
$ make testacc
```

For information about writing acceptance tests, see the main Terraform [contributing guide](https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md#writing-acceptance-tests).

Releasing the Provider
----------------------
The dedicated DigitalOcean team is responsible for releasing the provider.

To release the provider:

Expand Down
1 change: 0 additions & 1 deletion digitalocean/app/app_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,6 @@ func appSpecIngressSchema() *schema.Resource {
"rule": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"match": {
Expand Down
92 changes: 92 additions & 0 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,55 @@ func TestAccDigitalOceanApp_TimeoutConfig(t *testing.T) {
})
}

func TestAccDigitalOceanApp_makeServiceInternal(t *testing.T) {
var app godo.App
appName := acceptance.RandomTestName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: testAccCheckDigitalOceanAppDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccCheckDigitalOceanAppConfig_minimalService, appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanAppExists("digitalocean_app.foobar", &app),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.name", appName,
),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.ingress.0.rule.0.match.0.path.0.prefix", "/",
),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.http_port", "8080",
),
),
},
{
Config: fmt.Sprintf(testAccCheckDigitalOceanAppConfig_internalOnlyService, appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanAppExists("digitalocean_app.foobar", &app),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.name", appName,
),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.http_port", "0",
),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.internal_ports.#", "1",
),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.internal_ports.0", "8080",
),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.ingress.0.rule.#", "0",
),
),
},
},
})
}

func testAccCheckDigitalOceanAppDestroy(s *terraform.State) error {
client := acceptance.TestAccProvider.Meta().(*config.CombinedConfig).GodoClient()

Expand Down Expand Up @@ -1577,3 +1626,46 @@ resource "digitalocean_app" "foobar" {
}
}
}`

var testAccCheckDigitalOceanAppConfig_minimalService = `
resource "digitalocean_app" "foobar" {
spec {
name = "%s"
region = "nyc"
service {
name = "go-service"
instance_count = 1
instance_size_slug = "apps-d-1vcpu-0.5gb"
git {
repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
branch = "main"
}
}
}
}`

var testAccCheckDigitalOceanAppConfig_internalOnlyService = `
resource "digitalocean_app" "foobar" {
spec {
name = "%s"
region = "nyc"
service {
name = "go-service"
instance_count = 1
instance_size_slug = "apps-d-1vcpu-0.5gb"
http_port = 0
internal_ports = [8080]
git {
repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
branch = "main"
}
}
ingress {}
}
}`
Loading

0 comments on commit 8c4a028

Please sign in to comment.