github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/datadog/integration_pagerduty.go (about)

     1  // Copyright 2018 The Terraformer Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package datadog
    16  
    17  import (
    18  	"fmt"
    19  
    20  	datadogCommunity "github.com/zorkian/go-datadog-api"
    21  
    22  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    23  )
    24  
    25  var (
    26  	// IntegrationPagerdutyAllowEmptyValues ...
    27  	IntegrationPagerdutyAllowEmptyValues = []string{"tags."}
    28  )
    29  
    30  // IntegrationPagerdutyGenerator ...
    31  type IntegrationPagerdutyGenerator struct {
    32  	DatadogService
    33  }
    34  
    35  func (g *IntegrationPagerdutyGenerator) createResources(pdSubdomain string) []terraformutils.Resource {
    36  	resources := []terraformutils.Resource{}
    37  	resources = append(resources, g.createResource(pdSubdomain))
    38  
    39  	return resources
    40  }
    41  
    42  func (g *IntegrationPagerdutyGenerator) createResource(serviceName string) terraformutils.Resource {
    43  	resource := terraformutils.NewResource(
    44  		serviceName,
    45  		fmt.Sprintf("integration_pagerduty_%s", serviceName),
    46  		"datadog_integration_pagerduty",
    47  		"datadog",
    48  		map[string]string{
    49  			"individual_services": "true",
    50  		},
    51  		IntegrationPagerdutyAllowEmptyValues,
    52  		map[string]interface{}{},
    53  	)
    54  	// Ignore services in favor of individual_services
    55  	resource.IgnoreKeys = append(resource.IgnoreKeys, "^services$")
    56  
    57  	return resource
    58  }
    59  
    60  // InitResources Generate TerraformResources from Datadog API,
    61  // from PD Service create 1 TerraformResource.
    62  // Need IntegrationPagerduty Subdomain as ID for terraform resource
    63  func (g *IntegrationPagerdutyGenerator) InitResources() error {
    64  	client := datadogCommunity.NewClient(g.Args["api-key"].(string), g.Args["app-key"].(string))
    65  
    66  	integration, err := client.GetIntegrationPD()
    67  	if err != nil {
    68  		return err
    69  	}
    70  	g.Resources = g.createResources(integration.GetSubdomain())
    71  	return nil
    72  }