Skip to content

Commit

Permalink
Merge pull request #78 from logicmonitor/DEV-151049-UpdateTerraformPr…
Browse files Browse the repository at this point in the history
…ovider

Provider documentation update and fields added in website resource
  • Loading branch information
lm-madhvi authored Dec 11, 2023
2 parents 6e33364 + c783bba commit fe2de63
Show file tree
Hide file tree
Showing 32 changed files with 787 additions and 742 deletions.
71 changes: 67 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,52 @@

## Requirements

- [Terraform](https://www.terraform.io/downloads.html) 0.14.x
- [Go](https://golang.org/doc/install) 1.16 (to build the provider plugin)
- [Terraform](https://www.terraform.io/downloads.html) 0.2.0
- [Go](https://golang.org/doc/install) 1.20.3 (to build the provider plugin)

## Steps to downgrade or upgrade go version

To downgrade or upgrade Go to a specific version, you need to follow these steps:

Uninstall the current version of Go from your system by removing the Go installation directory.
Download the specific Go version binary for your operating system and architecture from the official website. You can find the previous releases of Go at:
```sh
https://golang.org/dl/
```
Extract the downloaded archive to a location on your system.
Set the GOROOT environment variable to point to the extracted Go directory (the path where you extracted the Go binary).
Update your PATH environment variable to include the bin directory inside the extracted Go directory.
```sh
export GOROOT=/path/to/extracted/go
export PATH=$GOROOT/bin:$PATH
```
## Steps to downgrade or upgrade terraform version

To upgrade Terraform manually, follow these steps:

Visit the official HashiCorp releases page for Terraform at
```sh
https://releases.hashicorp.com/terraform/
```
Find the desired version and click on it to see available downloads.
Download the appropriate archive for your operating system (e.g., ZIP for windows, tar.gz for macOS/Linux).
Extract the downloaded archive to a directory included in your system's PATH environment variable.
Verify the installation by running terraform version in the terminal.
To downgrade to a specific version manually, follow these steps:
Uninstall the currently installed Terraform version.
Follow the manual installation steps above, ensuring that you download and extract the desired version.
Remember to update any configuration files or scripts that rely on specific Terraform versions when upgrading or downgrading.
## Building the Provider (Internal)
Clone repository:
```sh
$ git clone git@github.com:logicmonitor/terraform-provider-logicmonitor.git
$ git clone ssh://git@stash.logicmonitor.com:7999/teamintegrations/terraform-integration.git
```
Enter the provider directory and build the provider:
```sh
$ cd terraform-provider-logicmonitor/
$ cd terraform-integration/terraform-provider-logicmonitor/
$ make
```
The make file will then generate the code, build the binary, and copy it to the Terraform plugin directory.
Expand All @@ -41,3 +76,31 @@ provider "logicmonitor" {
company = var.logicmonitor_company
}
```
Example usage can be found in the /terraform-integration/examples directory.
## Initialize the Terraform project
Run the following command to initialize the project and download necessary provider plugins:
```sh
terraform init
```
## Plan the execution
```sh
terraform plan
```
This will show you a preview of the changes that Terraform will make based on your configuration. Review the plan carefully before proceeding to apply it.
## Apply the changes
If you are satisfied with the execution plan and ready to apply the changes, run the following command:
```sh
terraform apply
```
Terraform will prompt you to confirm the execution plan one more time. Type yes and press Enter to proceed.
The Terraform execution will begin and create/update the necessary resources according to your configuration.
## Internal Documentation
```sh
https://confluence.logicmonitor.com/display/ENG/Development+Guide
```
28 changes: 23 additions & 5 deletions examples/website/datasource.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
resource "logicmonitor_website" "my_website"{
type = "pingcheck"
type = "webcheck"
host = "google.com"
overall_alert_level = "warn"
polling_interval = 5
description = "website test"
disable_alerting = true
stop_monitoring = true
user_permission = "string"
group_id = 8
individual_sm_alert_enable = false
steps = [
{
schema = "https"
resp_type = "config"
timeout = 0
match_type = "plain"
match_type = "json"
description = "string"
use_default_root = true
http_method = "GET"
Expand All @@ -24,18 +25,35 @@ resource "logicmonitor_website" "my_website"{
name = "string"
req_type = "config"
fullpage_load = false
require_auth = true
http_headers = "X-Version:3"
auth = [{
password = "string"
type = "ntlm"
user_name = "string"
domain = "string"
}]
path = "$.data.resultKey"
keyword = "DEVWRT-SANRT-JOB1-9127"
http_body = "string"
resp_script = "string"
req_script = "string"
label = "string"
url = "/santaba/rest/version"
type = "string"
invert_match = true
status_code = "200"
}
]
transition = 1
global_sm_alert_cond = 0
is_internal = false
domain = "www.ebay.com"
name = "Ebay pingcheck"
domain = "www.example.com"
name = "Ebay webcheck test"
use_default_location_setting = false
use_default_alert_setting = true
individual_alert_level = "warn"
}

data "logicmonitor_website" "my_website" {
filter = "description~\"website test\""
depends_on = [
Expand Down
27 changes: 23 additions & 4 deletions examples/website/resource.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
resource "logicmonitor_website" "my_website"{
type = "pingcheck"
type = "webcheck"
host = "google.com"
overall_alert_level = "warn"
polling_interval = 5
description = "website test"
disable_alerting = true
stop_monitoring = true
user_permission = "string"
group_id = 8
individual_sm_alert_enable = false
steps = [
{
schema = "https"
resp_type = "config"
timeout = 0
match_type = "plain"
match_type = "json"
description = "string"
use_default_root = true
http_method = "GET"
Expand All @@ -24,13 +25,31 @@ resource "logicmonitor_website" "my_website"{
name = "string"
req_type = "config"
fullpage_load = false
require_auth = true
http_headers = "X-Version:3"
auth = [{
password = "string"
type = "ntlm"
user_name = "string"
domain = "string"
}]
path = "$.data.resultKey"
keyword = "DEVWRT-SANRT-JOB1-9127"
http_body = "string"
resp_script = "string"
req_script = "string"
label = "string"
url = "/santaba/rest/version"
type = "string"
invert_match = true
status_code = "200"
}
]
transition = 1
global_sm_alert_cond = 0
is_internal = false
domain = "www.ebay.com"
name = "Ebay pingcheck"
domain = "www.example.com"
name = "Ebay webcheck test"
use_default_location_setting = false
use_default_alert_setting = true
individual_alert_level = "warn"
Expand Down
70 changes: 70 additions & 0 deletions logicmonitor/schemata/authentication_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package schemata

import (
"terraform-provider-logicmonitor/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func AuthenticationSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Optional: true,
},

"password": {
Type: schema.TypeString,
Sensitive: true,
Required: true,
},

"type": {
Type: schema.TypeString,
Required: true,
},

"user_name": {
Type: schema.TypeString,
Required: true,
},

}
}

func SetAuthenticationSubResourceData(m []*models.Authentication) (d []*map[string]interface{}) {
for _, authentication := range m {
if authentication != nil {
properties := make(map[string]interface{})
properties["domain"] = authentication.Domain
properties["password"] = authentication.Password
properties["type"] = authentication.Type
properties["user_name"] = authentication.UserName
d = append(d, &properties)
}
}
return
}

func AuthenticationModel(d map[string]interface{}) *models.Authentication {
// assume that the incoming map only contains the relevant resource data
domain := d["domain"].(string)
password := d["password"].(string)
typeVar := d["type"].(string)
userName := d["user_name"].(string)

return &models.Authentication {
Domain: domain,
Password: &password,
Type: &typeVar,
UserName: &userName,
}
}

func GetAuthenticationPropertyFields() (t []string) {
return []string{
"domain",
"password",
"type",
"user_name",
}
}
Loading

0 comments on commit fe2de63

Please sign in to comment.