Giter Site home page Giter Site logo

hashicorp / terraform-provider-hcs Goto Github PK

View Code? Open in Web Editor NEW
4.0 241.0 9.0 656 KB

Terraform provider for HashiCorp Consul Service on Azure.

License: Mozilla Public License 2.0

Makefile 0.91% Go 98.38% Shell 0.57% HCL 0.13%
terraform-provider consul hashicorp-consul-service hcs

terraform-provider-hcs's Introduction

HashiCorp Consul Service on Azure (HCS) Terraform Provider

Requirements

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the make dev command

Adding Dependencies

This provider uses Go modules. Please see the Go documentation for the most up to date information about using Go modules.

To add a new dependency github.com/author/dependency to your Terraform provider:

go get github.com/author/dependency
go mod tidy

Then commit the changes to go.mod and go.sum.

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).

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

To generate the latest models for the HCS Custom Resource Provider actions, run:

make generate-hcs-ama-api-spec-models

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

$ make testacc

Generating Docs

From the root of the repo run:

go generate && go mod tidy

Using the provider

Please see the docs for details about a particular resource. Below is a complex example that leverages the Azure Terraform provider and creates a federation of two HCS clusters.

// Configure the provider
provider "hcs" {}

provider "azurerm" {
  features {}
}

// If you have not already done so, accept the HCS Marketplace agreement
data "hcs_plan_defaults" "hcs_plan" {}

resource "azurerm_marketplace_agreement" "hcs_marketplace_agreement" {
  publisher = data.hcs_plan_defaults.hcs_plan.publisher
  offer     = data.hcs_plan_defaults.hcs_plan.offer
  plan      = data.hcs_plan_defaults.hcs_plan.plan_name
}

// Create the Resource Group for the primary cluster
resource "azurerm_resource_group" "primary" {
  name     = "hcs-tf-federation-primary-rg"
  location = "westus2"
}

// Create the primary cluster
resource "hcs_cluster" "primary" {
  resource_group_name      = azurerm_resource_group.primary.name
  managed_application_name = "hcs-tf-federation-primary"
  email                    = "[email protected]"
  cluster_mode             = "production"
  min_consul_version       = "v1.9.0"
  vnet_cidr                = "172.25.16.0/24"
  consul_datacenter        = "hcs-tf-federation-example"
}

// Create a federation token
data "hcs_federation_token" "fed" {
  resource_group_name      = hcs_cluster.primary.resource_group_name
  managed_application_name = hcs_cluster.primary.managed_application_name
}

// Create the Resource Group for the secondary cluster
resource "azurerm_resource_group" "secondary" {
  name     = "hcs-tf-federation-secondary-rg"
  location = "eastus"
}

// Create the secondary cluster using the federation token from above
resource "hcs_cluster" "secondary" {
  resource_group_name      = azurerm_resource_group.secondary.name
  managed_application_name = "hcs-tf-federation-secondary"
  email                    = "[email protected]"
  cluster_mode             = "production"
  min_consul_version       = "v1.9.0"
  vnet_cidr                = "172.25.17.0/24"
  consul_datacenter        = "hcs-tf-federation-secondary"
  consul_federation_token  = data.hcs_federation_token.fed.token
}

terraform-provider-hcs's People

Contributors

alexmunda avatar bflad avatar calebalbers avatar chapmanc avatar claire-labry avatar crhino avatar dependabot[bot] avatar fitzse avatar hanshasselberg avatar hashicorp-cloud avatar hashicorp-copywrite[bot] avatar hashicorp-tsccr[bot] avatar janet avatar mkeeler avatar modrake avatar paultyng avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-hcs's Issues

Unable to use Recommended Consul Version

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

1.2.5

Affected Resource(s)

  • hcs_cluster
  • hcs_consul_versions

Terraform Configuration Files

data "hcs_consul_versions" "default" {}

data "hcs_plan_defaults" "default" {}

# Accept the HCS Marketplace agreement
resource "azurerm_marketplace_agreement" "hcs" {
  publisher = data.hcs_plan_defaults.default.publisher
  offer     = data.hcs_plan_defaults.default.offer
  plan      = data.hcs_plan_defaults.default.plan_name
}

# Create the primary cluster
resource "hcs_cluster" "hcs" {
  managed_application_name = var.application_name
  location                 = var.location
  resource_group_name      = var.resource_group_name
  cluster_mode             = var.consul_cluster_mode
  email                    = var.email

  cluster_name                = var.consul_cluster_name
  consul_datacenter           = var.consul_datacenter_name
  consul_external_endpoint    = var.external_endpoint
  managed_resource_group_name = var.managed_resource_group_name
  min_consul_version          = var.consul_version == null ? data.hcs_consul_versions.default.recommended : var.consul_version

  depends_on = [
    azurerm_marketplace_agreement.hcs
  ]
}

Debug Output

Error: specified Consul version (v1.11.6) is unavailable; must be one of: [{Version:v1.10.12 Status:} {Version:v1.10.11 Status:} {Version:v1.10.10 Status:} {Version:v1.10.9 Status:} {Version:v1.10.8 Status:} {Version:v1.9.17 Status:} {Version:v1.9.16 Status:} {Version:v1.9.15 Status:}]

Expected Behavior

The version that the HCS provider recommends should be available.

Actual Behavior

The above error.

Steps to Reproduce

  1. terraform apply

Important Factoids

I just upgraded the marketplace agreement from on-demand to on-demand-v2.

GitHub Actions - deprecated warnings found - action required!

Workflow Name: Tests
Branch: main
Run URL: https://github.com/hashicorp/terraform-provider-hcs/actions/runs/4556622965

save-state deprecation warnings: 0
set-output deprecation warnings: 0
node12 deprecation warnings: 1

Please review these deprecation warnings as soon as possible and merge in the necessary updates.

GitHub will be removing support for these commands and plan to fully disable them on 31st May 2023. At this time, any workflow that still utilizes these commands will fail. See https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/.

GitHub have not finalized a date for deprecating node12 yet but have indicated that this will be summer 2023. So it is advised to switch to node16 asap. See https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.

If you need any help, please reach out to us in #team-rel-eng.

hcs_cluster resource is not idempotent for Development clusters

Terraform Version

Terraform v0.14.9

Affected Resource(s)

  • hcs_cluster

Terraform Configuration Files

resource "hcs_cluster" "example" {
  resource_group_name      = azurerm_resource_group.hcs.name
  managed_application_name = "hcs-cluster"
  email                    = "[email protected]"
  cluster_mode             = "Development"
  consul_datacenter        = "dc1"
  consul_external_endpoint = true
  min_consul_version       = data.hcs_consul_versions.default.recommended
  plan_name                = data.hcs_plan_defaults.default.plan_name
  tags                     = local.common_tags
}

Expected Behavior

The resource should be idempotent. Subsequent plans/applies that contain no changes should not modify the HCS cluster.

Actual Behavior

first terraform apply creates the cluster successfully
however during the next refresh the cluster_mode changes to PRODUCTION.

Terraform v0.14.9
Configuring remote state backend...
Initializing Terraform configuration...
azurerm_resource_group.hcs: Refreshing state... []
hcs_cluster.example: Refreshing state... []

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # hcs_cluster.example must be replaced
-/+ resource "hcs_cluster" "example" {
      ~ blob_container_name            = "blobzdso7arbudgwu" -> (known after apply)
      ~ cluster_mode                   = "PRODUCTION" -> "Development" # forces replacement
...

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. terraform apply

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.