Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Terraformerのおはなし

int
October 02, 2019

 Terraformerのおはなし

int

October 02, 2019
Tweet

More Decks by int

Other Decks in Programming

Transcript

  1. ͍ܰ࢖͍ํ terraformer import google --resources=logging --projects=playground 2019/10/02 17:41:09 google importing

    project playground-226302 region global 2019/10/02 17:41:10 google importing... logging 2019/10/02 17:41:10 [TRACE] GRPCProvider: GetSchema 2019/10/02 17:41:10 [TRACE] GRPCProvider: Configure 2019/10/02 17:41:10 [TRACE] GRPCProvider: GetSchema 2019/10/02 17:41:11 [TRACE] GRPCProvider: GetSchema 2019/10/02 17:41:11 [TRACE] GRPCProvider: Configure 2019/10/02 17:41:11 Refreshing state... google_logging_metric.hog 2019/10/02 17:41:11 [TRACE] GRPCProvider: GetSchema 2019/10/02 17:41:11 Refreshing state... google_logging_metric.fuga 2019/10/02 17:41:11 [TRACE] GRPCProvider: GetSchema 2019/10/02 17:41:11 [TRACE] GRPCProvider: ReadResource 2019/10/02 17:41:11 [TRACE] GRPCProvider: ReadResource 2019/10/02 17:41:12 google Connecting.... 2019/10/02 17:41:12 google save logging 2019/10/02 17:41:12 [DEBUG] New state was assigned lineage "7bfb14fa-5e9e-4fb8-456d-1feab006acdd" 2019/10/02 17:41:12 google save tfstate for logging . ├── generated │ └── google │ └── playground-226302 │ └── logging │ └── global │ ├── logging_metric.tf │ ├── outputs.tf │ ├── provider.tf │ └── terraform.tfstate └── provider.tf
  2. resource "google_logging_metric" "fuga" { bucket_options { exponential_buckets { growth_factor =

    "2" num_finite_buckets = "64" scale = "0.01" } } description = "fuga" filter = "resource.type=\"k8s_cluster\"\nresource.labels.location=\"us-central1-a\"\nresource.labels.cluster_name=\"standard-cluster-1\"\n" label_extractors = {} metric_descriptor { metric_kind = "DELTA" value_type = "DISTRIBUTION" } name = "fuga" project = "playground-226302" value_extractor = "EXTRACT(protoPayload.@type)" } resource "google_logging_metric" "hoge" { description = "hoge" filter = "resource.type=\"k8s_cluster\"\nresource.labels.location=\"us-central1-a\"\nresource.labels.cluster_name=\"standard-cluster-1\"\n" label_extractors = {} metric_descriptor { metric_kind = "DELTA" unit = "1" value_type = "INT64" } name = "hog" project = "playground-226302" }
  3. ΞʔΩςΫνϟ঺հ terraformer import google --resources=logging --projects=playground Terraformer લॲཧ providerͱͷ௨৴ औಘ݁Ռͷparse

    •ίϚϯυͷparse • provider͝ͱͷॳظઃఆ • ରԠͯ͠ΔϦιʔε͔ʙ • ରԠ͍ͯ͠Ε͹ͦͷϦιʔεͷҰཡΛऔಘ͠ɺIDͱϦιʔ ε໊Ληοτ͢Δ • providerͱͷ௨৴४උ ىಈ͔Β
 https://github.com/GoogleCloudPlatform/terraformer/blob/0.8.1/cmd/import.go ͷfunc Importͷલ൒ลΓ
  4. ΞʔΩςΫνϟ঺հ terraformer import google --resources=logging --projects=playground Terraformer લॲཧ providerͱͷ௨৴ औಘ݁Ռͷparse

    provider-google •ࢦఆͨ͠ϦιʔεͷRefresh(Read) Λୟ͍ͯ݁ՌΛड͚औΔ • rpc͔grpcͰ௨৴ https://github.com/GoogleCloudPlatform/terraformer/blob/0.8.1/cmd/import.go ͷfunc Importͷޙ൒ ֤छproviderͷresourcesลΓ
  5. ΞʔΩςΫνϟ঺հ terraformer import google --resources=logging --projects=playground Terraformer લॲཧ providerͱͷ௨৴ औಘ݁Ռͷparse

    •↑Ͱಘͨ݁ՌΛࣗྗͰparseͯ͠ tf,tfstateϑΝΠϧΛग़ྗ͢Δ https://github.com/GoogleCloudPlatform/terraformer/blob/0.8.1/cmd/import.go ͷfunc ImportFromPlanลΓ
  6. func (g *LoggingGenerator) loadLoggingMetrics(ctx context.Context, client *logadmin.Client) error { metricIterator:=

    client.Metrics(ctx) for{ metric, err := metricIterator.Next() if err == iterator.Done { break } if err != nil { return err } g.Resources = append(g.Resources, terraform_utils.NewResource( metric.ID, metric.ID, "google_logging_metric", "google", map[string]string{ "name": metric.ID, "project": g.GetArgs()["project"].(string), }, loggingAllowEmptyValues, loggingAdditionalFields, )) } return nil } ͜Εͱ
  7. ࢀߟࢿྉ ! ιʔείʔυ:https://github.com/GoogleCloudPlatform/terraformer ! 3rd Party tool Λ͖͔͚ͬʹ Terraform ͷιʔείʔυΛগ͠ᅂΜͩ࿩

    https://chroju.github.io/blog/2019/05/14/read_terraform_source_code/ ! Terraform Provider࣮૷ ೖ໳(1): Custom Providerͷجૅ ! http://febc-yamamoto.hatenablog.jp/entry/terraform-custom-provider-01