Skip to content

Commit

Permalink
Merge pull request #119 from OctopusDeploy/beta-candidate-01
Browse files Browse the repository at this point in the history
Beta candidate 01
  • Loading branch information
jbristowe authored Jan 21, 2021
2 parents 15d1b25 + d760dbc commit f2a3963
Show file tree
Hide file tree
Showing 419 changed files with 23,485 additions and 6,410 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Go

on:
push:
branches: beta-candidate-01
branches:
- beta-candidate-01

jobs:

Expand All @@ -24,4 +25,4 @@ jobs:
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0

- name: Run golang-ci with all linters enabled
run: golangci-lint run --disable unused --disable deadcode
run: golangci-lint run --disable unused --disable deadcode --timeout 2m0s
17 changes: 13 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@ defaults:
jobs:
test:
env:
OCTOPUS_VERSION: "2020.2.7"
ACCEPT_EULA: "Y"
ACCEPT_OCTOPUS_EULA: "Y"
ADMIN_EMAIL: "john.bristowe@octopus.com"
ADMIN_USERNAME: "admin"
DB_CONNECTION_STRING: "Server=db,1433;Database=OctopusDeploy;User=sa;Password=Password01!"
MASTER_KEY: "6EdU6IWsCtMEwk0kPKflQQ=="
OCTOPUS_SERVER_BASE64_LICENSE: ${{ secrets.OCTOPUS_SERVER_BASE64_LICENSE }}
OCTOPUS_SERVER_TAG: "latest"
OCTOPUS_URL: "http://localhost:8080"
SA_PASSWORD: "Password01!"
SQL_IMAGE: "mcr.microsoft.com/mssql/server"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Build
run: go build -v .

- name: Start the Octopus container
run: ./tests/start-octopus.sh

- name: Generate an API key
run: ./tests/Create-ApiKey.ps1
shell: pwsh

- name: Build
run: go build -v .

- name: Test
run: go test -v ./octopusdeploy/...
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
OFF/

# Terraform
.terraform/
*.tfstate
*.tfstate.backup
crash.log
Expand All @@ -32,8 +31,9 @@ terraform-provider-octopusdeploy.exe

# Commenting the below because I wasn't able to save my main.tf configs for examples
#main.tf
build/
artifacts/
build/
vendor/
.release/
*.tfplan

Expand Down
10 changes: 10 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
TEST?=$$(go list ./... | grep -v 'vendor')
HOSTNAME=octopus.com
NAMESPACE=com
NAME=octopusdeploy
BINARY=terraform-provider-${NAME}
VERSION=0.6
OS_ARCH=darwin_amd64

default: install

build:
go build -o ${BINARY}

release:
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64

install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

test:
go test -i $(TEST) || exit 1
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
25 changes: 6 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ It is based on the [go-octopusdeploy](https://github.com/OctopusDeploy/go-octopu

## Testing

A GitHub action has been added to this project which initializes an instance of Octopus Deploy and runs the tests
against it. These same tests can be run in a forked repository.
A GitHub action has been added to this project which initializes an instance of Octopus Deploy and runs the tests against it. These same tests can be run in a forked repository.

## Downloading & Installing

As this provider is still under development, you will need to manually download it.
## Downloading and Installing

There are compiled binaries for most platforms in [Releases](https://github.com/OctopusDeploy/terraform-provider-octopusdeploy/releases).

Expand All @@ -22,7 +19,7 @@ To use it, extract the binary for your platform into the same folder as your `.t

### Default Space

```hcl
```terraform
# main.tf
provider "octopusdeploy" {
Expand All @@ -37,7 +34,7 @@ Simply provide the _name_ of the space (not the space ID)

**Note:** System level resources such as Teams are not support on a Space-scoped provider.

```hcl
```terraform
# main.tf
provider "octopusdeploy" {
Expand All @@ -51,7 +48,7 @@ provider "octopusdeploy" {

To manage resources in multiple spaces you currently must use multiple instances of the provider with [aliases](https://www.terraform.io/docs/configuration/providers.html#alias-multiple-provider-instances) like so:

```hcl
```terraform
# main.tf
provider "octopusdeploy" {
Expand Down Expand Up @@ -91,14 +88,4 @@ resource "octopusdeploy_environment" "Env3" {
provider = "octopusdeploy.space_product1"
name = "TestEnv3"
}
```

## Data Sources

* [octopusdeploy_environment](docs/provider/data_sources/environment.md)
* [octopusdeploy_lifecycle](docs/provider/data_sources/lifecycle.md)

## Provider Resources

* [octopusdeploy_environment](docs/provider/resources/environment.md)
* [octopusdeploy_lifecycle](docs/provider/resources/lifecycle.md)
```
42 changes: 42 additions & 0 deletions docs/Getting-Started/Step 1 - Why Terraform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Step 1 - Why Terraform?

If you're new to Terraform in general, it may be in your best interest to start with some Terraform Getting Started Docs.

[Getting Started](https://www.terraform.io/intro/index.html)

## Why Terraform?

Terraform has been the go-to for Infrastructure-as-code and quite frankly, Service-as-code for several organizations. You can essentially create anything including:
1. Azure Web Apps
2. Virtual Machines
3. Networks
4. Kubernetes Clusters
5. On-prem resources

And so much more...

The idea behind taking infrastructure that you would typically create manually and writing code to deploy it is:
1. You don't have to worry about manual efforts, especially if you have multiple pieces of an environment to set up.
2. You can store the code in source control for anyone to have the ability to work on and contribute to it.
3. Less mistakes happen in code vs creating resources manually because you can integrate tests and checks of the code.
4. You can automatically deploy the code to create resources and don't even have to run the code in an adhoc fashion.

## Why Terraform for Octopus Deploy?
Well, the same rules apply for the *Why Terraform?* section. You want the ability to create resources automatically instead of manually going through a UI.

With Terraform and the Octopus Deploy provider, you can create:
1. Account types (Azure, AWS, UsernamePassword, SSH, etc.).
2. Certificates
3. Channels
4. Deployment Triggers
5. Environments
6. Feeds
7. Variables and variable sets
8. Projects
9. Project groups
10. Lifecycles

And that's just in the beta... (more resources will be added)

Instead of having to create all of those resources manually in Octopus, or adhoc scripts, you can now create those resources in an automated fashion. You can even create the resources via a deployment from Octopus Deploy itself!

52 changes: 52 additions & 0 deletions docs/Getting-Started/Step 2 - The Setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Step 2 - The Setup

To use the Terraform provider, you may want to test it if you don't have a dev environment of Octopus Deploy.

To do this, let's set up Octopus Deploy instead of a Docker Container.

## Prerequisites
To follow along, you should have the following:
1. Docker installed on the OS that you're using
2. Familiarity with Docker

## The Dockerfile

To create an Octopus Deploy environment, the easiest way is with Docker Compose.

The docker-compose code below will create an Octopus Deploy server and a local SQL server.

You can access it once the container is up and running by going to `http://localhost:8080`

*Please note this is for development purposes and should not be used in production*

```
version: '3'
services:
octopus:
ports:
- "8080:8080"
- "10943:10943"
environment:
ADMIN_USERNAME: admin
ADMIN_EMAIL: test@gmail.com
ADMIN_PASSWORD: Password01!
ACCEPT_EULA: Y
DB_CONNECTION_STRING: Server=mssql,1433;Database=Octopus;User Id=SA;Password=Password01!;ConnectRetryCount=6
CONNSTRING: Server=mssql,1433;Database=Octopus;User Id=SA;Password=Password01!;ConnectRetryCount=6
MASTER_KEY: 6EdU6IWsCtMEwk0kPKflQQ==
image: octopusdeploy/octopusdeploy:latest
labels:
autoheal: true
depends_on:
- mssql
mssql:
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Password01!
MSSQL_PID: Express
image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
autoheal:
image: willfarrell/autoheal:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Step 3 - Terraform Directory

Before we can create a resource, we need a place for the HCL code to exist. Of similar importance, we need the Octopus Deploy Terraform provider.

Traditionally when you use Terraform, you can run `terraform init` and the provider gets pulled down for you. However, because the Terraform Provider is not yet in the Hashicorp store, you'll need to manually pull the package down and create the directory that the package should be in.

## Creating the Directory
In the directory where you plan to store the Terraform configuration files, you'll need to create the directory where the provider package will live.

### On Windows
The directory is:

`.teraform/plugins/windows_amd64`

### On MacOS
The directory is:
`.terraform/plugins/darwin_amd64`

After you create the directory, it should look something like the screenshot below on Mac for example.

![](images/terraformdirectory.png)

## The Terraform Provider
Once the directory is created, you'll need to add in the Terraform provider. The latest provider can be downloaded from the releases page found here:
[Octopus_Terraform_Provider](https://github.com/OctopusDeploy/terraform-provider-octopusdeploy/releases)

You should put the provider download in the directory that you created: `.terraform/plugins/os_version_amd64`
33 changes: 33 additions & 0 deletions docs/Getting-Started/Step 4 - Creating a Resource .md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Step 3 - Creating a Resource

Now that the environment is up and running, it's time to create a resource to test. Just so we can see how it works, we'll create one resource.

Before we start creating a Terraform configuration, we'll need a few components.

1. The server URL, which is going to be `localhost:8080`.
2. An API key which is generated from the Octopus Deploy server.

When connecting to the Octopus Deploy Terraform provider, the server URL and API key is needed for authentication. That way, Terraform knows what environment to connect to.

Once you have the API key, you can move on to the next step.

## Main.tf
The `main.tf` will be where you put the newly created resource. For example, you can create a resource to create a new project group.

```
provider "octopusdeploy" {
address = "localhost:8080"
apikey = api_key
space = "Default"
}
resource "octopusdeploy_project_group" "DevOpsProject" {
name = "testProject"
description = "my test project group"
}
```

With the above HCL code, the Terraform resource can be created with the standard Terraform commands:
1. `terraform init`
2. `terraform plan`
3. `terraform apply`
Loading

0 comments on commit f2a3963

Please sign in to comment.